FastStart is a modular and flexible starting point for building backend microservices with FastAPI. This repository provides a robust base structure with various extensions and configurations to help you get started quickly and efficiently.
- Multiple Variations: Different branches provide various features and integrations (see Branches table below).
- Extensible: Easily add and customize features as per your project requirements.
- Best Practices: Follow industry best practices for code organization, security, and performance.
| Branch Name | Description |
|---|---|
| main | A lightweight, stripped-down FastAPI starter with only essential boilerplate. |
| base | Builds on main by adding improved OpenAPI documentation, better error handling, and common middleware utilities. |
| sqlalchemy | Extends base with integrated support for Async SQLAlchemy to handle asynchronous database operations efficiently. |
| log-viewer | Extends base with a built-in log viewer for inspecting application logs directly from the browser. |
To get started with the FastAPI Starter Kit, follow the steps:
Before setting up this project, you should be familiar with:
- uv: A fast tool for managing Python packages, environments, and project dependencies.
- Clone the Repository
git clone --single-branch -b sqlalchemy https://github.com/Hoopoes/FastStart.git
cd FastStart- Install Dependencies
uv sync- Initialize Alembic
(Optional) Skip this if the alembic/ folder already exists
uv run alembic init -t async alembicThis creates the alembic folder and a preconfigured async-compatible env.py.
- Create and Apply Initial Migration
Edit alembic/env.py to import your models and use the correct SQLALCHEMY_DATABASE_URL from your settings.
# Create initial migration from SQLAlchemy models
uv run alembic revision --autogenerate -m "Initial tables"- Apply Existing Migrations
If you already have migrations and just need to apply them (without generating new ones), you can use:
uv run alembic upgrade headThis will apply any pending migrations to your SQL database.
- Run the Application
uv run python main.py📦Project
┣ 📂app
┃ ┣ 📂db
┃ ┣ 📂errors
┃ ┣ 📂middlewares
┃ ┣ 📂models
┃ ┣ 📂routes
┃ ┃ ┣ 📂v1
┃ ┃ ┃ ┣ 📂endpoints
┃ ┃ ┃ ┃ ┗ 🐍user.py
┃ ┃ ┃ ┗ 🐍v1_route.py
┃ ┃ ┗ 🐍route.py
┃ ┣ 📂schemas
┃ ┣ 📂services
┃ ┣ 📂utils
┃ ┗ 🐍server.py
┣ 📂db
┣ 📂docs
┣ 📂logs
┣ 📂alembic
┣ 🗝️.env
┣ 🗝️.env.example
┣ 📜.gitattributes
┣ 📜.gitignore
┣ 📜alembic.ini
┣ 🐍config.py
┣ 🐍main.py
┣ 🔒uv.lock
┗ ⚙️pyproject.toml
-
Root Directory: Configuration files and entry points.
-
app: Main application directory.
- db: Database configuration and connection setup (e.g. engine, session, initialization).
- errors: Custom error response definitions, including error documentation for swagger.
- middlewares: Custom middleware for request/response processing and exception handling.
- models: Database models & core application objects.
- routes: API endpoints and route handlers.
- v1 – Versioned API routes (e.g., v1). Additional versions like v2 or v3 can be created as needed for backward compatibility.
- schemas: Data Transfer Objects (DTOs) & validation schemas (
pydantic). - services: Business logic.
- utils: Helper utilities for various tasks (e.g. logging).
server.py: Sets up and configures the FastAPI server.
-
db: Local SQLite database that is ignored by Git.
-
docs: Project documentation.
-
logs: Log files.
-
alembic: Alembic Migrations files.
env.py: Configures DB connection and runs migrations.
-
.env: Secret Environment configuration that is ignored by Git.
-
.env.example: Example environment configuration file that is not ignored by Git.
-
alembic.ini: Alembic config file for database connection, migration paths, and settings.
-
config.py: Project configurations, such as loading environment keys.
-
main.py: Application entry point.
-
uv.lock, pyproject.toml: Dependency management.
-
The log-viewer branch adds a built-in log viewer for inspecting application logs directly from the browser.
To access the Log Viewer, simply navigate to the appropriate route in the application (you may need to configure the path depending on your setup). This feature helps you monitor the logs and debug your application more effectively.
For any questions or feedback, please reach out to:
- Muhammad Umar Anzar - [email protected]
Or open an issue on GitHub.
