A Flask-based REST API that powers the Team Task Manager (TeamFlow) application.
This backend provides:
- JWT-based authentication
- Secure task CRUD operations
- PostgreSQL persistence via SQLAlchemy
- CORS-enabled API access for frontend clients
- Production-style application factory pattern
It is designed to be consumed by a modern frontend (React/Vite) and deployed in real-world DevOps environments.
- Overview
- Features
- Tech Stack
- Architecture Overview
- Authentication & Authorization
- API Endpoints
- Database Models
- Environment Variables
- Local Development Setup
- Database Initialization & Seeding
- Running the Application
- Security Considerations
- Assumptions
- Future Improvements
The Team Task Manager Backend is a RESTful API built with Flask that handles:
- User authentication (signup & login)
- JWT token generation and verification
- Task creation, retrieval, updating, and deletion
- Database persistence using PostgreSQL
All task endpoints are protected and require a valid JWT token.
- User signup
- User login
- JWT token issuance
- Token validation via request middleware
- Password hashing with Werkzeug
- Create tasks
- Retrieve all tasks
- Update tasks
- Delete tasks
- Task attributes:
- Title
- Description
- Priority (low, medium, high)
- Status (todo, in_progress, done)
- Flask application factory pattern
- SQLAlchemy ORM
- Automatic database table creation
- Default user seeding
- CORS enabled for frontend integration
- Python 3
- Flask
- Flask-SQLAlchemy
- Flask-CORS
- PyJWT
- PostgreSQL
- psycopg2-binary
- python-dotenv
- werkzeug.security
The backend follows a clean, modular structure:
Request
↓
Flask Routes (Blueprint)
↓
Auth Middleware (JWT validation)
↓
Service / Model Logic
↓
SQLAlchemy ORM
↓
PostgreSQL Database
Key Design Choices
- Blueprint-based routing (
/api) - Decorator-based authentication
- Centralized app creation
- Environment-driven configuration
- Tokens are generated using HS256
- Tokens contain:
user_idusername
- Tokens are passed via the Authorization header
Example:
Authorization: Bearer <JWT_TOKEN>
Protected routes use a decorator: @token_required
If the token is:
- Missing → 401 Unauthorized
- Invalid → 401 Unauthorized
- Malformed → 401 Unauthorized
POST /api/auth/signup
Creates a new user and returns a JWT token.
Request Body
{
"username": "example",
"password": "password123"
}POST /api/auth/login
Authenticates a user and returns a JWT token.
All task endpoints require authentication.
GET /api/tasks
Returns all tasks (ordered by creation date).
POST /api/tasks
Creates a new task.
Request Body
{
"title": "My Task",
"description": "Optional description",
"priority": "medium",
"status": "todo"
}PUT /api/tasks/<id>
Updates an existing task.
DELETE /api/tasks/<id>
Deletes a task.
- id
- username (unique)
- password_hash
- created_at
- id
- title
- description
- priority
- status
- created_at
- updated_at
SQLAlchemy automatically maps models to PostgreSQL tables.
Create a .env file (not committed):
DATABASE_URL=postgresql://taskapp_user:taskapp_password@localhost:5432/taskapp
SECRET_KEY=change-this-in-production
PORT=5000Important Notes
SECRET_KEYmust be changed in productionDATABASE_URLshould point to PostgreSQL- Defaults are provided for local development
- Python 3.10+
- PostgreSQL
- pip or virtualenv
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtOn application startup:
- Tables are created automatically using
db.create_all() - Default users are seeded only if no users exist
| Username | Password |
|---|---|
| admin | admin123 |
| user | user123 |
This is intended for development and demo purposes only.
Start the Server
python run.pyThe API will be available at:
http://localhost:5000/api
- Passwords are hashed using Werkzeug
- JWT tokens are signed with a secret key
- All task routes are protected
- CORS is enabled (should be restricted in production)
Warning: This setup is suitable for development and demos.
Production systems should add:
- Token expiration
- Refresh tokens
- Role-based access control
- Rate limiting
- PostgreSQL is available and reachable
- Frontend supplies JWT tokens correctly
- API is deployed behind HTTPS in production
- Database migrations are handled externally if needed
- Token expiration & refresh tokens
- Role-Based Access Control (RBAC)
- Per-user task ownership
- Alembic migrations
- Structured logging
- API versioning
- Dockerized deployment
- CI/CD integration