# Todo App API A simple Todo application API built with FastAPI and SQLite. ## Features - ✅ Create, read, update, and delete todos - ✅ RESTful API design - ✅ SQLite database with SQLAlchemy ORM - ✅ Database migrations with Alembic - ✅ API documentation with Swagger UI - ✅ CORS support for frontend integration - ✅ Health check endpoint - ✅ Pydantic schemas for data validation ## API Endpoints ### Base Endpoints - `GET /` - API information and links - `GET /health` - Health check endpoint ### Todo Endpoints - `GET /api/v1/todos/` - List all todos (with pagination) - `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 ## Installation 1. Install dependencies: ```bash pip install -r requirements.txt ``` ## Running the Application 1. Start the development server: ```bash uvicorn main:app --reload ``` 2. Access the API documentation: - Swagger UI: http://localhost:8000/docs - ReDoc: http://localhost:8000/redoc - OpenAPI JSON: http://localhost:8000/openapi.json 3. Health check: - http://localhost:8000/health ## Database The application uses SQLite database stored at `/app/storage/db/db.sqlite`. ### Database Migrations Database migrations are managed with Alembic: ```bash # Create a new migration alembic revision --autogenerate -m "Description of changes" # Apply migrations alembic upgrade head # Downgrade migrations alembic downgrade -1 ``` ## Project Structure ``` ├── README.md ├── requirements.txt ├── main.py # FastAPI application entry point ├── alembic.ini # Alembic configuration ├── alembic/ # Database migrations │ ├── versions/ │ ├── env.py │ └── script.py.mako └── app/ ├── api/ │ └── todos.py # Todo API endpoints ├── db/ │ ├── base.py # SQLAlchemy base │ └── session.py # Database session ├── models/ │ └── todo.py # Todo database model └── schemas/ └── todo.py # Pydantic schemas ``` ## Todo Model Each todo has the following fields: - `id` (int): Unique identifier - `title` (str): Todo title (required) - `description` (str): Optional description - `completed` (bool): Completion status (default: false) - `created_at` (datetime): Creation timestamp - `updated_at` (datetime): Last update timestamp ## Development ### Code Quality The project uses Ruff for linting and code formatting: ```bash # Run linting ruff check . # Auto-fix issues ruff check . --fix ``` ### API Usage Examples #### Create a Todo ```bash curl -X POST "http://localhost:8000/api/v1/todos/" \ -H "Content-Type: application/json" \ -d '{"title": "Buy groceries", "description": "Milk, bread, eggs"}' ``` #### List Todos ```bash curl "http://localhost:8000/api/v1/todos/" ``` #### Update a Todo ```bash curl -X PUT "http://localhost:8000/api/v1/todos/1" \ -H "Content-Type: application/json" \ -d '{"completed": true}' ``` #### Delete a Todo ```bash curl -X DELETE "http://localhost:8000/api/v1/todos/1" ``` ## License This project is open source and available under the MIT License.