How saiteja013526/socialmediaapi works
Project type and purpose
• This is a standalone backend REST API for a social-media-style application, built in Python using FastAPI.
• Core features: user registration & JWT login, CRUD operations on posts, data validation with Pydantic, persistence via SQLAlchemy + PostgreSQL.
File structure
• Top-level “app” folder contains the FastAPI app:
– main.py: application entrypoint (Uvicorn + FastAPI instantiation)
– config.py: environment and settings loader
– database.py: SQLAlchemy engine, session management
– models.py: ORM model definitions
– oauth_2.py: JWT token creation and verification logic
– schemas.py: Pydantic request/response models
– utils.py: helper functions (e.g. password hashing)
– routers/: directory with separate routers for auth, user, and post endpoints
• requirements.txt lists dependencies (FastAPI, SQLAlchemy, uvicorn, etc.)
README for additional insights
• Confirms stack: FastAPI, PostgreSQL, SQLAlchemy, JWT (Passlib), Uvicorn
• Emphasizes the standard layered approach: HTTP endpoints → validation → business logic → data persistence
a. Main components
• Client (Swagger UI / Postman / Frontend App)
• API Server (Uvicorn + FastAPI)
• Router Layer: AuthRouter, UserRouter, PostRouter
• Service / Business Logic Layer (utils, oauth2, any helper functions)
• Data Access Layer: SQLAlchemy session, models
• Database: PostgreSQL instance
• External services: JWT signing service (built-in), environment configuration (.env)
b. Relationships and interactions
1. Client → HTTP request → API Server
2. API Server dispatches request to the appropriate Router
3. Router uses Pydantic schemas to validate input
4. Router calls business-logic helpers (utils, oauth2)
5. Business logic invokes SQLAlchemy session to query/update DB
6. DB returns results → business logic returns domain objects → routers serialize using schemas → HTTP response back to client
c. Architectural patterns and design principles
• Layered architecture (Presentation / API layer, Validation, Business logic, Persistence)
• Separation of concerns: each router handles one resource
• Dependency injection style for DB sessions and settings
• Stateless authentication via JWT
d. Key technologies/frameworks
• FastAPI + Uvicorn (ASGI server)
• Pydantic (input/output validation)
• SQLAlchemy (ORM)
• PostgreSQL (relational database)
• Passlib + PyJWT (password hashing & token handling)