How ivanshepeta/fast_api_postproject works
Project type and purpose
• This is a backend-only RESTful API service built with FastAPI.
• Purpose: Provide secure endpoints for user registration, login (JWT-based), post management (CRUD), and file upload/streaming, all backed by a PostgreSQL database with Pydantic/SQLAlchemy for validation and ORM.
File structure
• Top level:
• app/ – contains all source code
• config, database connection, models, schemas, utils, OAuth2 logic, and main entrypoint
• app/routers/ – groups endpoint handlers by domain (auth, user, post)
• app/models.py – SQLAlchemy ORM definitions
• app/schemas.py – Pydantic request/response models
• app/oauth2.py – JWT token creation/verification and security dependencies
• app/database.py – sessionLocal + engine setup for PostgreSQL
• app/utils.py – common helper functions (e.g., password hashing)
• app/main.py – FastAPI instantiation, router mounts, middleware
• app/config.py – environment variable loading via Python-dotenv
README for additional insights
• Lists core technologies: FastAPI, PostgreSQL, SQLAlchemy, PyJWT, Pydantic
• Highlights JWT authentication, CRUD for posts, file upload/streaming
Components
a. Main components:
• Client (web/mobile frontend, API consumer)
• FastAPI Application
– Routers (Auth, User, Post)
– Dependencies (OAuth2, utils)
– Schemas & Validation
• Business Logic / Services (optional layer within utils or routers)
• Database Layer
– SQLAlchemy ORM + PostgreSQL
• File Storage/Streaming Subsystem (could be local disk or cloud bucket)
• External Services (e.g., email service, if any; not in this version)
b. Relationships and interactions:
1. Client → FastAPI (HTTP request)
2. FastAPI Router authenticates via OAuth2 dependency → PyJWT
3. Router invokes business logic (utils + schemas) to validate/fill data
4. Business logic uses SQLAlchemy session (app.database) → PostgreSQL
5. For file endpoints: FastAPI reads/writes to file storage and streams to client
6. FastAPI responds over HTTP back to client
c. Architectural patterns / design principles:
• Layered architecture: Controllers (routers) → Services (utils) → Data access (models + database)
• Dependency injection via FastAPI’s Depends (for DB sessions, OAuth2 scopes)
• Separation of concerns: Pydantic schemas vs. SQLAlchemy models
• Configuration abstraction via app.config (dotenv)
d. Relevant technologies/frameworks:
• FastAPI (ASGI server, routing, dependency injection)
• Pydantic (request/response validation)
• SQLAlchemy ORM (models, sessions)
• PyJWT (token encoding/decoding)
• Python-dotenv (environment management)
• PostgreSQL (persistent storage)