Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Production Ready API

A Production-Grade Backend API built with FastAPI

A clean, modular and scalable backend project implementing modern backend engineering practices including authentication, middleware, logging, testing and Dockerized deployment.


Python FastAPI SQLAlchemy Docker JWT Pytest


πŸ“– Overview

This project was built to practice production-style backend development rather than creating a simple CRUD application.

It follows a clean modular architecture and includes many features commonly found in real-world backend systems, including secure authentication, centralized logging, middleware, exception handling, automated testing and Docker support.


✨ Features

  • πŸ” JWT Authentication
  • πŸ”‘ Secure Password Hashing
  • πŸ‘€ User Registration & Login
  • πŸ›‘ Protected Endpoints
  • πŸ“¦ SQLAlchemy ORM
  • πŸ—„ SQLite Database
  • βš™ Environment Variables
  • πŸ“ Centralized Logging
  • 🚦 Custom Request Middleware
  • ❌ Global Exception Handling
  • ❀️ Health Check Endpoint
  • πŸ§ͺ Automated API Testing
  • 🐳 Dockerized Deployment
  • πŸ“‚ Clean Project Architecture

πŸ— Project Architecture

Client
   β”‚
   β–Ό
Middleware
   β”‚
   β–Ό
Router
   β”‚
   β–Ό
Controller
   β”‚
   β–Ό
Authentication
   β”‚
   β–Ό
Database
   β”‚
   β–Ό
Response

πŸ“ Folder Structure

Production-Ready-API
β”‚
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ auth
β”‚   β”œβ”€β”€ users
β”‚   β”œβ”€β”€ middleware
β”‚   β”œβ”€β”€ exceptions
β”‚   β”œβ”€β”€ database
β”‚   β”œβ”€β”€ core
β”‚   β”œβ”€β”€ services
β”‚   └── utils
β”‚
β”œβ”€β”€ tests
β”œβ”€β”€ logs
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ pytest.ini
β”œβ”€β”€ main.py
└── README.md

πŸ“‚ Module Responsibilities

Folder Responsibility
auth Authentication, JWT, Security
users User CRUD Operations
middleware Request Logging
exceptions Custom Exceptions & Global Handlers
database SQLAlchemy Engine & Sessions
core Logging & Application Lifespan
utils Application Settings
services Reserved for Future Business Logic
tests API Testing

βš™ Tech Stack

Category Technology
Language Python 3.14
Framework FastAPI
ORM SQLAlchemy
Database SQLite
Authentication JWT
Validation Pydantic v2
Password Hashing pwdlib
Logging Loguru
Testing Pytest
Containerization Docker

πŸ” Authentication Flow

Register
    β”‚
    β–Ό
Hash Password
    β”‚
    β–Ό
Store User
    β”‚
    β–Ό
Login
    β”‚
    β–Ό
Verify Password
    β”‚
    β–Ό
Generate JWT
    β”‚
    β–Ό
Authorization Header
    β”‚
    β–Ό
Protected Route

🌐 API Endpoints

Authentication

Method Endpoint Description
POST /auth/login Login & Generate JWT
GET /auth/me Get Current User

Users

Method Endpoint
POST /users
GET /users
GET /users/{username}
PUT /users/{username}
DELETE /users/{username}

Utility

Method Endpoint
GET /health

🐳 Docker

Build

docker build -t production-ready-api .

Run

docker run -d \
--name production-api \
--env-file .env \
-v "$(pwd)/production.db:/app/production.db" \
-p 8000:8000 \
production-ready-api

πŸ’» Local Setup

Clone repository

git clone https://github.com/whoismehfooz/Production-Ready-API.git

Move into project

cd Production-Ready-API

Create Virtual Environment

python -m venv venv

Linux

source venv/bin/activate

Windows

venv\Scripts\activate

Install Dependencies

pip install -r requirements.txt

Create .env

DB_CONNECTION=sqlite:///./production.db
SECRET_KEY=your-secret-key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30

Run

uvicorn main:app --reload

πŸ§ͺ Running Tests

pytest -v

πŸ“ˆ Project Highlights

βœ” Clean Modular Architecture

βœ” JWT Authentication

βœ” Dependency Injection

βœ” SQLAlchemy ORM

βœ” Middleware

βœ” Centralized Logging

βœ” Exception Handling

βœ” Docker Support

βœ” Automated Testing

βœ” Environment-based Configuration


πŸ“š Key Learning Outcomes

This project provided hands-on experience with:

  • FastAPI
  • SQLAlchemy ORM
  • JWT Authentication
  • Password Hashing
  • Docker
  • Pytest
  • Logging
  • Middleware
  • Dependency Injection
  • Clean Architecture
  • Linux
  • Backend Debugging

πŸš€ Future Improvements

  • PostgreSQL
  • Alembic Migrations
  • Docker Compose
  • Redis Integration
  • Background Tasks
  • Refresh Tokens
  • Role-Based Access Control (RBAC)
  • CI/CD using GitHub Actions
  • API Versioning

πŸ‘¨β€πŸ’» Author

Mehfooz

Python Backend Developer

GitHub

https://github.com/whoismehfooz


⭐ If you found this project interesting, consider giving it a Star!

About

πŸ‘‰ A production-grade FastAPI backend featuring JWT authentication, SQLAlchemy ORM, Docker, middleware, logging, testing, and clean architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages