Automated Action c9baaa994e Create comprehensive Task Manager API with FastAPI
- Add user authentication with JWT tokens
- Implement task CRUD operations with status and priority
- Set up SQLite database with SQLAlchemy ORM
- Create Alembic migrations for database schema
- Add comprehensive API documentation
- Include health check endpoint and CORS configuration
- Structure codebase with proper separation of concerns
2025-06-20 19:35:55 +00:00

4.5 KiB

Task Manager API

A comprehensive Task Manager API built with FastAPI, featuring user authentication, task management, and SQLite database integration.

Features

  • User registration and authentication with JWT tokens
  • Task CRUD operations (Create, Read, Update, Delete)
  • Task filtering by status and priority
  • User profile management
  • SQLite database with SQLAlchemy ORM
  • Database migrations with Alembic
  • API documentation with Swagger UI
  • Health check endpoint
  • CORS enabled for all origins

Project Structure

├── main.py                 # FastAPI application entry point
├── requirements.txt        # Python dependencies
├── alembic.ini            # Alembic configuration
├── alembic/               # Database migrations
├── app/
│   ├── api/               # API route handlers
│   │   ├── auth.py        # Authentication endpoints
│   │   ├── tasks.py       # Task management endpoints
│   │   └── users.py       # User management endpoints
│   ├── core/              # Core application logic
│   │   ├── auth.py        # Authentication dependencies
│   │   ├── config.py      # Application configuration
│   │   └── security.py    # Security utilities
│   ├── db/                # Database configuration
│   │   ├── base.py        # SQLAlchemy base class
│   │   └── session.py     # Database session management
│   ├── models/            # SQLAlchemy models
│   │   ├── task.py        # Task model
│   │   └── user.py        # User model
│   ├── schemas/           # Pydantic schemas
│   │   ├── task.py        # Task schemas
│   │   └── user.py        # User schemas
│   └── services/          # Business logic layer
│       ├── task.py        # Task service
│       └── user.py        # User service
└── storage/
    └── db/                # SQLite database storage

Installation

  1. Install dependencies:
pip install -r requirements.txt
  1. Run database migrations:
alembic upgrade head
  1. Start the application:
uvicorn main:app --reload

The API will be available at http://localhost:8000

Environment Variables

Set the following environment variables for production:

  • SECRET_KEY: Secret key for JWT token signing (default: "your-secret-key-here")

Example:

export SECRET_KEY="your-super-secret-key-here"

API Endpoints

Authentication

  • POST /auth/register - Register a new user
  • POST /auth/login - Login and get access token

Tasks

  • GET /tasks/ - Get all tasks for authenticated user
  • POST /tasks/ - Create a new task
  • GET /tasks/{task_id} - Get a specific task
  • PUT /tasks/{task_id} - Update a task
  • DELETE /tasks/{task_id} - Delete a task

Users

  • GET /users/me - Get current user profile
  • PUT /users/me - Update current user profile

System

  • GET / - API information
  • GET /health - Health check endpoint

API Documentation

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc
  • OpenAPI JSON: http://localhost:8000/openapi.json

Task Management

Task Status Options

  • pending - Task is pending
  • in_progress - Task is in progress
  • completed - Task is completed
  • cancelled - Task is cancelled

Task Priority Options

  • low - Low priority
  • medium - Medium priority
  • high - High priority
  • urgent - Urgent priority

Authentication

The API uses JWT (JSON Web Tokens) for authentication. After registration or login, include the token in the Authorization header:

Authorization: Bearer <your-jwt-token>

Database

The application uses SQLite as the database with the following features:

  • Database file stored at /app/storage/db/db.sqlite
  • Automatic table creation on startup
  • Database migrations managed by Alembic
  • Relationships between users and tasks

Development

Running Tests

To run tests (when available):

pytest

Code Formatting

The project uses Ruff for code formatting and linting:

ruff check .
ruff format .

Database Operations

Create a new migration:

alembic revision --autogenerate -m "description"

Apply migrations:

alembic upgrade head

Health Check

The application provides a health check endpoint at /health that returns:

{
  "status": "healthy",
  "service": "Task Manager API",
  "version": "1.0.0"
}

License

This project is generated by BackendIM, the AI-powered backend generation platform.