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