FastAPI Todo App

A simple Todo API built with FastAPI and SQLite.

Features

  • Create, read, update, and delete Todo items
  • RESTful API endpoints
  • SQLite database with SQLAlchemy ORM
  • Alembic migrations
  • API documentation with Swagger UI and ReDoc

Project Structure

simpletodoapp/
├── alembic/                    # Database migrations
│   ├── versions/               # Migration scripts
│   ├── env.py                  # Migration environment
│   └── script.py.mako          # Migration script template
├── app/                        # Application package
│   ├── api/                    # API endpoints
│   │   └── routers/            # API routers
│   │       ├── health.py       # Health check endpoints
│   │       └── todos.py        # Todo endpoints
│   ├── core/                   # Core functionality
│   │   └── database.py         # Database configuration
│   ├── models/                 # SQLAlchemy models
│   │   └── todo.py             # Todo model
│   ├── schemas/                # Pydantic schemas
│   │   └── todo.py             # Todo schemas
│   └── services/               # Business logic
│       └── todo.py             # Todo services
├── storage/                    # Data storage directory
│   └── db/                     # Database files
├── alembic.ini                 # Alembic configuration
├── main.py                     # Application entry point
├── pyproject.toml              # Project configuration (Ruff)
└── requirements.txt            # Python dependencies

Getting Started

Prerequisites

  • Python 3.8 or higher

Installation

  1. Clone the repository
  2. Install dependencies:
pip install -r requirements.txt
  1. Run the application:
uvicorn main:app --reload

The API will be available at http://localhost:8000

API Documentation

API Endpoints

Health Check

  • GET /health - Check API health

Todo Operations

  • GET /api/todos - List all todos
  • GET /api/todos/{todo_id} - Get a single todo
  • POST /api/todos - Create a new todo
  • PUT /api/todos/{todo_id} - Update a todo
  • DELETE /api/todos/{todo_id} - Delete a todo

Database Migrations

The application uses Alembic for database migrations. The initial migration is included to create the todos table.

To apply migrations:

alembic upgrade head

Development

Linting

The project uses Ruff for linting:

ruff check .

To automatically fix linting issues:

ruff check --fix .
Description
Project: Simple Todo App
Readme 47 KiB
Languages
Python 97.6%
Mako 2.4%