
- 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
4.5 KiB
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
- Install dependencies:
pip install -r requirements.txt
- Run database migrations:
alembic upgrade head
- 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 userPOST /auth/login
- Login and get access token
Tasks
GET /tasks/
- Get all tasks for authenticated userPOST /tasks/
- Create a new taskGET /tasks/{task_id}
- Get a specific taskPUT /tasks/{task_id}
- Update a taskDELETE /tasks/{task_id}
- Delete a task
Users
GET /users/me
- Get current user profilePUT /users/me
- Update current user profile
System
GET /
- API informationGET /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 pendingin_progress
- Task is in progresscompleted
- Task is completedcancelled
- Task is cancelled
Task Priority Options
low
- Low prioritymedium
- Medium priorityhigh
- High priorityurgent
- 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.