How sanjeev-thiyagarajan/fastapi-course works
Project Type and Purpose
• This is a RESTful backend service for a social media clone built with FastAPI.
• It provides 4 main API routes: posts, users, authentication, and voting.
• It uses PostgreSQL for persistence, Alembic for migrations, and runs in Docker (with nginx and Gunicorn in production).
File Structure
Top-level folders and files reveal the layers:
• app/
– routers/ (auth.py, post.py, user.py, vote.py) – API endpoints
– models.py (SQLAlchemy ORM models)
– schemas.py (Pydantic request/response schemas)
– database.py (DB session setup)
– oauth2.py (JWT token creation/validation)
– utils.py and calculations.py (business logic/helpers)
– config.py (env var loading)
– main.py (FastAPI app instantiation, include_router calls)
• alembic/ (DB migration scripts and env)
• Dockerfile, docker-compose-dev.yml/prod, nginx/, gunicorn.service – Deployment
• tests/ – automated test suite using pytest
• README.md – high-level overview and setup instructions
README for Additional Insights
• Confirms 4 route groups and PostgreSQL dependency.
• Mentions environment variables (.env) for DB credentials and JWT secret.
• Describes local dev vs. prod deployments.
Main Components & Their Relationships
a. API Gateway / Reverse Proxy Layer
• nginx container (in prod) receives HTTP traffic and forwards to Gunicorn
b. Application Servers
• Gunicorn master process with multiple Uvicorn worker processes
• Each worker runs the FastAPI application code (main.py)
c. FastAPI Application
• Routers (auth, post, user, vote)
• Controllers/business logic in utils.py, calculations.py
• oauth2.py for JWT
• Pydantic schemas for validation
d. Data Persistence
• PostgreSQL database (in its own container)
• SQLAlchemy ORM for CRUD operations (models.py + database.py session)
• Alembic for schema migrations
e. CI/CD & DevOps
• GitHub Actions workflow (build-deploy.yml)
• Docker Compose for local dev environment (fast reload)
• Dockerfile for image build, gunicorn.service for systemd in prod
Architectural Patterns & Design Principles
• Layered Architecture:
• Presentation (nginx reverse proxy)
• Application/API (FastAPI routers + controllers)
• Domain/Business Logic (calculations.py, utils.py)
• Data Access (SQLAlchemy + Alembic)
• Dependency Injection via FastAPI’s Depends
• Separation of Concerns: routers vs. schemas vs. models
• Twelve-factor app principles for config (env vars in config.py)