FastAPI Todo Application
This is a simple Todo application API built with FastAPI and SQLite. It provides endpoints for creating, reading, updating, and deleting todo items.
Features
- RESTful API for todo management
- CRUD operations for todo items
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- API documentation with Swagger UI and ReDoc
- Health check endpoint
Project Structure
todoapp/
├── alembic.ini # Alembic configuration
├── app/ # Application package
│ ├── api/ # API routes
│ │ ├── api.py # API router
│ │ └── routes/ # API route modules
│ │ ├── health.py # Health check endpoint
│ │ └── todos.py # Todo endpoints
│ ├── core/ # Core application modules
│ │ └── config.py # Application configuration
│ ├── db/ # Database modules
│ │ ├── deps.py # Database dependencies
│ │ └── session.py # Database session
│ ├── models/ # SQLAlchemy models
│ │ └── todo.py # Todo model
│ ├── schemas/ # Pydantic schemas
│ │ └── todo.py # Todo schemas
│ └── services/ # Business logic services
│ └── todo.py # Todo service
├── main.py # Application entry point
├── migrations/ # Alembic migrations
│ ├── env.py # Alembic environment
│ ├── script.py.mako # Migration script template
│ └── versions/ # Migration scripts
│ └── 001_create_todos_table.py # Initial migration
├── README.md # Project documentation
├── requirements.txt # Project dependencies
└── storage/ # Data storage directory
└── db/ # Database files
Getting Started
Prerequisites
- Python 3.8 or higher
- pip (Python package installer)
Installation
-
Clone the repository:
git clone <repository-url> cd todoapp
-
Install the dependencies:
pip install -r requirements.txt
-
Run the migrations to create the database:
alembic upgrade head
-
Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000.
API Documentation
Once the application is running, you can access the API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
GET /api/v1/todos
: Get all todosPOST /api/v1/todos
: Create a new todoGET /api/v1/todos/{todo_id}
: Get a specific todoPUT /api/v1/todos/{todo_id}
: Update a todoDELETE /api/v1/todos/{todo_id}
: Delete a todoGET /api/v1/health
: API health checkGET /health
: Alternative health check endpoint
Database
The application uses SQLite as the database. The database file is stored in storage/db/db.sqlite
.
Development
Code Style
This project uses Ruff for linting and formatting.
To lint the code:
ruff check .
To format the code:
ruff format .
Description
Languages
Python
95.7%
Mako
4.3%