Skip to content

A simple and fast FastAPI backend template with JWT auth, SQLModel ORM, Alembic migrations, orjson, and secure configuration — built for speed, security, and ease of use. Runs on Uvicorn with worker support for better concurrency.

Notifications You must be signed in to change notification settings

Dev-Shivaprasad/Fastapi-Template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

⚡ FastAPI Full-Stack Template

A production-ready FastAPI full-stack boilerplate to kickstart your modern backend projects with a clean architecture. Built with performance and scalability in mind, this template comes with everything you need for rapid development.

Before Getting Started understand the Project Structure

🚀 Getting Started

1. 📥 Clone the repository

git clone https://github.com/Dev-Shivaprasad/Fastapi-Tamplate.git

cd fastapi-fullstack-template/backend

2. 🧪 Create VENV and install dependencies

uv sync

3. ⚙️ Create .env file and copy all variables

  • There is already a file is provided called example_env.txt which contains all the necessary variables just replace them.
# linux
cp example_env.txt .env
# windows
copy example_env.txt .env

4. 🔄 Run migrations

  • All the DataBase table schemas and models are stored in the models/ folder
alembic upgrade head

use alembic revision --autogenerate -m <name_of_the_migration> to create the migration
or
alembic revision -m <name_of_the_migration> for empty migration

5. 🚀 Run the server

All the necessary server configuration is done in the main.py file
docs / Swagger UI is locally hosted on this link http://localhost:8000/docs

uv run main.py

✨ Features

  • ⚡ FastAPI + Uvicorn — High-performance async API server

  • 🔗 SQLModel — ORM by the creator of FastAPI (based on SQLAlchemy)

  • 📦 Alembic — Robust and flexible database migrations

  • 🔐 JWT Authentication — Secure token-based auth with PyJWT

  • 🧂 Password Hashing — Credential hashing via Bcrypt

  • 🚀 Orjson — Super-fast JSON parsing for response speed

  • 🧩 Modular Architecture — Clean, scalable, and organized codebase

  • 🌱 .env Support — Environment-based flexible configuration

  • ⏱️ Rate Limiting — Prevent abuse & DoS

  • 🐳 Docker — Dockerfile, docker-compose, and Nginx setup

  • 🟥 Redis — Caching layer


📁 Project Structure

FASTAPI-TEMPLATE/

├── backend/
│ ├── .venv/ # uv-managed virtual environment
│ │
│ ├── alembic # Alembic migration files
│ │
│ ├── core
│ │├─ authentication/ # JWT logic, login, password hashing
│ │├─ cache/ # redis cache setup and initialization (optional)
│ │├─ database/ # DB session setup and initialization
│ │├─ ratelimiter/ # ratelimiter setup and initialization (optional)
│ │└─ helperfunctions.py # contains helper functions
│ │
│ ├── docker/ (optional)
│ │ ├─ .dockerignore # Docker build exclusions
│ │ └─ .Dockerfile # Backend container definition
│ │ │ ├── services/ # contains services (like JWT middleware) for business logic and operations.
│ │
│ ├── src/
│ │ ├─ controllers/ # API route handlers
│ │ ├─ models/ # SQLModel ORM models
│ │ └─ ControllerTemplate.py # controller boilerplate
│ │
│ ├── .env.backup # a demo .env
│ ├── .gitignore # File specifying untracked files to ignore.
│ ├── .python-version # Python version pin
│ ├── alembic.ini # Alembic configuration
│ ├── main.py # App entry point
│ ├── pyproject.toml # uv dependency definition
│ └── uv.lock # Dependency lock file

├── docker_and_nginix_configurations/ (optional)
│ ├── env.production # Production environment
│ ├── docker-compose.dev.yml # Development Docker Compose
│ ├── docker-compose.yml # Main Docker Compose configuration
│ ├── DOCKER.md # Docker documentation
│ ├── env.production.example # Production environment template
│ └── nginx.conf # Nginx reverse proxy config

├── frontend/ # Optional frontend (React, Vue, etc.)

└── README.md # Main documentation


🐳 Docker Setup (Optional)

For containerized development and deployment, we now provide comprehensive Docker support:

Quick Start with Docker

Development Environment:

# Start development environment with hot reload
docker-compose -f ./docker_and_nginix_configurations/docker-compose.dev.yml up --build

Production Environment:

# Copy production environment template
cp ./docker_and_nginix_configurations/env.production.example docker_and_nginix_configurations/.env.production
# Edit .env.production with your values
# Start production stack
docker-compose --env-file ./docker_and_nginix_configurations/.env.production --profile production up -d

Docker Features

  • 🚀 Multi-stage builds : for optimized production images
  • 🔄 Hot reload : for development
  • 🗄️ PostgreSQL : for production database
  • 🔒 Nginx : reverse proxy and abstraction
  • 📊 Health checks : and monitoring
  • 🔐 Security : best practices

📖 Full Docker documentation: See DOCKER.md for detailed setup and usage instructions.


🧩 Future Enhancements

Here’s what’s planned or coming soon:

  • Rate Limiting — Prevent abuse & DoS

  • Nginx — secure routing and abstraction

  • Docker — Dockerfile & docker-compose setup

  • Redis — Caching layer


💡 Frontend?

  • The frontend/ folder is a placeholder — use it with any frontend framework like:

  • ⚛️ React / Next.js

  • 🔥 Vue / Nuxt

  • 🌌 Astro / SvelteKit

You can remove it if not needed.


🙌 Contributions

Feel free to open issues, suggest improvements, or submit a pull request. Let’s make this great together 😊.

About

A simple and fast FastAPI backend template with JWT auth, SQLModel ORM, Alembic migrations, orjson, and secure configuration — built for speed, security, and ease of use. Runs on Uvicorn with worker support for better concurrency.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •