Installation Guide
Installation Guide
This guide covers different ways to install and set up the FastAPI Boilerplate depending on your needs and environment.
System Requirements
Before you begin, ensure your system meets these requirements:
- Python: 3.11 or higher
- Operating System: Linux, macOS, or Windows (with WSL2 recommended)
- Memory: Minimum 4GB RAM (8GB recommended)
- Disk Space: At least 2GB free space
Method 1: Docker Compose (Recommended)
Docker Compose is the easiest way to get started. It handles all dependencies and services automatically.
Prerequisites
Install these tools on your system:
- Docker (version 20.10+)
- Docker Compose (version 1.29+)
Installation Steps
-
Get the template:
git clone https://github.com/benavlabs/fastapi-boilerplate cd fastapi-boilerplate -
Set up environment:
cp src/.env.example src/.env # Edit src/.env with your configuration -
Start services:
docker compose up -d -
Verify installation:
curl http://localhost:8000/docs
What Gets Installed
Docker Compose sets up these services:
- Web server (FastAPI + Uvicorn) on port 8000
- PostgreSQL database on port 5432 (internal)
- Redis server on port 6379 (internal)
- ARQ Worker for background tasks
- NGINX (optional, for production)
Method 2: Manual Installation
For more control or development purposes, you can install everything manually.
Prerequisites
-
Install Python 3.11+:
# On Ubuntu/Debian sudo apt update sudo apt install python3.11 python3.11-pip # On macOS (with Homebrew) brew install python@3.11 # On Windows # Download from python.org -
Install uv (Python package manager):
pip install uv -
Install PostgreSQL:
# On Ubuntu/Debian sudo apt install postgresql postgresql-contrib # On macOS brew install postgresql # On Windows # Download from postgresql.org -
Install Redis:
# On Ubuntu/Debian sudo apt install redis-server # On macOS brew install redis # On Windows # Download from redis.io
Installation Steps
-
Clone the repository:
git clone https://github.com/benavlabs/fastapi-boilerplate cd fastapi-boilerplate -
Install Python dependencies:
uv sync -
Set up environment variables:
cp src/.env.example src/.env # Edit src/.env with your local database/Redis settings -
Set up PostgreSQL:
# Create database and user sudo -u postgres psql CREATE DATABASE myapp; CREATE USER myuser WITH PASSWORD 'mypassword'; GRANT ALL PRIVILEGES ON DATABASE myapp TO myuser; \q -
Run database migrations:
cd src uv run alembic upgrade head -
Create admin user:
uv run python -m src.scripts.create_first_superuser -
Start the application:
uv run uvicorn src.app.main:app --reload --host 0.0.0.0 --port 8000 -
Start the worker (in another terminal):
uv run arq src.app.core.worker.settings.WorkerSettings
Method 3: Development Setup
For contributors and advanced users who want to modify the boilerplate.
Additional Prerequisites
- Git for version control
- Pre-commit for code quality
Installation Steps
-
Fork and clone:
# Fork the repository on GitHub first git clone https://github.com/yourusername/fastapi-boilerplate cd fastapi-boilerplate -
Install development dependencies:
uv sync --group dev -
Set up pre-commit hooks:
uv run pre-commit install -
Set up development environment:
cp src/.env.example src/.env # Configure for development -
Run tests to verify setup:
uv run pytest
Docker Services Breakdown
Understanding what each Docker service does:
Web Service
web:
build: .
ports:
- "8000:8000"
depends_on:
- db
- redis- Runs the FastAPI application
- Handles HTTP requests
- Auto-reloads on code changes (development)
Database Service
db:
image: postgres:13
environment:
POSTGRES_DB: myapp
POSTGRES_USER: postgres
POSTGRES_PASSWORD: changethis- PostgreSQL database server
- Persistent data storage
- Automatic initialization
Redis Service
redis:
image: redis:alpine
command: redis-server --appendonly yes- In-memory data store
- Used for caching and job queues
- Persistent storage with AOF
Worker Service
worker:
build: .
command: arq src.app.core.worker.settings.WorkerSettings
depends_on:
- redis- Background task processor
- Handles async jobs
- Scales independently
Configuration
Environment Variables
The application uses environment variables for configuration. Key variables:
# Database
POSTGRES_USER=postgres
POSTGRES_PASSWORD=changethis
POSTGRES_SERVER=localhost # or "db" for Docker
POSTGRES_PORT=5432
POSTGRES_DB=myapp
# Redis
REDIS_CACHE_HOST=localhost # or "redis" for Docker
REDIS_CACHE_PORT=6379
# Security
SECRET_KEY=your-secret-key-here
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30Database Connection
For manual installation, update your database settings:
# Local PostgreSQL
POSTGRES_SERVER=localhost
POSTGRES_PORT=5432
# Docker PostgreSQL
POSTGRES_SERVER=db
POSTGRES_PORT=5432Verification
After installation, verify everything works:
- API Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/services/v1/health
- Database Connection: Check logs for successful connection
- Redis Connection: Test caching functionality
- Background Tasks: Submit a test job
Troubleshooting
Common Issues
Port Already in Use:
# Check what's using port 8000
lsof -i :8000
# Kill the process
kill -9 <PID>Database Connection Error:
# Check PostgreSQL status
sudo systemctl status postgresql
# Restart PostgreSQL
sudo systemctl restart postgresqlRedis Connection Error:
# Check Redis status
redis-cli ping
# Start Redis
redis-serverPermission Errors:
# Fix Docker permissions
sudo usermod -aG docker $USER
# Log out and back inDocker Issues
Clean Reset:
# Stop all containers
docker compose down
# Remove volumes (⚠️ deletes data)
docker compose down -v
# Rebuild images
docker compose build --no-cache
# Start fresh
docker compose upNext Steps
After successful installation:
- Configuration Guide - Set up your environment
- First Run - Test your installation
- Project Structure - Understand the codebase
Need Help?
If you encounter issues:
- Check the GitHub Issues for common problems
- Search existing issues
- Create a new issue with details