
- Set up project structure and FastAPI application - Create Todo database model with SQLAlchemy - Configure Alembic for database migrations - Implement CRUD endpoints for managing Todo items - Add health check endpoint - Include comprehensive documentation in README.md - Configure and apply Ruff linting
107 lines
2.9 KiB
Markdown
107 lines
2.9 KiB
Markdown
# Simple Todo App with FastAPI and SQLite
|
|
|
|
A simple Todo API application built with FastAPI and SQLite that provides CRUD operations for todo items.
|
|
|
|
## Features
|
|
|
|
- Create, read, update, and delete todo items
|
|
- RESTful API with FastAPI
|
|
- SQLite database with SQLAlchemy ORM
|
|
- Database migrations with Alembic
|
|
- Automatic API documentation with Swagger UI and ReDoc
|
|
- Health check endpoint
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
simpletodoapp/
|
|
├── alembic.ini # Alembic configuration
|
|
├── migrations/ # Database migration scripts
|
|
├── app/ # Application package
|
|
│ ├── api/ # API routes
|
|
│ │ └── routes/ # Route modules
|
|
│ │ ├── health.py # Health check endpoint
|
|
│ │ └── todos.py # Todo endpoints
|
|
│ ├── core/ # Core modules
|
|
│ │ └── config.py # App configuration
|
|
│ ├── crud/ # CRUD operations
|
|
│ │ └── todo.py # Todo CRUD operations
|
|
│ ├── db/ # Database setup
|
|
│ │ └── session.py # DB session and engine
|
|
│ ├── models/ # SQLAlchemy models
|
|
│ │ └── todo.py # Todo model
|
|
│ └── schemas/ # Pydantic schemas
|
|
│ └── todo.py # Todo schemas
|
|
├── main.py # FastAPI application creation
|
|
└── requirements.txt # Python dependencies
|
|
```
|
|
|
|
## Getting Started
|
|
|
|
### Prerequisites
|
|
|
|
- Python 3.8 or higher
|
|
- pip (Python package installer)
|
|
|
|
### Installation
|
|
|
|
1. Clone the repository:
|
|
```bash
|
|
git clone https://github.com/yourusername/simpletodoapp.git
|
|
cd simpletodoapp
|
|
```
|
|
|
|
2. Install the dependencies:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
3. Run the application:
|
|
```bash
|
|
uvicorn main:app --reload
|
|
```
|
|
|
|
The application will be available at http://localhost:8000.
|
|
|
|
### API Documentation
|
|
|
|
After starting the application, you can access the API documentation at:
|
|
- Swagger UI: http://localhost:8000/docs
|
|
- ReDoc: http://localhost:8000/redoc
|
|
|
|
## API Endpoints
|
|
|
|
### Health Check
|
|
- `GET /health` - Check the health of the application and database connection
|
|
|
|
### Todo Operations
|
|
- `GET /api/v1/todos` - Retrieve all todos (with pagination)
|
|
- `POST /api/v1/todos` - Create a new todo
|
|
- `GET /api/v1/todos/{todo_id}` - Retrieve a specific todo
|
|
- `PUT /api/v1/todos/{todo_id}` - Update a specific todo
|
|
- `DELETE /api/v1/todos/{todo_id}` - Delete a specific todo
|
|
|
|
## Database Migrations
|
|
|
|
Migrations are managed by Alembic:
|
|
|
|
```bash
|
|
# Apply all migrations
|
|
alembic upgrade head
|
|
|
|
# Generate a new migration (after modifying models)
|
|
alembic revision --autogenerate -m "description"
|
|
```
|
|
|
|
## Development
|
|
|
|
### Running Tests
|
|
```bash
|
|
pytest
|
|
```
|
|
|
|
### Linting
|
|
```bash
|
|
ruff check .
|
|
ruff format .
|
|
``` |