
- Set up FastAPI project structure with API versioning - Create database models for users and tasks - Implement SQLAlchemy ORM with SQLite database - Initialize Alembic for database migrations - Create API endpoints for task management (CRUD) - Create API endpoints for user management - Add JWT authentication and authorization - Add health check endpoint - Add comprehensive README.md with API documentation
2.8 KiB
2.8 KiB
Task Management Tool
A FastAPI backend for managing tasks with user authentication and SQLite database.
Features
- User registration and authentication with JWT tokens
- Task management with CRUD operations
- Task prioritization and status tracking
- RESTful API with JSON responses
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
- Health check endpoint
API Endpoints
Health Check
GET /health
- Check API health
User Management
POST /users/register
- Register a new userPOST /users/login
- Login and get access tokenGET /users/me
- Get current user infoPUT /users/me
- Update current user info
Task Management
GET /tasks
- List all tasks for current 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
Tech Stack
- FastAPI - Modern, fast web framework for building APIs
- SQLAlchemy - SQL toolkit and Object-Relational Mapping
- Alembic - Database migration tool
- Pydantic - Data validation and settings management
- SQLite - Lightweight relational database
- Python-Jose - JavaScript Object Signing and Encryption (JOSE) implementation
- Passlib - Password hashing library
Setup and Installation
Prerequisites
- Python 3.9+
- pip (Python package installer)
Environment Setup
- Clone the repository:
git clone <repository-url>
cd taskmanagementtool
- Create and activate a virtual environment (optional but recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Set environment variables (optional, defaults are provided):
export SECRET_KEY="your-secret-key"
export ACCESS_TOKEN_EXPIRE_MINUTES=30
Database Setup
- Run Alembic migrations to set up the database:
alembic upgrade head
Running the Application
- Start the FastAPI server:
uvicorn main:app --host 0.0.0.0 --port 8000 --reload
- Access the API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Development
Adding Migrations
When you modify the database models, create a new migration:
alembic revision --autogenerate -m "Description of changes"
Applying Migrations
To update your database to the latest schema:
alembic upgrade head
API Documentation
The API documentation is automatically generated and can be accessed at /docs
or /redoc
endpoints.