Automated Action 9505ec13a1 Implement simple todo application with FastAPI and SQLite
- Set up project structure and FastAPI app
- Create database models and SQLAlchemy connection
- Implement Alembic migration scripts
- Add CRUD API endpoints for Todo items
- Add health check endpoint
- Set up validation, error handling, and middleware
- Add comprehensive documentation in README.md
2025-05-18 12:42:38 +00:00
2025-05-18 12:36:26 +00:00

Simple Todo Application

Overview

This is a simple todo application API built with FastAPI and SQLite. It provides a RESTful API for managing todo items with the following features:

  • Create, read, update, and delete todo items
  • Filter todos by completion status
  • Health check endpoint
  • Validation and error handling
  • CORS support
  • Request logging

Technologies Used

  • FastAPI: A modern, fast (high-performance) web framework for building APIs with Python
  • SQLAlchemy: SQL toolkit and Object-Relational Mapping (ORM) for Python
  • Pydantic: Data validation and settings management using Python type hints
  • SQLite: Lightweight disk-based database
  • Alembic: Database migration tool for SQLAlchemy
  • Uvicorn: ASGI server for running the FastAPI application

Project Structure

.
├── app
│   ├── api
│   │   ├── endpoints
│   │   │   └── todos.py        # Todo API endpoints
│   │   ├── health.py           # Health check endpoint
│   │   └── routes.py           # API router setup
│   ├── core
│   │   ├── config.py           # Application configuration
│   │   ├── error_handlers.py   # Global error handlers
│   │   └── exceptions.py       # Custom exceptions
│   ├── db
│   │   ├── crud
│   │   │   ├── base.py         # Base CRUD operations
│   │   │   └── crud_todo.py    # Todo-specific CRUD operations
│   │   └── session.py          # Database session setup
│   ├── middleware
│   │   └── logging.py          # Request logging middleware
│   ├── models
│   │   ├── base.py             # Base SQLAlchemy model
│   │   └── todo.py             # Todo model definition
│   └── schemas
│       └── todo.py             # Pydantic schemas for Todo model
├── migrations
│   ├── env.py                  # Alembic environment configuration
│   ├── script.py.mako          # Alembic script template
│   └── versions
│       └── 20240101_initial_todo_table.py  # Initial database migration
├── alembic.ini                 # Alembic configuration
├── main.py                     # Application entry point
└── requirements.txt            # Project dependencies

API Endpoints

Health Check

  • GET /health: Check the health of the application

Todo Endpoints

  • GET /todos: List all todo items

    • Query parameters:
      • skip: Number of items to skip (default: 0)
      • limit: Maximum number of items to return (default: 100)
      • completed: Filter by completion status (optional)
  • POST /todos: Create a new todo item

    • Request body:
      • title: Required string (1-100 characters)
      • description: Optional string (0-500 characters)
      • completed: Boolean (default: false)
  • GET /todos/{todo_id}: Get a specific todo item by ID

  • PUT /todos/{todo_id}: Update a todo item

    • Request body:
      • title: Optional string (1-100 characters)
      • description: Optional string (0-500 characters)
      • completed: Optional boolean
  • DELETE /todos/{todo_id}: Delete a todo item

Setup and Installation

  1. Clone the repository:
git clone <repository-url>
cd simple-todo-application
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the application:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
  1. Access the API documentation:

Database Migrations

The application uses Alembic for database migrations:

# Apply all migrations
alembic upgrade head

# Revert last migration
alembic downgrade -1

Configuration

The application can be configured using environment variables. Create a .env file in the project root with the following variables:

PROJECT_NAME=My Todo App
CORS_ORIGINS=["http://localhost:3000","https://example.com"]
Description
Project: Simple Todo Application
Readme 42 KiB
Languages
Python 97.3%
Mako 2.7%