108 lines
2.7 KiB
Markdown

# FastAPI Todo App
A simple Todo API built with FastAPI and SQLite.
## Features
- Create, read, update, and delete Todo items
- RESTful API endpoints
- SQLite database with SQLAlchemy ORM
- Alembic migrations
- API documentation with Swagger UI and ReDoc
## Project Structure
```
simpletodoapp/
├── alembic/ # Database migrations
│ ├── versions/ # Migration scripts
│ ├── env.py # Migration environment
│ └── script.py.mako # Migration script template
├── app/ # Application package
│ ├── api/ # API endpoints
│ │ └── routers/ # API routers
│ │ ├── health.py # Health check endpoints
│ │ └── todos.py # Todo endpoints
│ ├── core/ # Core functionality
│ │ └── database.py # Database configuration
│ ├── models/ # SQLAlchemy models
│ │ └── todo.py # Todo model
│ ├── schemas/ # Pydantic schemas
│ │ └── todo.py # Todo schemas
│ └── services/ # Business logic
│ └── todo.py # Todo services
├── storage/ # Data storage directory
│ └── db/ # Database files
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
├── pyproject.toml # Project configuration (Ruff)
└── requirements.txt # Python dependencies
```
## Getting Started
### Prerequisites
- Python 3.8 or higher
### Installation
1. Clone the repository
2. Install dependencies:
```bash
pip install -r requirements.txt
```
3. Run the application:
```bash
uvicorn main:app --reload
```
The API will be available at http://localhost:8000
### API Documentation
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## API Endpoints
### Health Check
- `GET /health` - Check API health
### Todo Operations
- `GET /api/todos` - List all todos
- `GET /api/todos/{todo_id}` - Get a single todo
- `POST /api/todos` - Create a new todo
- `PUT /api/todos/{todo_id}` - Update a todo
- `DELETE /api/todos/{todo_id}` - Delete a todo
## Database Migrations
The application uses Alembic for database migrations. The initial migration is included to create the `todos` table.
To apply migrations:
```bash
alembic upgrade head
```
## Development
### Linting
The project uses Ruff for linting:
```bash
ruff check .
```
To automatically fix linting issues:
```bash
ruff check --fix .
```