FastAPI Admin Template

A modern FastAPI admin template with SQLModel and Starlette Admin.

Prerequisites

  • Python 3.11 or higher
  • PostgreSQL
  • UV package manager

Setup

  1. Install UV if you haven't already:
curl -LsSf https://astral.sh/uv/install.sh | sh
  1. Create and activate a virtual environment:
uv venv
source .venv/bin/activate  # On Unix/macOS
# or
.venv\Scripts\activate     # On Windows
  1. Install dependencies:
uv pip install -e ".[dev]"
  1. Copy .env.example to .env and configure your environment variables:
cp .env.example .env
  1. Initialize the database:
alembic upgrade head

Running the Application

Start the development server:

uvicorn app.main:app --reload

The admin interface will be available at http://localhost:8000/admin

Development Scripts

Testing

Run the test suite:

# Run all tests
pytest

# Run tests with coverage report
pytest --cov=app

# Run specific test file
pytest tests/test_specific.py

Code Quality

# Lint your code
ruff check .

# Lint with auto-fix
ruff check --fix .

# Format your code
ruff format .

Database Operations

# Create a new migration
alembic revision --autogenerate -m "describe your changes"

# Apply all pending migrations
alembic upgrade head

# Rollback last migration
alembic downgrade -1

# Check current migration status
alembic current

Project Structure

fastapi-admin-template/
├── app/
│   ├── api/
│   ├── core/
│   ├── models/
│   └── main.py
├── alembic/
├── tests/
└── pyproject.toml