← Home|
Backend Documentation

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

CategoryTechnology
FrameworkFastAPI
RuntimePython 3.10
DeploymentAWS Lambda (Docker container)
ASGI AdapterMangum
DatabaseAmazon DynamoDB
CacheRedis (AWS ElastiCache)
AuthenticationJWT + Custom Crypto
InfrastructureTerraform (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.py

Application entrypoint and Mangum Lambda handler

terraform/

AWS infrastructure provisioning — VPC, ECR, API Gateway, DynamoDB, ElastiCache, IAM, Lambda

Dockerfile

Lambda container image specification

requirements.txt

Python dependencies definition

Database Schema (DynamoDB)

Users Table (USERS_TABLE)

Partition Keyuser_id (String — VAH... prefix and auto-increment sequence)
GSIemail-index (Partition Key: email)
Attributes
user_idusernameemailpasswordroleactivation_status

Tasks Table (TASKS_TABLE)

Partition Keyuser_id (String)
Sort Keytask_id (String — UUID)
Attributes
user_idtask_idtitledescriptionstatus (pending/ongoing/complete)created_at

Authentication Flow

1

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.

2

Login

POST /api/v1/auth/login — Queries DynamoDB using email-index GSI, validates decrypted password, returns signed JWT via 'Bearer' token on success.

3

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)

Cache Keytasks:{user_id}
TTL300 seconds (5 minutes)
Used ForGET /api/v1/tasks/fetch-task
InvalidationAggressively invalidated strictly upon task creation, update, or deletion operations
FallbackRedis connection issues immediately flag 'redis_disabled=True' globally to prevent continuous request latency; Redis is bypassed locally when ENVIRONMENT='development'.

API Endpoints

Authentication

POST/api/v1/auth/registerPUBLIC

Register 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

POST/api/v1/auth/loginPUBLIC

Login and retrieve authentication JWT token

Request Body

{
  "email": "string",
  "password": "string"
}

Response: access_token and token_type ('bearer')

GET/api/v1/auth/userAUTH

Get current authenticated user info and detailed task statistics

Response: task_data (counts per status) and user_data objects

Tasks

POST/api/v1/tasks/create-taskAUTH

Create a new assigned task

Request Body

{
  "title": "string",
  "description": "string"
}

Response: Generated task_id alongside input details

GET/api/v1/tasks/fetch-taskAUTH

Fetch all tasks for the logged in user (Cached heavily using Redis)

Response: List Array containing full task items

PUT/api/v1/tasks/update-task/{task_id}AUTH

Update specific task workflow status

Request Body

{
  "status": "string (pending/ongoing/complete)"
}

Response: Success notification reflecting action.

DELETE/api/v1/tasks/delete-task/{task_id}AUTH

Permanently delete task instance

Response: Status update signifying deletion

Admin

GET/api/v1/admin/usersAUTH

List all registered users (Strictly admin role required)

Response: Array of user objects containing system info

PUT/api/v1/admin/update-user/{user_id}AUTH

Update 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

1
python -m venv venv && source venv/bin/activate

Establish and link local virtual environment dependencies

2
pip install -r requirements.txt

Bulk assemble dependent libraries

3
cp .env.example .env

Copy settings locally into isolated '.env' reference. Initialize default parameters (Mandatory: ENVIRONMENT='development' to locally circumvent timeout latency defaults via AWS Redis routing attempts)

4
uvicorn app.main:app --reload

Serve and execute application via ASGI Uvicorn.

Environment Variables

VariableDescriptionExample
AWS_REGIONAWS region location for resources (e.g. DynamoDB)us-east-1
USERS_TABLETarget DynamoDB users persistence tableprod-users
TASKS_TABLETarget DynamoDB tasks persistence tableprod-tasks
JWT_SECRETSecret salt encryption key for signing secure JWT tokenssuper_secret
PASS_SECRET_KEYCrypto secret used to encrypt/decrypt strings (passwords)crypto_secret_key
REDIS_HOSTEndpoint URL for ElastiCache instanceredis.cluster.local
REDIS_PORTPort connection index for ElastiCache instance6379
ENVIRONMENTSystem execution state context (Used frequently to flag DEV Redis interactions to avoid excessive timeout latency)development

Deployment

1

Configure local credentials profile for AWS console targeting via CLI

2

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.

3

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.

4

Automate/Assign relevant new deployment hashes pointing newly active runtime handlers directly toward matching ECR targets containing the built source content payload.

Infrastructure (Terraform-provisioned)

VPC combined utilizing subnets scaling across networking tiers.
ECR repositories containing actively handled application logic versions built over python:3.10 lambda base structures.
API Gateway executing requests over standard HTTP routing.
AWS Lambda acting uniquely configured with Mangum integrations.
DynamoDB databases persisting elements incorporating diverse indexed global associations strategies.
ElastiCache defining managed integrated memory access.
IAM permissions managing deep functional interactions exclusively defining logic boundaries securely.