Backend Overview¶
The Depict AI backend is built with FastAPI, providing a high-performance REST API for managing computer vision datasets, annotations, and user authentication.
Architecture¶
src/backend/
├── api/
│ ├── __init__.py
│ ├── annotations.py # Annotation CRUD endpoints
│ ├── auth.py # Authentication & JWT
│ ├── data.py # Data/image management
│ ├── deps.py # FastAPI dependencies
│ ├── ml.py # ML model endpoints
│ ├── oauth2.py # Social login (Google, Microsoft, GitHub)
│ ├── projects.py # Project management
│ └── users.py # User management
├── db/
│ ├── database.py # Database connection & initialization
│ └── tables.py # SQLModel table definitions
└── endpoints.py # Main FastAPI app & router registration
Tech Stack¶
- FastAPI - Modern async web framework
- SQLModel - SQL databases with Pydantic models
- Pydantic - Data validation
- python-jose - JWT token handling
- httpx - Async HTTP client for OAuth2
- Sentry SDK - Error monitoring
Key Features¶
🔐 Authentication¶
- Local Auth: Email/password with SHA-256 hashing
- OAuth2: Social login with Google, Microsoft, GitHub
- JWT Tokens: Secure stateless authentication
- Role-Based Access: User permissions (view, edit, delete, certify)
📊 Data Management¶
- Projects: Organize images into projects
- Images: Upload, store, and manage image data
- Annotations: Create, read, update annotations
- ML Integration: Run ML models on images
🔗 API Design¶
- RESTful: Standard HTTP methods (GET, POST, PUT, DELETE)
- OpenAPI: Auto-generated API documentation at
/docs - Async: Non-blocking I/O for high performance
- CORS: Configured for frontend integration
Database Schema¶
See Database Schema for complete schema details.
Main entities: - User - Authentication and profile - Project - Image collection container - Data - Image/video metadata - Annotation - Labels, boxes, masks - ProjectUserLink - Many-to-many user-project relation
API Endpoints¶
Authentication¶
POST /signup- Create new userPOST /login- Email/password loginPOST /token- OAuth2 token endpointGET /me- Get current user info
OAuth2¶
GET /auth/{provider}/login- Initiate OAuth2 flowGET /auth/{provider}/callback- OAuth2 callback
Projects¶
GET /projects/my-projects- List user's projectsPOST /projects/- Create new projectPOST /projects/join/{code}- Join project by codeGET /projects/{id}- Get project detailsPUT /projects/{id}- Update projectDELETE /projects/{id}- Delete project
Data (Images)¶
POST /data/- Upload imagePOST /data/batch- Batch uploadGET /data/non-labeled- Get unlabeled images
Annotations¶
POST /annotations/- Create annotationGET /annotations/{id}- Get annotationPUT /annotations/{id}- Update annotation
See API Reference for complete endpoint documentation.
Running the Backend¶
Development Mode¶
# Using Poetry
cd src/backend
poetry run fastapi dev endpoints.py
# Using uvicorn directly
poetry run uvicorn endpoints:app --reload --host 0.0.0.0 --port 8000
Production Mode¶
Environment Configuration¶
Create .env file in project root:
# API
API_URL="http://localhost:8000"
# JWT
JWT_SECRET_KEY="your-secret-key-here"
# OAuth2 (optional)
GOOGLE_CLIENT_ID="..."
GOOGLE_CLIENT_SECRET="..."
MICROSOFT_CLIENT_ID="..."
MICROSOFT_CLIENT_SECRET="..."
GITHUB_CLIENT_ID="..."
GITHUB_CLIENT_SECRET="..."
# Monitoring (optional)
SENTRY_DSN="..."
Testing¶
See Testing for testing strategies.
Next Steps¶
- API Reference - Complete API documentation
- Database Schema - Schema details
- User Management - Auth implementation details
- Contributing - Testing guide