An open API service indexing awesome lists of open source software.

https://github.com/ahmadalsharef994/fastapi-postgres-boilerplate

Production-Ready Starter Template, FastAPI + PostgreSQL boilerplate with Docker, GitHub Actions, and clean architecture.
https://github.com/ahmadalsharef994/fastapi-postgres-boilerplate

api backend boilerplate docker fastapi guthub-actions postgres python template

Last synced: 2 months ago
JSON representation

Production-Ready Starter Template, FastAPI + PostgreSQL boilerplate with Docker, GitHub Actions, and clean architecture.

Awesome Lists containing this project

README

          

# ๐Ÿš€ FastAPI + PostgreSQL Boilerplate


Python
FastAPI
PostgreSQL
Docker
CI
License

A **production-ready starter template** for building FastAPI applications with PostgreSQL โ€” clean architecture, Docker Compose setup, and GitHub Actions CI included out of the box.

---

## โœจ What's Included

- โœ… **FastAPI** with async route handlers
- โœ… **SQLAlchemy 2.0** ORM with PostgreSQL
- โœ… **Alembic** for database migrations
- โœ… **Docker + Docker Compose** โ€” one command to start everything
- โœ… **GitHub Actions CI** โ€” runs tests on every push
- โœ… **Dependency injection** โ€” clean, testable service layer
- โœ… **Pydantic v2** request/response validation
- โœ… **Auto-generated Swagger UI** at `/docs`

---

## ๐Ÿš€ Quick Start

```bash
git clone https://github.com/ahmadalsharef994/fastapi-postgres-boilerplate.git
cd fastapi-postgres-boilerplate

cd infra/docker
docker-compose up --build
```

API: `http://localhost:8000`
Swagger: `http://localhost:8000/docs`

### Without Docker

```bash
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt

# Set up DB
alembic upgrade head

uvicorn app.main:app --reload
```

---

## ๐Ÿ“ Structure

```
app/
โ”œโ”€โ”€ main.py # FastAPI app entry point
โ”œโ”€โ”€ db/
โ”‚ โ”œโ”€โ”€ base.py # SQLAlchemy base + session
โ”‚ โ””โ”€โ”€ models.py # ORM models
โ”œโ”€โ”€ routes/ # API route handlers
โ”œโ”€โ”€ schemas/ # Pydantic schemas
โ”œโ”€โ”€ services/ # Business logic layer
โ””โ”€โ”€ dependencies.py # DI container
infra/
โ””โ”€โ”€ docker/
โ””โ”€โ”€ docker-compose.yml
.github/
โ””โ”€โ”€ workflows/ci.yml # GitHub Actions
```

---

## โš™๏ธ Environment Variables

```env
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/dbname
SECRET_KEY=your-secret-key
DEBUG=true
```

---

## ๐Ÿงช Testing

```bash
pytest tests/ -v --cov=app
```

---

## ๐Ÿ“„ License

MIT โ€” Start building faster ๐Ÿ’ก