
TaskMaster Pro - FastAPI Backend
A powerful, secure RESTful API for managing tasks and todos, built with FastAPI and SQLite.
Features
- 🔐 Enhanced JWT Authentication
- Access and Refresh tokens
- Token revocation (logout)
- Role-based access control (User/Admin roles)
- 📝 Todo CRUD operations
- Priority levels (High, Medium, Low)
- Due dates for better task management
- Categories for task organization
- Tags for flexible grouping and filtering
- Smart ordering by priority and due date
- 👤 User management
- 🔍 Advanced todo filtering and pagination
- 📄 API documentation (via Swagger UI and ReDoc)
- 🔄 Database migrations (Alembic)
Requirements
- Python 3.8+
- FastAPI
- SQLAlchemy
- Alembic
- Pydantic
- SQLite
Installation
-
Clone the repository
-
Install dependencies:
pip install -r requirements.txt
-
Run database migrations:
alembic upgrade head
Running the Application
Start the server with:
uvicorn main:app --reload
The API will be available at http://localhost:8000.
- API Documentation: http://localhost:8000/docs
- Alternative Documentation: http://localhost:8000/redoc
- OpenAPI Schema: http://localhost:8000/openapi.json
- Health Check: http://localhost:8000/health
Environment Variables
The application can be configured using the following environment variables:
Variable | Description | Default |
---|---|---|
SECRET_KEY | Secret key for JWT encoding | Auto-generated |
ACCESS_TOKEN_EXPIRE_MINUTES | JWT token expiration time (minutes) | 11520 (8 days) |
API Endpoints
Authentication
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Login and get access tokenPOST /api/v1/auth/refresh
- Refresh access token using refresh tokenPOST /api/v1/auth/logout
- Logout and revoke refresh token
Users
GET /api/v1/users/
- List all usersGET /api/v1/users/me
- Get current user detailsPUT /api/v1/users/me
- Update current userGET /api/v1/users/{user_id}
- Get user by ID
Admin
GET /api/v1/admin/users
- List all users (admin only)GET /api/v1/admin/users/{user_id}
- Get user by ID (admin only)PUT /api/v1/admin/users/{user_id}
- Update user (admin only)
Todos
GET /api/v1/todos/
- List todos (with filtering and pagination)POST /api/v1/todos/
- Create a new todoGET /api/v1/todos/{id}
- Get todo by IDPUT /api/v1/todos/{id}
- Update a todoDELETE /api/v1/todos/{id}
- Delete a todo
Categories
GET /api/v1/categories/
- List all categoriesPOST /api/v1/categories/
- Create a new categoryGET /api/v1/categories/{id}
- Get category by IDPUT /api/v1/categories/{id}
- Update a categoryDELETE /api/v1/categories/{id}
- Delete a category
Tags
GET /api/v1/tags/
- List all tagsPOST /api/v1/tags/
- Create a new tagGET /api/v1/tags/{id}
- Get tag by IDPUT /api/v1/tags/{id}
- Update a tagDELETE /api/v1/tags/{id}
- Delete a tag
Todo Filtering
The GET /api/v1/todos/
endpoint supports the following query parameters:
skip
: Number of records to skip (default: 0)limit
: Maximum number of records to return (default: 100)title
: Filter by title (contains search)is_completed
: Filter by completion status (true/false)priority
: Filter by priority level (low, medium, high)due_date_before
: Filter for todos due before this datedue_date_after
: Filter for todos due after this datecategory_id
: Filter by category IDtag_id
: Filter by tag ID
Database Schema
User Model
id: Integer (Primary Key)
email: String (Unique, Indexed)
hashed_password: String
is_active: Boolean (Default: True)
role: Enum(admin, user) (Default: user)
Todo Model
id: Integer (Primary Key)
title: String (Indexed)
description: Text (Optional)
is_completed: Boolean (Default: False)
priority: Enum(low, medium, high) (Default: medium)
due_date: DateTime (Optional)
category_id: Integer (Foreign Key to Category, Optional)
owner_id: Integer (Foreign Key to User)
Category Model
id: Integer (Primary Key)
name: String (Unique, Indexed)
description: String (Optional)
owner_id: Integer (Foreign Key to User)
Tag Model
id: Integer (Primary Key)
name: String (Unique, Indexed)
owner_id: Integer (Foreign Key to User)
TodoTag Association Table
todo_id: Integer (Foreign Key to Todo, Primary Key)
tag_id: Integer (Foreign Key to Tag, Primary Key)
RefreshToken Model
id: Integer (Primary Key)
token: String (Unique, Indexed)
expires_at: DateTime
created_at: DateTime
revoked: Boolean (Default: False)
user_id: Integer (Foreign Key to User)
Development
Code Structure
app/
: Main application packageapi/
: API routes and dependenciescore/
: Core functionality (config, security)crud/
: CRUD operationsdb/
: Database setup and session managementmodels/
: SQLAlchemy modelsschemas/
: Pydantic schemasstorage/
: Storage for database and other files
migrations/
: Alembic migrationsmain.py
: Application entry point
Adding New Models
- Create a new model in
app/models/
- Import the model in
app/db/base_class.py
- Create corresponding Pydantic schemas in
app/schemas/
- Create CRUD operations in
app/crud/
- Create API endpoints in
app/api/v1/endpoints/
- Generate a new migration:
alembic revision -m "description"
- Edit the migration file manually
- Apply the migration:
alembic upgrade head
License
MIT License
Description
Languages
Python
99.1%
Mako
0.9%