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

  1. Clone the repository

  2. Install dependencies:

    pip install -r requirements.txt
    
  3. 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.

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 user
  • POST /api/v1/auth/login - Login and get access token
  • POST /api/v1/auth/refresh - Refresh access token using refresh token
  • POST /api/v1/auth/logout - Logout and revoke refresh token

Users

  • GET /api/v1/users/ - List all users
  • GET /api/v1/users/me - Get current user details
  • PUT /api/v1/users/me - Update current user
  • GET /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 todo
  • GET /api/v1/todos/{id} - Get todo by ID
  • PUT /api/v1/todos/{id} - Update a todo
  • DELETE /api/v1/todos/{id} - Delete a todo

Categories

  • GET /api/v1/categories/ - List all categories
  • POST /api/v1/categories/ - Create a new category
  • GET /api/v1/categories/{id} - Get category by ID
  • PUT /api/v1/categories/{id} - Update a category
  • DELETE /api/v1/categories/{id} - Delete a category

Tags

  • GET /api/v1/tags/ - List all tags
  • POST /api/v1/tags/ - Create a new tag
  • GET /api/v1/tags/{id} - Get tag by ID
  • PUT /api/v1/tags/{id} - Update a tag
  • DELETE /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 date
  • due_date_after: Filter for todos due after this date
  • category_id: Filter by category ID
  • tag_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 package
    • api/: API routes and dependencies
    • core/: Core functionality (config, security)
    • crud/: CRUD operations
    • db/: Database setup and session management
    • models/: SQLAlchemy models
    • schemas/: Pydantic schemas
    • storage/: Storage for database and other files
  • migrations/: Alembic migrations
  • main.py: Application entry point

Adding New Models

  1. Create a new model in app/models/
  2. Import the model in app/db/base_class.py
  3. Create corresponding Pydantic schemas in app/schemas/
  4. Create CRUD operations in app/crud/
  5. Create API endpoints in app/api/v1/endpoints/
  6. Generate a new migration:
    alembic revision -m "description"
    
  7. Edit the migration file manually
  8. Apply the migration:
    alembic upgrade head
    

License

MIT License

Description
Project: Todo App Backend
Readme 86 KiB
Languages
Python 99.1%
Mako 0.9%