Automated Action 7a8eb3a5b2 Create complete FastAPI Todo application
- Set up FastAPI application with CORS support
- Created SQLite database configuration with absolute paths
- Implemented Todo model with SQLAlchemy
- Added full CRUD operations for todos
- Created API endpoints with proper error handling
- Set up Alembic for database migrations
- Added health check and base URL endpoints
- Updated README with comprehensive documentation
- Configured project structure following best practices

Features:
- Complete Todo CRUD API
- SQLite database with proper path configuration
- Database migrations with Alembic
- API documentation at /docs and /redoc
- Health check endpoint at /health
- CORS enabled for all origins
- Proper error handling and validation
2025-06-23 13:46:11 +00:00
2025-06-23 13:41:26 +00:00

Todo API

A simple Todo API built with FastAPI and SQLite. This application provides a RESTful API for managing todo items with full CRUD operations.

Features

  • Create, read, update, and delete todo items
  • SQLite database with SQLAlchemy ORM
  • Database migrations with Alembic
  • Automatic API documentation with FastAPI
  • CORS support for cross-origin requests
  • Health check endpoint
  • Proper error handling and validation

Project Structure

todoapp-h5yaal/
├── main.py                    # FastAPI application entry point
├── requirements.txt           # Python dependencies
├── alembic.ini               # Alembic configuration
├── alembic/                  # Database migrations
│   ├── env.py
│   └── versions/
│       └── 001_initial_migration.py
└── app/
    ├── __init__.py
    ├── api/
    │   ├── __init__.py
    │   └── todos.py          # Todo API endpoints
    ├── db/
    │   ├── __init__.py
    │   ├── base.py           # SQLAlchemy Base
    │   ├── session.py        # Database session configuration
    │   └── crud.py           # Database operations
    └── models/
        ├── __init__.py
        ├── todo.py           # Todo SQLAlchemy model
        └── schemas.py        # Pydantic schemas

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. Run database migrations:
alembic upgrade head

Running the Application

Start the development server:

uvicorn main:app --reload --host 0.0.0.0 --port 8000

The application will be available at:

API Endpoints

Base Endpoints

  • GET / - API information and links
  • GET /health - Health check endpoint

Todo Endpoints

  • GET /api/v1/todos - Get all todos (with pagination)
  • GET /api/v1/todos/{todo_id} - Get a specific todo
  • POST /api/v1/todos - Create a new todo
  • PUT /api/v1/todos/{todo_id} - Update a todo
  • DELETE /api/v1/todos/{todo_id} - Delete a todo

Example API Usage

Create a todo:

curl -X POST "http://localhost:8000/api/v1/todos" \
  -H "Content-Type: application/json" \
  -d '{"title": "Buy groceries", "description": "Milk, bread, eggs", "completed": false}'

Get all todos:

curl "http://localhost:8000/api/v1/todos"

Update a todo:

curl -X PUT "http://localhost:8000/api/v1/todos/1" \
  -H "Content-Type: application/json" \
  -d '{"completed": true}'

Database

The application uses SQLite database stored at /app/storage/db/db.sqlite. The database schema is managed through Alembic migrations.

Database Schema

Todos Table:

  • id (Integer, Primary Key)
  • title (String, Required)
  • description (Text, Optional)
  • completed (Boolean, Default: False)
  • created_at (DateTime)
  • updated_at (DateTime)

Development

Running Migrations

Create a new migration:

alembic revision --autogenerate -m "Description of changes"

Apply migrations:

alembic upgrade head

Code Quality

The project uses Ruff for linting and code formatting:

ruff check . --fix

Environment Variables

This application doesn't currently require any environment variables, but you can extend it by adding configuration for:

  • Database URL
  • CORS origins
  • Logging level
  • API keys (if authentication is added)

License

This project is generated by BackendIM.

Description
Project: Todo App
Readme 40 KiB
Languages
Python 95.1%
Mako 4.9%