How 7s9n/small_sms_api works
Project type and purpose
• This is a backend‐only RESTful API for a “School Management System,” built with FastAPI and Uvicorn.
• It provides endpoints for managing students, subjects, grades, registrations, school years, nationalities, and user authentication/permissions.
• Alembic is used for database migrations against a PostgreSQL database.
File structure
• Top level:
• alembic/… & alembic.ini – migration scripts and config
• app/ – all application code
• requirements.txt, .env.example, README.MD
• app/ substructure:
• api/api_v1/routes – HTTP route definitions (grade, student, subject, etc.)
• api/api_v1/api.py – router aggregation and versioning
• deps.py – dependency‐injection helpers (e.g., DB session, current user)
• core/config.py – environment/configuration settings
• crud/ – repository layer, one class per model encapsulating DB operations
• db/ – session factory and base ORM classes
• models/ – SQLAlchemy ORM model definitions
• schemas/ – Pydantic models for request/response validation
• main.py – FastAPI app instantiation and Uvicorn entry point
README
• Confirms it’s a FastAPI service using a .env file for config
• Requires creating a Postgres database, then running Alembic “upgrade head”
• Launch with uvicorn app.main:app --reload
a. Main components to include
1. Client(s): Browser, mobile app, Postman, etc.
2. API Gateway/Uvicorn: HTTP server exposing FastAPI endpoints
3. FastAPI Application Layers:
– API Layer (Routers)
– Dependency Layer (deps.py)
– Service/Repository Layer (CRUD classes)
– ORM Layer (SQLAlchemy models & session)
– Validation Layer (Pydantic schemas)
4. Configuration (FastAPI Settings via core/config.py)
5. Database: PostgreSQL
6. Migration Tool: Alembic
b. Relationships and data flows
• Client → HTTP request → Uvicorn/FastAPI
• FastAPI → Router (app/api/api_v1/routes)
• Router → Dependencies (get_db, get_current_user)
• Handler → CRUD method → Session → Database
• Handler → Pydantic Schema for input/output
• Alembic → reads model metadata → executes migrations on Database
c. Architectural patterns & principles
• Layered architecture (Presentation → API → Service/Repository → Data)
• Dependency Injection (via FastAPI’s Depends)
• Repository pattern (CRUD classes abstract DB operations)
• Separation of concerns (routers vs. business logic vs. data models)
d. Key technologies/frameworks
• FastAPI + Uvicorn (ASGI server)
• Pydantic (request/response validation)
• SQLAlchemy (ORM)
• Alembic (DB migrations)
• PostgreSQL (persistent store)