How job-kuaitie/job-kuai-tie-api works
Project Type and Purpose
• This is a backend‐only RESTful microservice built with FastAPI, SQLAlchemy (ORM), and Alembic (migrations), packaged via Docker and orchestrated with docker‐compose.
• Purpose: demonstrate core FastAPI concepts—routing, security (JWT), database modeling, and migrations—for an interview demo.
High-Level Architecture Components
a. Client Layer
– External clients (e.g., browser frontends, Postman, mobile apps) that send HTTP(S) requests to the API.
b. API/Application Layer
– FastAPI application, comprising:
• Routers (account, category, company, job, security) handling individual resource endpoints.
• Dependency injection (from app/config.py, app/db.py).
• Security modules (JWT authentication, password hashing in app/security).
– Uvicorn (ASGI server) hosting the FastAPI app.
c. Data Layer
– PostgreSQL database (configured via environment variables).
– SQLAlchemy models (app/model/*.py).
– Alembic for migrations (alembic/versions/*.py).
d. Infrastructure/DevOps
– Dockerfile and docker‐compose.yml (multi-env support: local, stage, dockerhub).
– GitHub Actions workflow for CI/CD (deploy.yml).
– Environment files (.env examples) for per-environment config.
e. Test Suite
– pytest tests covering routers and data logic (tests/*.py, factory helpers).
Relationships & Data Flows
• Client → FastAPI/Uvicorn
– HTTP requests (GET/POST/PUT/DELETE) hit the API gateway.
• FastAPI Routers → Security Module
– Protected endpoints validate JWT tokens and passwords via app/security.
• FastAPI → Database
– CRUD operations executed through SQLAlchemy session (app/db.py).
• Alembic → Database
– Schema migrations applied at startup or via CLI.
• Docker → All Components
– Containers encapsulate FastAPI, Postgres, Alembic, executing in isolated networks.
• CI/CD → Dockerhub/Stage
– On push, GitHub Actions builds Docker images and deploys to target env.
Architectural Patterns & Key Principles
• Layered/Modular Design: separation of routers, models, security, and config.
• Dependency Injection: FastAPI’s Depends to inject DB sessions and settings.
• Single Responsibility: each router handles one resource.
• Statelessness: authentication via JWT, no server‐side sessions.
• Infrastructure as Code: Docker and compose files define runtime and relationships.