Skip to content

A production-ready FastAPI boilerplate enforcing Clean Architecture. Features structured directory layouts, JWT-based security, Pydantic v2 validation, and scalable dependency injection patterns

Notifications You must be signed in to change notification settings

brianobot/fastAPI_project_structure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Project Structure Template

📖 Read Article here

This repository provides a clean and scalable template for building FastAPI applications. It is designed to help you start new projects quickly with best practices in mind.

Features

  • Organized project structure
  • Environment configuration
  • Dependency management
  • Initial User Model and User Authentication Endpoints with Unit Tests
  • Unit Test Configuration with Pytest (With Async Support)
  • Alembic Data Migration Configuration

Getting Started

In order to get started with the FastAPI Project, follow the following steps

  • Create an .env file from the .env.example file and provide values for missing environment variables - 1. Update the DATABASE_URL to point at an accessible DATABASE server - 2. Update the MAIL_CONFIG section to include mail server credentials

  • Install make if you do not already have it and run the command make run-local to start you local server

  • Apply Initial Database Migration for Ensure Database Connection string is valid bash alembic upgrade head

  • Ensure the Setup Is Complete and Sucessful by Running the following command bash make test-local If all the tests pass successfully you're good to start working on your project.

  • Start Local Server with the following command bash make run-local

Project Structure

fastapi-project-structure/
.
├── Makefile
├── app
│   ├── __init__.py
│   ├── api_router.py
│   ├── database.py
│   ├── dependencies.py
│   ├── logger.py
│   ├── main.py
│   ├── middlewares.py
│   ├── models
│   │   ├── __init__.py
│   │   └── auth.py
│   ├── routers
│   │   ├── __init__.py
│   │   └── auth.py
│   ├── schemas
│   │   ├── __init__.py
│   │   └── auth.py
│   ├── services
│   │   ├── __init__.py
│   │   └── auth.py
│   └── settings.py
├── logs
└── requirements.txt

Getting Started

  1. Clone the repository:

    git clone https://github.com/brianobot/fastAPI_project_structure.git
    cd fastAPI_project_structure
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the application:

    make run-local # or uvicorn app.main:app --reload
  4. Access the API docs:

Testing

Run tests using pytest:

pytest

Environment Variables

Copy .env.example to .env and update the values as needed.

Contributing

Contributions are welcome! Please open issues or submit pull requests.

About

A production-ready FastAPI boilerplate enforcing Clean Architecture. Features structured directory layouts, JWT-based security, Pydantic v2 validation, and scalable dependency injection patterns

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published