- Syed Abdullah Hassan [email protected]
- Muhammad Hassan Sohail. [email protected]
- Uswah Batool. [email protected]
- Mathéo Morin. [email protected]
A RESTful API for managing tasks, projects, teams, and users. Built with Flask, PostgreSQL, and JWT authentication.
- Introduction
- Features
- Prerequisites
- Project Setup
- Database Configuration
- Running the Application
- API Endpoints
- Testing the Application
- Code Quality and Analysis
- Project Structure
- Troubleshooting
This project is a Task Management API built using Flask, SQLAlchemy, and JWT for authentication. It provides endpoints for managing users, teams, projects, and tasks. The API is designed to be modular, scalable, and secure.
- JWT Authentication: Secure user login and token-based access control.
- CRUD Operations:
- Manage users, teams, projects, and tasks.
- Assign tasks to users and link them to projects.
- Caching: Optimized response times using Flask-Caching.
- Input Validation: JSON schema validation for all endpoints.
- Automated Testing: pytest for functional and integration tests.
- Code Quality: Integrated linters (Black, Flake8, Pylint) and security checks (Bandit).
Before you start, ensure you have the following installed on your system:
- Python 3.8 or higher
- Docker and Docker Compose (for database setup)
- Git (for cloning the repository)
git clone https://github.com/Abdullah12has/Task-management-LLM-API.git
cd task-management-api
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install -r requirement-quality.txt
The project uses PostgreSQL as the database. You can set it up using Docker or manually.
docker-compose up -d
docker exec -it my_postgres_db bash
psql -U admin -d task_management_db
\dt # List all tables
docker stop my_postgres_db
docker rm my_postgres_db
Follow the official PostgreSQL installation guide to set up PostgreSQL on your system.
CREATE USER admin WITH PASSWORD 'helloworld123';
CREATE DATABASE task_management_db OWNER admin;
Modify the SQLALCHEMY_DATABASE_URI in app.py to match your local setup:
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://admin:helloworld123@localhost:5432/task_management_db'
python app.py
python app.py
The API will be available at http://127.0.0.1:5000.
POST /login
{
"email": "[email protected]",
"password": "password123"
}
POST /users
{
"username": "newuser",
"email": "[email protected]",
"password": "password123",
"role": "member"
}
GET /users/<user_id>
PUT /users/<user_id>
{
"username": "updateduser",
"email": "[email protected]",
"password": "newpassword123",
"role": "admin"
}
DELETE /users/<user_id>
POST /teams
{
"name": "New Team",
"description": "Team description",
"lead_id": "user_id"
}
GET /teams/<team_id>
PUT /teams/<team_id>
{
"name": "Updated Team",
"description": "Updated description",
"lead_id": "new_user_id"
}
DELETE /teams/<team_id>
POST /projects
{
"title": "New Project",
"description": "Project description",
"team_id": "team_id",
"category_id": "category_id"
}
GET /projects/<project_id>
PUT /projects/<project_id>
{
"title": "Updated Project",
"description": "Updated description",
"team_id": "new_team_id",
"category_id": "new_category_id"
}
DELETE /projects/<project_id>
POST /tasks
{
"title": "New Task",
"description": "Task description",
"project_id": "project_id",
"assignee_id": "user_id",
"status": "pending",
"priority": 3
}
GET /tasks/<task_id>
PUT /tasks/<task_id>
{
"title": "Updated Task",
"description": "Updated description",
"status": "in_progress",
"priority": 2
}
DELETE /tasks/<task_id>
pytest --html=reports/report.html --self-contained-html
Open reports/report.html
in a web browser.
The project includes scripts for code quality checks:
- Black: Code formatter
- isort: Import sorter
- Flake8: Linter
- Pylint: Static analysis
- Bandit: Security analysis
- MyPy: Type checking
To automatically fix formatting issues:
python code_quality.py --fix
.
├── app.py # Application entry point
├── models/ # Database models
├── routes/ # API endpoints
├── schemas/ # Request/response validation schemas
├── utils/ # Utility functions and helpers
├── tests/ # Test suites
├── requirements.txt # Project dependencies
├── requirements-test.txt # Testing dependencies
├── requirement-quality.txt # Code quality dependencies
└── docker-compose.yml # Docker configuration
- Ensure the PostgreSQL service is running.
- Verify the database credentials in app.py.
- Reinstall dependencies using pip install -r requirements.txt.
- Check the test output for specific error messages.
- Ensure the test database is properly initialized.
- Review the generated reports for detailed feedback.
- Run python code_quality.py --fix to automatically correct formatting issues.
coverage report -m
coverage html
stateDiagram-v2
[*] --> Users: GET /users
Users --> User: GET /users/{id}
User --> UpdateUser: PUT /users/{id}
UpdateUser --> User
User --> [*]: DELETE /users/{id}
[*] --> Teams: GET /teams
Teams --> Team: GET /teams/{id}
Teams --> CreateTeam: POST /teams
CreateTeam --> Team
Team --> UpdateTeam: PUT /teams/{id}
UpdateTeam --> Team
Team --> [*]: DELETE /teams/{id}
Team --> TeamMembers: GET /teams/{id}/members
TeamMembers --> CreateTeamMember: POST /teams/{id}/members
CreateTeamMember --> TeamMember
TeamMember --> UpdateTeamMember: PUT /teams/{id}/members/{user_id}
UpdateTeamMember --> TeamMember
TeamMember --> [*]: DELETE /teams/{id}/members/{user_id}
[*] --> Projects: GET /projects
Projects --> Project: GET /projects/{id}
Projects --> CreateProject: POST /projects
CreateProject --> Project
Project --> UpdateProject: PUT /projects/{id}
UpdateProject --> Project
Project --> [*]: DELETE /projects/{id}
Project --> Tasks: GET /tasks?project_id={id}
Tasks --> Task: GET /tasks/{id}
[*] --> Tasks: GET /tasks
Tasks --> Task: GET /tasks/{id}
Tasks --> CreateTask: POST /tasks
CreateTask --> Task
Task --> UpdateTask: PUT /tasks/{id}
UpdateTask --> Task
Task --> [*]: DELETE /tasks/{id}
%% Optional connections to show better connectedness
User --> Teams: GET /users/{id}/teams
Task --> Project: GET /projects/{id}