1- # Hero API
2-
3- A FastAPI-based CRUD application for managing heroes, following best practices and modern Python async patterns.
4-
5- ## Features
6-
7- - Full CRUD operations for heroes
8- - Async SQLAlchemy with PostgreSQL
9- - Alembic migrations
10- - Clean architecture with repository pattern
11- - Custom exception handling
12- - Type hints and documentation
13-
14- ## Project Structure
15-
1+ # Hero API π¦ΈββοΈ
2+ A modern, production-ready FastAPI template for building scalable APIs.
3+
4+ ## Features β¨
5+ - π Complete CRUD operations for heroes
6+ - π Async SQLAlchemy with PostgreSQL
7+ - π Automatic Alembic migrations
8+ - ποΈ Clean architecture with repository pattern
9+ - β οΈ Custom exception handling
10+ - π CI and testing pipeline
11+ - π§Ή Linter setup with pre-commit hooks
12+ - π One-click Railway deployment
13+
14+ ## Deploy Now! π
15+ [ ![ Deploy on Railway] ( https://railway.com/button.svg )] ( https://railway.com/template/wbTudS?referralCode=beBXJA )
16+
17+ ## Project Structure π
1618```
17- app/
18- βββ core/
19- β βββ config.py # Application configuration
20- β βββ database.py # Database setup and session management
21- βββ heroes/
22- β βββ exceptions.py # Custom exceptions
23- β βββ models.py # SQLAlchemy models
24- β βββ repository.py # Database operations
25- β βββ routes.py # API endpoints
26- β βββ schemas.py # Pydantic models
27- β βββ service.py # Business logic
28- βββ main.py # FastAPI application setup
19+ api/
20+ βββ core/ # Core functionality
21+ β βββ config.py # Environment and app configuration
22+ β βββ database.py # Database connection and sessions
23+ β βββ exceptions.py # Global exception handlers
24+ β βββ logging.py # Logging configuration
25+ β βββ security.py # Authentication and security
26+ βββ src/
27+ β βββ heroes/ # Heroes module
28+ β β βββ models.py # Database models
29+ β β βββ repository.py # Data access layer
30+ β β βββ routes.py # API endpoints
31+ β β βββ schemas.py # Pydantic models
32+ β βββ users/ # Users module
33+ β βββ models.py # User models
34+ β βββ repository.py # User data access
35+ β βββ routes.py # User endpoints
36+ β βββ schemas.py # User schemas
37+ βββ utils/ # Utility functions
38+ βββ main.py # Application entry point
2939```
3040
31- ## Requirements
32-
41+ ## Requirements π
3342- Python 3.8+
3443- PostgreSQL
35- - Dependencies listed in requirements.txt
3644
37- ## Setup
45+ ## Setup π οΈ
46+ 1 . Install uv (follow instructions [ here] ( https://docs.astral.sh/uv/#getting-started ) )
3847
39- 1 . Create a virtual environment :
48+ 2 . Clone the repository :
4049``` bash
41- python -m venv venv
42- source venv/bin/activate # Linux/Mac
43- venv\S cripts\a ctivate # Windows
50+ git clone https://github.com/yourusername/minimalistic-fastapi-template.git
51+ cd minimalistic-fastapi-template
4452```
4553
46- 2 . Install dependencies:
54+ 3 . Install dependencies with uv :
4755``` bash
48- pip install -r requirements.txt
49- ```
50-
51- 3 . Create PostgreSQL database:
52- ``` sql
53- CREATE DATABASE hero_db ;
56+ uv sync
5457```
5558
56- 4 . Set up environment variables (or create .env file):
57- ```
58- DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/hero_db
59+ 4 . Set up environment variables:
60+ ``` bash
61+ cp .env.example .env
62+ # Edit .env with your database credentials
5963```
6064
61- 5 . Run database migrations :
65+ 5 . Start the application :
6266``` bash
63- alembic upgrade head
67+ uv run uvicorn app.main:app
6468```
6569
66- 6 . Start the application:
70+ ## Creating a Migration π
71+ 1 . Make changes to your models
72+ 2 . Generate migration:
6773``` bash
68- uvicorn app.main:app --reload
74+ alembic revision --autogenerate -m " your migration message "
6975```
7076
71- ## API Endpoints
77+ Note: Migrations will be automatically applied when you start the application - no need to run ` alembic upgrade head ` manually!
7278
79+ ## API Endpoints π
80+ ### Heroes
7381- ` GET /heroes ` - List all heroes
7482- ` GET /heroes/{id} ` - Get a specific hero
7583- ` POST /heroes ` - Create a new hero
7684- ` PATCH /heroes/{id} ` - Update a hero
7785- ` DELETE /heroes/{id} ` - Delete a hero
7886
79- ## Example Usage
87+ ### Authentication
88+ - ` POST /auth/register ` - Register a new user
89+ - ` POST /auth/login ` - Login and get access token
90+ - ` GET /auth/me ` - Get current user profile
8091
92+ ## Example Usage π
8193Create a new hero:
8294``` bash
8395curl -X POST " http://localhost:8000/heroes/" -H " Content-Type: application/json" -d ' {
@@ -86,15 +98,3 @@ curl -X POST "http://localhost:8000/heroes/" -H "Content-Type: application/json"
8698 "powers": "Wall-crawling, super strength, spider-sense"
8799}'
88100```
89-
90- ## Development
91-
92- To create a new database migration:
93- ``` bash
94- alembic revision --autogenerate -m " description"
95- ```
96-
97- To apply migrations:
98- ``` bash
99- alembic upgrade head
100- ```
0 commit comments