
- 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
2.9 KiB
2.9 KiB
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
- Clone the repository:
git clone https://github.com/yourusername/simpletodoapp.git
cd simpletodoapp
- Install the dependencies:
pip install -r requirements.txt
- Run the application:
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 todoGET /api/v1/todos/{todo_id}
- Retrieve a specific todoPUT /api/v1/todos/{todo_id}
- Update a specific todoDELETE /api/v1/todos/{todo_id}
- Delete a specific todo
Database Migrations
Migrations are managed by Alembic:
# Apply all migrations
alembic upgrade head
# Generate a new migration (after modifying models)
alembic revision --autogenerate -m "description"
Development
Running Tests
pytest
Linting
ruff check .
ruff format .