
- Add modern formatting with emojis and clear sections - Include detailed API reference with request/response examples - Add project structure overview - Include development, deployment, and contribution guidelines - Enhance quick start instructions with virtual environment setup - Add health check documentation and code quality tools
FastAPI Todo Application
A modern, fast, and feature-rich todo management API built with FastAPI, SQLAlchemy, and SQLite.
🚀 Quick Start
Prerequisites
- Python 3.8+
- pip package manager
Installation & Setup
-
Clone and navigate to the project:
git clone <repository-url> cd todoapp
-
Create a virtual environment (recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Initialize the database:
alembic upgrade head
-
Start the server:
uvicorn main:app --host 0.0.0.0 --port 8000
The API will be available at http://localhost:8000
📋 Features
- ✅ Full CRUD Operations - Create, read, update, and delete todos
- 🔍 Pagination Support - Efficient handling of large todo lists
- 📊 SQLite Database - Lightweight, serverless database
- 🔄 Database Migrations - Version-controlled schema changes with Alembic
- 📚 Auto-generated Documentation - Interactive API docs with Swagger UI
- 🌐 CORS Enabled - Cross-origin requests supported
- 💪 Type Safety - Full Pydantic validation and type hints
- 🏥 Health Monitoring - Built-in health check endpoint
- 🎯 Production Ready - Structured codebase with best practices
🛠 Tech Stack
- FastAPI - Modern, fast web framework for building APIs
- SQLAlchemy - SQL toolkit and ORM
- Alembic - Database migration tool
- Pydantic - Data validation using Python type annotations
- SQLite - Lightweight, file-based database
- Uvicorn - Lightning-fast ASGI server
📡 API Reference
Base Endpoints
Method | Endpoint | Description |
---|---|---|
GET | / |
API information and links |
GET | /health |
Health check status |
GET | /docs |
Interactive API documentation |
GET | /redoc |
Alternative API documentation |
GET | /openapi.json |
OpenAPI specification |
Todo Management
Method | Endpoint | Description | Request Body |
---|---|---|---|
POST | /todos/ |
Create a new todo | TodoCreate |
GET | /todos/ |
List all todos | Query params: skip , limit |
GET | /todos/{todo_id} |
Get specific todo | - |
PUT | /todos/{todo_id} |
Update todo | TodoUpdate |
DELETE | /todos/{todo_id} |
Delete todo | - |
Request/Response Models
TodoCreate
{
"title": "string",
"description": "string (optional)",
"completed": false
}
TodoUpdate
{
"title": "string (optional)",
"description": "string (optional)",
"completed": "boolean (optional)"
}
TodoResponse
{
"id": 1,
"title": "string",
"description": "string",
"completed": false,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-01T00:00:00Z"
}
🗂 Project Structure
todoapp/
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
├── alembic.ini # Alembic configuration
├── ruff.toml # Code linting configuration
├── app/
│ ├── __init__.py
│ ├── db/
│ │ ├── __init__.py
│ │ ├── base.py # SQLAlchemy Base class
│ │ └── session.py # Database session configuration
│ ├── models/
│ │ ├── __init__.py
│ │ └── todo.py # Todo SQLAlchemy model
│ └── schemas/
│ ├── __init__.py
│ └── todo.py # Pydantic schemas
└── alembic/
├── env.py # Alembic environment configuration
├── script.py.mako # Migration script template
└── versions/ # Database migration files
└── 001_initial_todo_table.py
🧪 Development
Running in Development Mode
uvicorn main:app --reload --host 0.0.0.0 --port 8000
Code Quality
This project uses Ruff for linting and formatting:
ruff check .
ruff format .
Database Operations
Create a new migration:
alembic revision --autogenerate -m "Description of changes"
Apply migrations:
alembic upgrade head
Rollback migrations:
alembic downgrade -1
🔧 Configuration
Database
- Type: SQLite
- Location:
/app/storage/db/db.sqlite
- Connection: Automatically created on startup
Environment Variables
No environment variables are required for basic operation. The application uses sensible defaults for development.
🏥 Health Check
The application includes a health check endpoint that returns the service status:
curl http://localhost:8000/health
Response:
{
"status": "healthy",
"service": "Todo API"
}
📖 API Documentation
Once the server is running, access the documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- OpenAPI JSON: http://localhost:8000/openapi.json
🚀 Deployment
For production deployment, consider:
-
Use a production WSGI server:
pip install gunicorn gunicorn main:app -w 4 -k uvicorn.workers.UvicornWorker
-
Set up proper logging and monitoring
-
Configure environment-specific settings
-
Use a more robust database (PostgreSQL, MySQL)
-
Set up SSL/TLS certificates
🤝 Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
📝 License
This project is open source and available under the MIT License.