How 1shisir/fastapi_backend works
Project Type and Purpose
• This is a backend-only REST API service built with FastAPI (Python).
• Its domain is a social-network style application supporting users, posts, likes, groups, messaging, connection requests, and notifications.
• It uses PostgreSQL for data persistence and Cloudinary for storing images.
File Structure
• Top-level files:
• main.py: application entry point where the FastAPI app is instantiated and routers are included.
• requirements.txt: Python dependencies.
• readme.txt: setup instructions.
• app/api/v1: API layer modules (auth.py, user.py) that define endpoint handlers.
• app/routers: higher-level routers grouping endpoints by feature (admin, chat, connections, groups, like, post).
• app/db:
• session.py: SQLAlchemy session management.
• base.py: base ORM metadata.
• models/: SQLAlchemy ORM models mapping to DB tables (user, post, message, etc.).
• app/core/security.py: security utilities (password hashing, JWT).
Extract Key Insights from the README
• Uses a .env file to configure PostgreSQL connection and Cloudinary credentials.
• Launches with “uvicorn main:app --reload” and exposes Swagger UI at /docs for interactive API testing.
• Cloudinary is the sole external service for image storage.
Main Components
a. External Client(s):
• Web or mobile frontend (not in repo) consuming the API via HTTP/HTTPS.
b. FastAPI Application:
• Request Handlers (routers & api modules)
• Business Logic & Security (core/security)
• Data Validation Layer (schemas)
c. Database Layer:
• PostgreSQL instance
• SQLAlchemy ORM (models, session)
d. External Service:
• Cloudinary for image uploads and storage
e. Deployment/Runtime:
• Uvicorn ASGI server hosting the FastAPI app
Relationships & Data Flows
• Client → FastAPI (HTTP requests)
• FastAPI → Database (SQLAlchemy session queries/inserts/updates)
• FastAPI → Cloudinary (upload/download images via Cloudinary API)
• FastAPI → Client (HTTP responses, JSON payloads)
• FastAPI components link: routers call API modules, which use schemas for validation and models for persistence, with security utilities applied on protected endpoints.
Architectural Patterns & Design Principles
• Layered architecture:
• API/Controller layer (routers & app/api)
• Service/Business layer (app/core)
• Data/Repository layer (app/db + SQLAlchemy models)
• DTO layer (Pydantic schemas)
• Separation of concerns: authentication/authorization is encapsulated in core/security, persistence is encapsulated in db/session & models.
• Configuration via environment variables ensures 12-factor compliance.
• Async support via FastAPI/Uvicorn for high concurrency.
Detailed Component Break-Out
• Routers (chat, connections, groups, like, post, admin)
• API modules (app/api/v1/auth.py, user.py)
• Core/security
• Database interface (session + models)
• Link each router to the corresponding schema and model sets (e.g. post router uses post schema & post model).