# 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: ```bash git clone cd simple-todo-application ``` 2. Install dependencies: ```bash pip install -r requirements.txt ``` 3. Run the application: ```bash uvicorn main:app --host 0.0.0.0 --port 8000 --reload ``` 4. Access the API documentation: - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc ## Database Migrations The application uses Alembic for database migrations: ```bash # 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"] ```