A modern, production-ready FastAPI template for building scalable APIs.
- 🔄 Complete CRUD operations for heroes
- 📊 Async SQLAlchemy with PostgreSQL
- 🔄 Automatic Alembic migrations
- 🏗️ Clean architecture with repository pattern
⚠️ Custom exception handling- 🔍 CI and testing pipeline
- 🧹 Linter setup with pre-commit hooks
- 🚂 One-click Railway deployment
api/
├── core/ # Core functionality
│ ├── config.py # Environment and app configuration
│ ├── database.py # Database connection and sessions
│ ├── exceptions.py # Global exception handlers
│ ├── logging.py # Logging configuration
│ └── security.py # Authentication and security
├── src/
│ ├── heroes/ # Heroes module
│ │ ├── models.py # Database models
│ │ ├── repository.py # Data access layer
│ │ ├── routes.py # API endpoints
│ │ └── schemas.py # Pydantic models
│ └── users/ # Users module
│ ├── models.py # User models
│ ├── repository.py # User data access
│ ├── routes.py # User endpoints
│ └── schemas.py # User schemas
├── utils/ # Utility functions
└── main.py # Application entry point
- Python 3.8+
- PostgreSQL
-
Install uv (follow instructions here)
-
Clone the repository:
git clone https://github.com/yourusername/minimalistic-fastapi-template.git
cd minimalistic-fastapi-template
- Install dependencies with uv:
uv sync
- Set up environment variables:
cp .env.example .env
# Edit .env with your database credentials
💡 Important:
- The DATABASE_URL must start with
postgresql+asyncpg://
(e.g.,postgresql+asyncpg://user:pass@localhost:5432/dbname
)- After updating environment variables, close and reopen VS Code to reload the configuration properly. VS Code will automatically activate the virtual environment when you reopen.
- Start the application:
Using terminal:
uv run uvicorn api.main:app
Using VS Code:
💡 If you're using VS Code, we've included run configurations in the
.vscode
folder. Just pressF5
or use the "Run and Debug" panel to start the application!
- (Optional) Enable pre-commit hooks for linting:
uv run pre-commit install
💡 This will enable automatic code formatting and linting checks before each commit
- Make changes to your models
- Generate migration:
alembic revision --autogenerate -m "your migration message"
Note: Migrations will be automatically applied when you start the application - no need to run alembic upgrade head
manually!
GET /heroes
- List all heroesGET /heroes/{id}
- Get a specific heroPOST /heroes
- Create a new heroPATCH /heroes/{id}
- Update a heroDELETE /heroes/{id}
- Delete a hero
POST /auth/register
- Register a new userPOST /auth/login
- Login and get access tokenGET /auth/me
- Get current user profile
Create a new hero:
curl -X POST "http://localhost:8000/heroes/" -H "Content-Type: application/json" -d '{
"name": "Peter Parker",
"alias": "Spider-Man",
"powers": "Wall-crawling, super strength, spider-sense"
}'