Todo API

A simple Todo API built with FastAPI and SQLite. This application provides a RESTful API for managing todo items with full CRUD operations.

Features

  • Create, read, update, and delete todo items
  • SQLite database with SQLAlchemy ORM
  • Database migrations with Alembic
  • Automatic API documentation with FastAPI
  • CORS support for cross-origin requests
  • Health check endpoint
  • Proper error handling and validation

Project Structure

todoapp-h5yaal/
├── main.py                    # FastAPI application entry point
├── requirements.txt           # Python dependencies
├── alembic.ini               # Alembic configuration
├── alembic/                  # Database migrations
│   ├── env.py
│   └── versions/
│       └── 001_initial_migration.py
└── app/
    ├── __init__.py
    ├── api/
    │   ├── __init__.py
    │   └── todos.py          # Todo API endpoints
    ├── db/
    │   ├── __init__.py
    │   ├── base.py           # SQLAlchemy Base
    │   ├── session.py        # Database session configuration
    │   └── crud.py           # Database operations
    └── models/
        ├── __init__.py
        ├── todo.py           # Todo SQLAlchemy model
        └── schemas.py        # Pydantic schemas

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. Run database migrations:
alembic upgrade head

Running the Application

Start the development server:

uvicorn main:app --reload --host 0.0.0.0 --port 8000

The application will be available at:

API Endpoints

Base Endpoints

  • GET / - API information and links
  • GET /health - Health check endpoint

Todo Endpoints

  • GET /api/v1/todos - Get all todos (with pagination)
  • GET /api/v1/todos/{todo_id} - Get a specific todo
  • POST /api/v1/todos - Create a new todo
  • PUT /api/v1/todos/{todo_id} - Update a todo
  • DELETE /api/v1/todos/{todo_id} - Delete a todo

Example API Usage

Create a todo:

curl -X POST "http://localhost:8000/api/v1/todos" \
  -H "Content-Type: application/json" \
  -d '{"title": "Buy groceries", "description": "Milk, bread, eggs", "completed": false}'

Get all todos:

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

Update a todo:

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

Database

The application uses SQLite database stored at /app/storage/db/db.sqlite. The database schema is managed through Alembic migrations.

Database Schema

Todos Table:

  • id (Integer, Primary Key)
  • title (String, Required)
  • description (Text, Optional)
  • completed (Boolean, Default: False)
  • created_at (DateTime)
  • updated_at (DateTime)

Development

Running Migrations

Create a new migration:

alembic revision --autogenerate -m "Description of changes"

Apply migrations:

alembic upgrade head

Code Quality

The project uses Ruff for linting and code formatting:

ruff check . --fix

Environment Variables

This application doesn't currently require any environment variables, but you can extend it by adding configuration for:

  • Database URL
  • CORS origins
  • Logging level
  • API keys (if authentication is added)

License

This project is generated by BackendIM.

Description
Project: Todo App
Readme 40 KiB
Languages
Python 95.1%
Mako 4.9%