How briink/backend-live-code-challenge works
Project Type and Purpose
• This is a single‐service backend application built with FastAPI, intended to expose a RESTful (or OpenAPI) interface and persist data in PostgreSQL. It is packaged and run via Docker (docker-compose) but can also run locally with Uvicorn and a venv.
File Structure Insights
• Top-level:
• Dockerfile / docker-compose.yml → container definitions and networking
• requirements.txt → Python dependencies (FastAPI, Uvicorn, SQLAlchemy or psycopg2, etc.)
• README.md → quick start, configuration, API docs
• app/ directory:
• api.py → FastAPI app + route definitions
• db.py → database engine/session configuration (connection URL, ORM setup)
Main Components
a. External Clients
• Browser or HTTP client (e.g., cURL, Postman)
• Swagger UI / ReDoc (auto-generated by FastAPI)
b. API Service Container
• Uvicorn/Gunicorn process hosting the FastAPI app
• app.api module: request handlers, routers, dependency injections
• app.db module: ORM or DB driver, connection pooling
c. Database Container
• PostgreSQL instance
• Data volume (persisted DB files)
d. Orchestration Layer
• docker-compose network linking the two containers
• Port mappings: Host:8000 → API:8000, (optionally) Host:5432 → DB:5432
Relationships and Data Flows
• HTTP flow: Client → [docker-compose network] → API Service at port 8000 → route handler →
→ data‐access via db.py → SQL queries → PostgreSQL → query results → back to client
1) Client “HTTP/JSON” → FastAPI
2) FastAPI “SQL” → PostgreSQL
3) PostgreSQL result → FastAPI → HTTP response → Client
Architectural Patterns and Principles
• Separation of concerns: API layer (business logic + routing) vs. data layer (DB config + ORM)
• Containerization: each major component lives in its own Docker container
• Single process per container: Uvicorn for API, native process for PostgreSQL
• Configuration-as-code: environment variables in docker-compose.yml drive DB URL
Relevant Technologies & Frameworks
• FastAPI for web framework
• Uvicorn as ASGI server
• SQLAlchemy or psycopg2 in app/db.py (depending on requirements.txt)
• Docker & docker-compose for container build and orchestration
• PostgreSQL for relational storage
• Optional layers: Black (formatter), pytest (testing)