
- Add project structure with FastAPI, SQLAlchemy, and Alembic - Implement Todo model with CRUD operations - Add REST API endpoints for todo management - Configure SQLite database with migrations - Include health check and API documentation endpoints - Add CORS middleware for all origins - Format code with Ruff
91 lines
2.3 KiB
Markdown
91 lines
2.3 KiB
Markdown
# Simple Todo API
|
|
|
|
A simple todo application built with FastAPI and SQLite.
|
|
|
|
## Features
|
|
|
|
- Create, read, update, and delete todos
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Database migrations with Alembic
|
|
- FastAPI with automatic OpenAPI documentation
|
|
- CORS enabled for all origins
|
|
- Health check endpoint
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /` - Root endpoint with basic information
|
|
- `GET /health` - Health check endpoint
|
|
- `GET /docs` - Interactive API documentation (Swagger UI)
|
|
- `GET /redoc` - Alternative API documentation
|
|
- `GET /api/v1/todos` - Get all todos
|
|
- `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 specific todo
|
|
- `DELETE /api/v1/todos/{todo_id}` - Delete a specific todo
|
|
|
|
## Installation
|
|
|
|
1. Install the dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
2. Run database migrations:
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
3. Start the application:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The API will be available at `http://localhost:8000`
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
├── app/
|
|
│ ├── api/
|
|
│ │ └── v1/
|
|
│ │ ├── __init__.py
|
|
│ │ └── todos.py
|
|
│ ├── crud/
|
|
│ │ ├── __init__.py
|
|
│ │ └── todo.py
|
|
│ ├── db/
|
|
│ │ ├── __init__.py
|
|
│ │ ├── base.py
|
|
│ │ └── session.py
|
|
│ ├── models/
|
|
│ │ ├── __init__.py
|
|
│ │ └── todo.py
|
|
│ ├── schemas/
|
|
│ │ ├── __init__.py
|
|
│ │ └── todo.py
|
|
│ └── __init__.py
|
|
├── alembic/
|
|
│ ├── versions/
|
|
│ │ └── 001_initial_todo_table.py
|
|
│ ├── env.py
|
|
│ └── script.py.mako
|
|
├── alembic.ini
|
|
├── main.py
|
|
├── requirements.txt
|
|
└── README.md
|
|
```
|
|
|
|
## Database
|
|
|
|
The application uses SQLite database stored at `/app/storage/db/db.sqlite`. The database schema is managed using Alembic migrations.
|
|
|
|
## Todo Model
|
|
|
|
Each todo has the following fields:
|
|
- `id`: Unique identifier (auto-generated)
|
|
- `title`: Todo title (required, max 200 characters)
|
|
- `description`: Todo description (optional, max 500 characters)
|
|
- `completed`: Completion status (boolean, default: false)
|
|
- `created_at`: Creation timestamp
|
|
- `updated_at`: Last update timestamp
|