
- Setup project structure and FastAPI application - Create SQLite database with SQLAlchemy - Implement user authentication with JWT - Create task and user models - Add CRUD operations for tasks and users - Configure Alembic for database migrations - Implement API endpoints for task management - Add error handling and validation - Configure CORS middleware - Create health check endpoint - Add comprehensive documentation
Task Management Tool
A robust task management API built with FastAPI and SQLite.
Features
- User authentication with JWT
- Task management (create, read, update, delete)
- Task priority and status tracking
- Role-based access control (admin/regular users)
- Error handling and validation
- SQLite database with SQLAlchemy ORM
- Database migrations with Alembic
Requirements
- Python 3.8+
- FastAPI
- SQLAlchemy
- Alembic
- Pydantic
- Python-jose
- Passlib
- Email-validator
- Uvicorn
Installation
- Clone the repository
git clone <repository-url>
cd taskmanagementtool
- Install dependencies
pip install -r requirements.txt
- Set up environment variables (or use default values for development)
# JWT Secret Key
export SECRET_KEY="your-secret-key-here"
# JWT Algorithm
export ALGORITHM="HS256"
# JWT Token Expiration (minutes)
export ACCESS_TOKEN_EXPIRE_MINUTES="11520" # 8 days
- Run database migrations
alembic upgrade head
- Start the server
uvicorn main:app --reload
The API will be available at http://localhost:8000
API Documentation
API documentation is automatically generated and available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Authentication
POST /api/v1/auth/login
- Get access tokenPOST /api/v1/auth/test-token
- Test if token is valid
Users
GET /api/v1/users/
- List all users (admin only)POST /api/v1/users/
- Create a new userGET /api/v1/users/me
- Get current user informationPUT /api/v1/users/me
- Update current user informationGET /api/v1/users/{user_id}
- Get user by ID
Tasks
GET /api/v1/tasks/
- List tasks (admins see all, users see their own)POST /api/v1/tasks/
- Create a new taskGET /api/v1/tasks/{id}
- Get task by IDPUT /api/v1/tasks/{id}
- Update taskDELETE /api/v1/tasks/{id}
- Delete task
Health
GET /api/v1/health
- Check if the service is running
Task Model
Tasks have the following attributes:
id
: Unique identifiertitle
: Task titledescription
: Detailed descriptionpriority
: Priority level (LOW, MEDIUM, HIGH)status
: Current status (TODO, IN_PROGRESS, DONE)due_date
: Optional due dateuser_id
: Owner of the taskcreated_at
: Creation timestampupdated_at
: Last update timestamp
Environment Variables
Variable | Description | Default |
---|---|---|
SECRET_KEY | JWT Secret Key | "YOUR_SECRET_KEY_HERE" |
ALGORITHM | JWT Algorithm | "HS256" |
ACCESS_TOKEN_EXPIRE_MINUTES | JWT Token Expiration (minutes) | 11520 (8 days) |
License
This project is licensed under the MIT License.
Description
Languages
Python
98.4%
Mako
1.6%