This repository contains the backend service for the application, built using Python FastAPI. It provides a clean, scalable REST API for user authentication, profiles, posts, likes, follows, and related social features.
The backend is designed following professional backend practices, focusing on modular architecture, clear separation of concerns, and best practices
- Python 3.10+
- FastAPI – High‑performance web framework
- Pydantic – Data validation and serialization
- SQLAlchemy / SQLModel – ORM (depending on implementation)
- PostgreSQL / SQLite – Database (configurable)
- JWT Authentication – Secure token‑based auth
- Uvicorn – ASGI server
app/
├── core/
│ ├── config.py # Environment & app settings
│ ├── security.py # JWT, password hashing
│ └── dependencies.py # Shared dependencies
│
├── db/
│ ├── base.py # Base ORM models
│ ├── session.py # DB session handling
│ └── init_db.py # DB initialization
│
├── models/
│ ├── user.py # User ORM model
│ ├── post.py # Post ORM model
│ └── follow.py # Follow relationship model
│
├── schemas/
│ ├── user.py # User request/response schemas
│ ├── post.py # Post schemas
│ └── auth.py # Auth schemas
│
├── repositories/
│ ├── user_repo.py # User DB operations
│ ├── post_repo.py # Post DB operations
│ └── follow_repo.py # Follow/unfollow logic
│
├── api/
│ ├── routes/
│ │ ├── auth.py # Login & auth routes
│ │ ├── users.py # User & profile routes
│ │ ├── posts.py # Create, like, fetch posts
│ │ └── follows.py # Follow/unfollow users
│ └── router.py # Main API router
│
├── main.py # App entry point
└── __init__.py
- Uses JWT (JSON Web Tokens)
- Tokens are issued on successful login
- Protected routes require a valid
Authorization: Bearer <token>header
- User registration & login
- Fetch user profile
- Follow & unfollow users
- Get followers and following lists
is_followingflag returned where applicable
-
Create posts
-
Fetch posts feed
-
Like & unlike posts
-
Post response includes:
likes_countis_likedcreated_at
Example Post Response:
{
"id": 18,
"content": "Hello world",
"author": {
"id": 3,
"username": "anab20"
},
"likes_count": 5,
"is_liked": true,
"created_at": "2026-01-02T00:17:35"
}- ORM‑based schema design
- Relationships handled via foreign keys
- Supports easy migration to PostgreSQL for production
Create a .env file in the root directory:
DATABASE_URL=sqlite:///./app.db
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60
# Install dependencies
pip install -r requirements.txt
# Run the server
uvicorn app.main:app --reloadServer will be available at:
http://127.0.0.1:8000
FastAPI provides interactive API docs out of the box:
- Swagger UI:
http://127.0.0.1:8000/docs - ReDoc:
http://127.0.0.1:8000/redoc
- Pytest compatible structure
- Repository‑level testing encouraged
- Dependency overrides supported by FastAPI
- Clean architecture
- Repository pattern
- Proper error handling
- Typed schemas
- Scalable & maintainable structure