Automated Action 8fefbb7c13 Add user authentication to the Todo app
- Created User model and schemas
- Implemented secure password hashing with bcrypt
- Added JWT token-based authentication
- Created user registration and login endpoints
- Added authentication to todo routes
- Updated todos to be associated with users
- Created migration script for the user table
- Updated documentation with auth information
2025-05-19 13:45:22 +00:00
2025-05-19 13:30:42 +00:00

Simple Todo App with FastAPI and SQLite

A simple Todo API application built with FastAPI and SQLite that provides CRUD operations for todo items with user authentication.

Features

  • Create, read, update, and delete todo items
  • User authentication with JWT tokens
  • User registration and login
  • Secure password hashing with bcrypt
  • 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
│   │   ├── deps.py             # Dependency injection and auth
│   │   └── routes/             # Route modules 
│   │       ├── auth.py         # Authentication endpoints
│   │       ├── health.py       # Health check endpoint
│   │       └── todos.py        # Todo endpoints
│   ├── core/                   # Core modules
│   │   ├── config.py           # App configuration
│   │   └── security.py         # Security utilities
│   ├── crud/                   # CRUD operations
│   │   ├── todo.py             # Todo CRUD operations
│   │   └── user.py             # User CRUD operations
│   ├── db/                     # Database setup
│   │   └── session.py          # DB session and engine
│   ├── models/                 # SQLAlchemy models
│   │   ├── todo.py             # Todo model
│   │   └── user.py             # User model
│   └── schemas/                # Pydantic schemas
│       ├── todo.py             # Todo schemas
│       ├── user.py             # User schemas
│       └── token.py            # Token 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:
git clone https://github.com/yourusername/simpletodoapp.git
cd simpletodoapp
  1. Install the dependencies:
pip install -r requirements.txt
  1. Apply the database migrations:
alembic upgrade head
  1. 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:

API Endpoints

Health Check

  • GET /health - Check the health of the application and database connection

Authentication

  • POST /api/v1/auth/register - Register a new user
  • POST /api/v1/auth/login - Login and get access token
  • GET /api/v1/auth/me - Get current user information

Todo Operations (Requires Authentication)

  • GET /api/v1/todos - Retrieve all todos for current user (with pagination)
  • POST /api/v1/todos - Create a new todo for current user
  • 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:

# 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 .
Description
Project: Simple Todo App
Readme 52 KiB
Languages
Python 98%
Mako 2%