How april202305/bye--distract-backend works
Project Type and Purpose
• This is a backend‐only, RESTful API service for managing Pomodoro timer sessions, tasks, and user profiles.
• Built with FastAPI, it exposes endpoints for timer control, task CRUD operations, and user authentication/management.
File Structure
• Top-level:
• alembic.ini, migrations/ → database migration setup (Alembic).
• app/ → main application package.
• requirements.txt → dependency list.
• Under app/:
• api/ → route definitions (one file per resource: users.py, tasks.py, video.py, etc.).
• services/ → business logic layer (auth.py, task operations, video utilities).
• database/ → SQLAlchemy engine and session setup (database.py).
• models/ → ORM models (models.py).
• schemas/ → Pydantic request/response models (login_schemas.py, task.py, etc.).
• utilts/ → video input/output helpers.
• main.py → FastAPI app instantiation, router inclusion, middleware, startup events.
README for Additional Insights
• Tech Stack: FastAPI, SQLAlchemy, Alembic, JWT, Swagger UI.
• Key features: timer management (start/pause/stop), task tracking, user register/login, session history.
• Endpoints listed for timers (/timer/*), tasks (/tasks), and users (/users/*).
a. Main Components
1. Client (Web or Mobile UI)
2. FastAPI App (app/main.py)
3. API Routers (app/api/*.py)
4. Service Layer (app/services/*.py)
5. Schema Layer (app/schemas) for validation
6. Database Layer:
• SQLAlchemy ORM (app/models/models.py)
• Database session/engine (app/database/database.py)
• Alembic migrations (migrations/)
7. Authentication: JWT token generator/validator (in services/auth.py)
8. External Interfaces:
• Swagger UI / ReDoc
• (Optional) Object storage for user_photo or video processing modules
b. Relationships and Interactions
• Client sends HTTP request → FastAPI entry point (main.py)
• Router matches path → Pydantic schema validates input
• Router calls service function → business logic applies rules/auth
• Service uses SQLAlchemy session → issues CRUD queries to PostgreSQL
• Service returns domain models → routers convert to response schemas
• FastAPI serializes and returns JSON response
• Alembic handles schema migrations offline or at startup
• JWT auth: middleware or dependency injection protects certain endpoints
c. Architectural Patterns
• Layered Architecture (Controller → Service → Repository/ORM → Database)
• Dependency Injection (FastAPI dependencies)
• Repository/Unit of Work implicitly via SQLAlchemy sessions
• Migrations as versioned schema management
d. Key Technologies/Frameworks
• FastAPI for HTTP layer
• Pydantic for data validation
• SQLAlchemy ORM for persistence
• Alembic for migrations
• PyJWT (or fastapi-jwt) for auth
• Uvicorn as ASGI server
Key Details to Capture
• All major endpoints (timer, tasks, users).
• Separation of concerns: validation (schemas), business logic (services), data access (models + database).
• Migration workflow and DB schema evolution.
• Authentication mechanism and protected route handling.
• External API documentation endpoints (Swagger UI).