SimpleTodoApp API
A FastAPI-based backend for a simple Todo application with SQLite database and user authentication.
Features
- User registration and authentication with JWT tokens
- Create, read, update, and delete Todo items (protected by authentication)
- User-specific Todo items
- Role-based access control (regular users and superusers)
- Health check endpoint
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- Comprehensive API documentation with Swagger UI and ReDoc
Project Structure
simpletodoapp/
├── api/ # API-related code
│ ├── crud/ # CRUD operations
│ │ ├── todo.py # Todo CRUD operations
│ │ └── user.py # User CRUD operations
│ ├── routers/ # API endpoints
│ │ ├── auth_router.py # Authentication endpoints
│ │ ├── health_router.py # Health check endpoint
│ │ ├── todo_router.py # Todo endpoints
│ │ └── user_router.py # User endpoints
│ ├── schemas/ # Pydantic models for request/response validation
│ │ ├── health.py # Health check schemas
│ │ ├── todo.py # Todo schemas
│ │ └── user.py # User and authentication schemas
│ └── utils/ # Utility functions
│ └── auth.py # Authentication utilities
├── db/ # Database-related code
│ ├── database.py # Database connection and session
│ └── models.py # SQLAlchemy models
├── migrations/ # Alembic migrations
├── alembic.ini # Alembic configuration
├── main.py # FastAPI application entry point
└── requirements.txt # Project dependencies
Installation & Setup
- Clone this repository
- Install dependencies:
pip install -r requirements.txt
- Apply database migrations:
alembic upgrade head
- Run the application:
uvicorn main:app --reload
Authentication
The API uses JWT (JSON Web Tokens) for authentication. To use protected endpoints:
- Register a new user using
POST /api/users
- Get an access token using
POST /api/auth/token
with your username and password - Include the token in the
Authorization
header of your requests:Authorization: Bearer <your_token>
Access tokens expire after 30 minutes by default.
API Documentation
Once the server is running, you can access:
- Swagger UI documentation at
/docs
- ReDoc documentation at
/redoc
API Endpoints
Authentication
POST /api/auth/token
- Get access token (login)POST /api/users
- Register a new user
Users
GET /api/users/me
- Get current user informationPUT /api/users/me
- Update current user informationGET /api/users/{id}
- Get user information by ID (current user or superuser only)GET /api/users
- List all users (superuser only)DELETE /api/users/{id}
- Delete a user (superuser only)
Todos
All todo endpoints require authentication.
GET /api/todos
- List all todos for current userGET /api/todos/{id}
- Get a single todo by ID (owned by current user)POST /api/todos
- Create a new todo (owned by current user)PATCH /api/todos/{id}
- Update a todo (owned by current user)DELETE /api/todos/{id}
- Delete a todo (owned by current user)
Health
GET /api/health
- Health check endpoint
Description
Languages
Python
98.4%
Mako
1.6%