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

  1. Clone the repository:

    git clone <repository-url>
    cd todoapp
    
  2. Install the dependencies:

    pip install -r requirements.txt
    
  3. Run the migrations to create the database:

    alembic upgrade head
    
  4. 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:

API Endpoints

  • GET /api/v1/todos: Get all todos
  • POST /api/v1/todos: Create a new todo
  • GET /api/v1/todos/{todo_id}: Get a specific todo
  • PUT /api/v1/todos/{todo_id}: Update a todo
  • DELETE /api/v1/todos/{todo_id}: Delete a todo
  • GET /api/v1/health: API health check
  • GET /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
Project: Todo App
Readme 42 KiB
Languages
Python 95.7%
Mako 4.3%