
- Set up project structure with proper directory layout - Implemented SQLite database with SQLAlchemy ORM - Created Todo model with CRUD operations - Added Alembic for database migrations - Implemented RESTful API endpoints for todos - Added health check endpoint - Configured CORS for all origins - Created comprehensive documentation - Added linting with Ruff
Todo API
A simple Todo application API built with FastAPI and SQLite.
Features
- Create, read, update, and delete todos
- RESTful API endpoints
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- Health check endpoint
- CORS enabled for all origins
- Interactive API documentation
Requirements
- Python 3.7+
- FastAPI
- SQLAlchemy
- Alembic
- Uvicorn
Installation
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Endpoints
Base
GET /
- API information and links to documentation
Health Check
GET /health
- Health check endpoint
Todos
GET /api/v1/todos
- Get all todos (with pagination)POST /api/v1/todos
- Create a new todoGET /api/v1/todos/{id}
- Get a specific todoPUT /api/v1/todos/{id}
- Update a todoDELETE /api/v1/todos/{id}
- Delete a todo
Documentation
- Interactive API docs:
http://localhost:8000/docs
- ReDoc documentation:
http://localhost:8000/redoc
- OpenAPI JSON:
http://localhost:8000/openapi.json
Project Structure
.
├── main.py # FastAPI application entry point
├── requirements.txt # Python dependencies
├── alembic.ini # Alembic configuration
├── alembic/ # Database migrations
│ ├── env.py
│ ├── script.py.mako
│ └── versions/
│ └── 0001_create_todos_table.py
└── app/
├── __init__.py
├── db/
│ ├── __init__.py
│ ├── base.py # SQLAlchemy declarative base
│ └── session.py # Database session configuration
├── models/
│ ├── __init__.py
│ └── todo.py # Todo model
└── routes/
├── __init__.py
├── todos.py # Todo CRUD endpoints
└── health.py # Health check endpoint
Database
The application uses SQLite database stored at /app/storage/db/db.sqlite
. The database is automatically created when the application starts.
Description
Languages
Python
94.3%
Mako
5.7%