Simple TODO Application

A simple TODO application built with FastAPI and SQLite.

Features

  • Create, read, update, and delete TODO items
  • Filter TODO items by completion status
  • Health check endpoint

Tech Stack

  • FastAPI: Web framework for building APIs
  • SQLAlchemy: ORM for database interactions
  • Pydantic: Data validation and settings management
  • Alembic: Database migration tool
  • SQLite: Lightweight relational database
  • Uvicorn: ASGI server for running the application

Project Structure

.
├── alembic.ini                   # Alembic configuration
├── main.py                       # FastAPI application entry point
├── migrations/                   # Database migrations
│   ├── env.py
│   ├── script.py.mako
│   └── versions/
│       └── 001_create_todos_table.py
├── app/
│   ├── api/                      # API endpoints
│   │   └── routes/
│   │       ├── health.py         # Health check endpoint
│   │       └── todos.py          # Todo endpoints
│   ├── core/                     # Core application code
│   │   └── config.py             # Application configuration
│   ├── db/                       # Database setup
│   │   ├── base.py
│   │   ├── deps.py               # Database dependencies
│   │   └── session.py            # Database session setup
│   ├── models/                   # SQLAlchemy models
│   │   └── todo.py               # Todo model
│   └── schemas/                  # Pydantic schemas
│       └── todo.py               # Todo schemas
└── requirements.txt              # Project dependencies

Running the Application

  1. Install dependencies:
pip install -r requirements.txt
  1. Run database migrations:
alembic upgrade head
  1. Start the application:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
  1. Visit the API documentation:

API Endpoints

Health Check

  • GET /health - Check API and database status

Todo Operations

  • GET /api/todos - List all todos (can filter by completion status)
  • POST /api/todos - Create a new todo
  • GET /api/todos/{todo_id} - Get a specific todo
  • PUT /api/todos/{todo_id} - Update a todo
  • DELETE /api/todos/{todo_id} - Delete a todo

Example Usage

Create a Todo

curl -X POST http://localhost:8000/api/todos \
  -H "Content-Type: application/json" \
  -d '{"title": "Learn FastAPI", "description": "Complete FastAPI tutorial", "completed": false}'

Get All Todos

curl http://localhost:8000/api/todos

Get Completed Todos

curl http://localhost:8000/api/todos?completed=true

Update a Todo

curl -X PUT http://localhost:8000/api/todos/1 \
  -H "Content-Type: application/json" \
  -d '{"completed": true}'

Delete a Todo

curl -X DELETE http://localhost:8000/api/todos/1
Description
Project: Simple Todo Application
Readme 37 KiB
Languages
Python 95.4%
Mako 4.6%