Skip to content

🧱 Modular FastAPI Starter Backend – A production-ready starter template for building scalable backend APIs with FastAPI, featuring a clean modular architecture, JWT authentication, PostgreSQL/SQLite support, .env configuration, and pre-built Auth & User modules. Perfect foundation for small projects, MVPs, or full-scale backends.

License

ngusadeep/Modular-FastAPI-starter-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¦ Modular FastAPI Starter Backend

This is a starter backend project built with FastAPI following a clean and modular architecture. It comes with ready-to-use Authentication (JWT), User module, database integration, and .env-based configuration β€” perfect as a foundation for larger projects.

πŸ—‚οΈ Project Structure

.
β”œβ”€β”€ app
β”‚   β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”œβ”€β”€ config.py         # Environment and settings configuration
β”‚   β”œβ”€β”€ db/
β”‚   β”‚   └── database.py       # Database connection (PostgreSQL or SQLite)
β”‚   β”œβ”€β”€ main.py              # FastAPI entry point
β”‚   └── modules/
β”‚       β”œβ”€β”€ auth/            # Authentication module
β”‚       β”‚   β”œβ”€β”€ dependencies.py
β”‚       β”‚   β”œβ”€β”€ routes.py
β”‚       β”‚   β”œβ”€β”€ schemas.py
β”‚       β”‚   └── services.py
β”‚       └── user/            # User module
β”‚           β”œβ”€β”€ models.py
β”‚           β”œβ”€β”€ routes.py
β”‚           β”œβ”€β”€ schemas.py
β”‚           └── services.py
β”œβ”€β”€ database.db
β”œβ”€β”€ .env
β”œβ”€β”€ .env.example
β”œβ”€β”€ requirements.txt
└── .ropeproject

πŸš€ Features

βœ… Modular structure β€” auth and user separated cleanly βœ… JWT authentication (login, register, protected routes) βœ… Forgot/Reset password flow βœ… CORS configuration via .env βœ… PostgreSQL or SQLite support βœ… Ready for /api/v1 route versioning βœ… Auto-generated Swagger docs (/docs)

βš™οΈ Setup & Installation

1️⃣ Clone the repository

git clone https://github.com/your-username/fastapi-starter-backend.git
cd fastapi-starter-backend

2️⃣ Create a virtual environment

python -m venv .venv
source .venv/bin/activate   # Linux/Mac
# OR
.venv\Scripts\activate      # Windows

3️⃣ Install dependencies

pip install -r requirements.txt

4️⃣ Configure environment variables

Copy the .env.example to .env and update values:

cp .env.example .env

.env example:

# App info
APP_TITLE=Modular FastAPI API
APP_DESCRIPTION=Backend API for Auth and User Modules
APP_VERSION=1.0.0

# Auth
SECRET_KEY=your_secret
ACCESS_TOKEN_EXPIRE_MINUTES=30
ALGORITHM=HS256

# Database
DATABASE_URL=postgresql+psycopg2://username:password@localhost:5432/your_db_name
# DATABASE_URL=sqlite:///database.db

# CORS
FRONTEND_URL=http://localhost:3000

πŸ” Generate a Secret Key

Use Python to generate a secure SECRET_KEY:

python -c "import secrets; print(secrets.token_hex(32))"

Copy the output and paste it into .env as SECRET_KEY.

πŸ—„οΈ Database Setup

Make sure PostgreSQL is running (or use SQLite). Then create the database:

psql -U postgres -c "CREATE DATABASE your_db_name;"

Or update .env to use SQLite for local development:

DATABASE_URL=sqlite:///./database.db

▢️ Run the Server

From the project root:

uvicorn app.main:app --reload

The API will be available at:

πŸ”‘ Authentication Endpoints

Endpoint Method Description
/api/v1/auth/register POST Register a new user
/api/v1/auth/login POST Login and get JWT token
/api/v1/auth/forgot-password POST Generate a password reset token
/api/v1/auth/reset-password POST Reset password using token

Use the JWT token returned from login as a Bearer Token in protected routes like:

GET /api/v1/users/me
Authorization: Bearer <your_access_token>

🧱 Future Improvements

  • Add role-based access (Admin, User)
  • Add email service integration for password reset
  • Add unit tests and CI/CD
  • Author : Ngusa

🀝 Contributing

Contributions are welcome! If you'd like to improve this project, feel free to fork the repository, create a new branch, and submit a pull request.

Steps:

  1. Fork this repo
  2. Create your feature branch: git checkout -b feature/your-feature
  3. Commit your changes: git commit -m 'Add some feature'
  4. Push to the branch: git push origin feature/your-feature
  5. Open a pull request πŸš€

πŸ“œ License

By contributing, you agree that your contributions will be licensed under the MIT License Β© 2025

About

🧱 Modular FastAPI Starter Backend – A production-ready starter template for building scalable backend APIs with FastAPI, featuring a clean modular architecture, JWT authentication, PostgreSQL/SQLite support, .env configuration, and pre-built Auth & User modules. Perfect foundation for small projects, MVPs, or full-scale backends.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages