Share Code is a collaborative code-sharing platform built with FastAPI, supporting real-time project collaboration, user authentication, and granular access control. It allows users to create projects, manage files, and collaborate with others in real time via websockets.
- User Authentication: Register, login, and manage user profiles securely.
- Project Management: Create, update, and delete projects. Assign access rights to collaborators.
- File Management: Add, edit, rename, and delete files within projects.
- Access Control: Grant "view" or "full access" permissions to users on a per-project basis.
- Real-Time Collaboration: Work together on projects using websockets for instant updates.
- RESTful API: Well-structured API endpoints for all major operations.
- Static File Serving: Serve CSS, JS, and other static assets.
- Backend: FastAPI, SQLModel, SQLAlchemy, Alembic
- Database: PostgreSQL (via asyncpg)
- Authentication: JWT-based
- Real-Time: Websockets (FastAPI + custom ConnectionManager)
- Frontend: Jinja2 templates, static assets (CSS/JS)
- Python 3.9+
- PostgreSQL database
-
Clone the repository:
git clone https://github.com/YousefSedik/sharecode cd sharecode -
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Create a
.envfile in the root directory. - Add your database URL and secret key:
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/sharecode SECRET_KEY=your_secret_key
- Create a
-
Run database migrations:
alembic upgrade head
-
Start the server:
uvicorn main:app --reload
-
Access the app:
- Register/Login: Use
/api/registerand/api/tokenendpoints. - Projects: Create and manage projects via
/api/project. - Files: Manage files within projects.
- Websockets: Connect to
/ws/join-project/{project_id}?token=...for real-time collaboration. - Admin Panel: (Optional) Uncomment the SQLAdmin code in
main.pyto enable.
sharecode/
apps/
auth_app/ # Authentication logic and routes
file_app/ # File management logic and routes
project_app/ # Project management logic and routes
_websocket_app/ # Websocket endpoints and utilities
models/ # SQLModel data models
static/ # Static assets (CSS, JS)
templates/ # Jinja2 HTML templates
main.py # FastAPI entrypoint
db.py # Database session and engine
utils/ # Utility modules (e.g., ConnectionManager)
requirements.txt # Python dependencies
alembic.ini # Alembic config for migrations
-
Authentication
POST /api/register— Register a new userPOST /api/token— Obtain JWT tokenGET /api/users/me— Get current user info
-
Projects
POST /api/project— Create a projectGET /api/project— List projectsGET /api/project/{project_id}— Project detailsPUT /api/project/{project_id}— Update projectDELETE /api/project/{project_id}— Delete project
-
Project Access
POST /api/project/{project_id}/access— Grant accessPUT /api/project/{project_id}/access— Update accessDELETE /api/project/{project_id}/access/{access_id}— Remove access
-
Websockets
GET /ws/join-project/{project_id}?token=...— Real-time collaboration
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.