Backend
Task Manager — FastAPI Serverless Application
A serverless application built with FastAPI, deployed on AWS Lambda via Docker container images. Uses Mangum to deploy as serverless, Amazon DynamoDB for persistent data storage, and Redis (via AWS ElastiCache) for caching.
Overview
A serverless application built with FastAPI, deployed on AWS Lambda via Docker container images. Uses Mangum to deploy as serverless, Amazon DynamoDB for persistent data storage, and Redis (via AWS ElastiCache) for caching.
Tech Stack
| Category | Technology |
|---|---|
| Framework | FastAPI |
| Runtime | Python 3.10 |
| Deployment | AWS Lambda (Docker container) |
| ASGI Adapter | Mangum |
| Database | Amazon DynamoDB |
| Cache | Redis (AWS ElastiCache) |
| Authentication | JWT + Custom Crypto |
| Infrastructure | Terraform (IaC) |
Project Structure
Root: backend/
app/api/v1/middleware/JWT Authentication middleware — get_current_user_id
app/api/v1/routes/FastAPI routers for Auth, Tasks, and Admin
app/config/Environment variables loader, database client, and Redis client setup
app/services/Core business logic — AuthService, TaskService, and AdminService
app/utils/JWT and cryptographic helper functions
app/main.pyApplication entrypoint and Mangum Lambda handler
terraform/AWS infrastructure provisioning — VPC, ECR, API Gateway, DynamoDB, ElastiCache, IAM, Lambda
DockerfileLambda container image specification
requirements.txtPython dependencies definition
Database Schema (DynamoDB)
Users Table (USERS_TABLE)
user_id (String — VAH... prefix and auto-increment sequence)email-index (Partition Key: email)user_idusernameemailpasswordroleactivation_statusTasks Table (TASKS_TABLE)
user_id (String)task_id (String — UUID)user_idtask_idtitledescriptionstatus (pending/ongoing/complete)created_atAuthentication Flow
Registration
POST /api/v1/auth/register — Generates unique 'VAH' user_id, encrypts password using custom crypto logic, stored with default 'user' role and 'active' status in DynamoDB Users Table.
Login
POST /api/v1/auth/login — Queries DynamoDB using email-index GSI, validates decrypted password, returns signed JWT via 'Bearer' token on success.
Protected Routes
get_current_user_id middleware intercepts requests, extracts Bearer token from header, validates it using JWT secret, and injects user_id.
Caching Strategy (Redis)
API Endpoints
Authentication
/api/v1/auth/registerPUBLICRegister a new user
Request Body
{
"username": "string",
"email": "string",
"password": "string(length 6-15, special chars included)",
"role": "string(optional)",
"activation_status": "string(optional)"
}Response: User details and activation status
/api/v1/auth/loginPUBLICLogin and retrieve authentication JWT token
Request Body
{
"email": "string",
"password": "string"
}Response: access_token and token_type ('bearer')
/api/v1/auth/userAUTHGet current authenticated user info and detailed task statistics
Response: task_data (counts per status) and user_data objects
Tasks
/api/v1/tasks/create-taskAUTHCreate a new assigned task
Request Body
{
"title": "string",
"description": "string"
}Response: Generated task_id alongside input details
/api/v1/tasks/fetch-taskAUTHFetch all tasks for the logged in user (Cached heavily using Redis)
Response: List Array containing full task items
/api/v1/tasks/update-task/{task_id}AUTHUpdate specific task workflow status
Request Body
{
"status": "string (pending/ongoing/complete)"
}Response: Success notification reflecting action.
/api/v1/tasks/delete-task/{task_id}AUTHPermanently delete task instance
Response: Status update signifying deletion
Admin
/api/v1/admin/usersAUTHList all registered users (Strictly admin role required)
Response: Array of user objects containing system info
/api/v1/admin/update-user/{user_id}AUTHUpdate users administrative data (Admin only)
Request Body
{
"username": "string(optional)",
"email": "string(optional)",
"password": "string(optional)",
"activation_status": "string(optional)"
}Response: Updated user validation status
Local Setup
python -m venv venv && source venv/bin/activateEstablish and link local virtual environment dependencies
pip install -r requirements.txtBulk assemble dependent libraries
cp .env.example .envCopy settings locally into isolated '.env' reference. Initialize default parameters (Mandatory: ENVIRONMENT='development' to locally circumvent timeout latency defaults via AWS Redis routing attempts)
uvicorn app.main:app --reloadServe and execute application via ASGI Uvicorn.
Environment Variables
| Variable | Description | Example |
|---|---|---|
AWS_REGION | AWS region location for resources (e.g. DynamoDB) | us-east-1 |
USERS_TABLE | Target DynamoDB users persistence table | prod-users |
TASKS_TABLE | Target DynamoDB tasks persistence table | prod-tasks |
JWT_SECRET | Secret salt encryption key for signing secure JWT tokens | super_secret |
PASS_SECRET_KEY | Crypto secret used to encrypt/decrypt strings (passwords) | crypto_secret_key |
REDIS_HOST | Endpoint URL for ElastiCache instance | redis.cluster.local |
REDIS_PORT | Port connection index for ElastiCache instance | 6379 |
ENVIRONMENT | System execution state context (Used frequently to flag DEV Redis interactions to avoid excessive timeout latency) | development |
Deployment
Configure local credentials profile for AWS console targeting via CLI
Navigate workspace into 'terraform/' initializing workspace via 'terraform init' applying current 'main' module specifications representing VPC routing layers, App Gateway instances, IAM credential specifications, and Database instance formations.
Execute Docker compilation parameters to encapsulate logic matching specific Lambda AWS Python images and stream output instances directly towards respective dedicated ECR hosting registry endpoints.
Automate/Assign relevant new deployment hashes pointing newly active runtime handlers directly toward matching ECR targets containing the built source content payload.