
- 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
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
- Clone the repository:
git clone https://github.com/yourusername/simpletodoapp.git
cd simpletodoapp
- Install the dependencies:
pip install -r requirements.txt
- Apply the database migrations:
alembic upgrade head
- 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
Authentication
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Login and get access tokenGET /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 userGET /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 .
Description
Languages
Python
98%
Mako
2%