Skip to content

MehemudAzad/fat32-api-avengers

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CareForAll - API Avengers Microservices Platform

Team FAT32

A highly scalable, event-driven donation platform built for the CUET API Avengers Microservice Hackathon 2025

Python FastAPI Docker License


πŸ“‹ Table of Contents


🎯 Overview

CareForAll is a production-ready, cloud-native donation platform designed to handle:

  • βœ… High Traffic: 1000+ requests/second capacity
  • βœ… Event-Driven Architecture: Kafka-based asynchronous communication
  • βœ… Idempotent Operations: Reliable payment processing with webhook handling
  • βœ… Complete Observability: Distributed tracing, log aggregation, and metrics
  • βœ… Transparent Donation Tracking: Full donation lifecycle management
  • βœ… Scalable Design: Independent microservices with dedicated databases

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend  β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      API Gateway (8000)                      β”‚
β”‚   β€’ Authentication & Authorization (JWT)                     β”‚
β”‚   β€’ Rate Limiting & Circuit Breaking                         β”‚
β”‚   β€’ Request Routing & Load Balancing                         β”‚
β”‚   β€’ Distributed Tracing                                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚                   β”‚                   β”‚
       β–Ό                   β–Ό                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚User Service β”‚    β”‚  Campaign   β”‚    β”‚  Donation   β”‚
β”‚   (8001)    β”‚    β”‚  Service    β”‚    β”‚  Service    β”‚
β”‚             β”‚    β”‚   (8002)    β”‚    β”‚   (8004)    β”‚
β”‚ β€’ Auth/JWT  β”‚    β”‚             β”‚    β”‚             β”‚
β”‚ β€’ Profiles  β”‚    β”‚ β€’ CRUD      │◄──── β€’ Pledges   β”‚
β”‚ β€’ Roles     β”‚    β”‚ β€’ gRPC      β”‚gRPCβ”‚ β€’ FSM       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
                                              β”‚
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
                   β”‚                          β”‚
                   β–Ό                          β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚  Payment    β”‚          β”‚ Notificationβ”‚
            β”‚  Service    β”‚          β”‚  Service    β”‚
            β”‚   (8003)    β”‚          β”‚   (8005)    β”‚
            β”‚             β”‚          β”‚             β”‚
            β”‚ β€’ Webhooks  β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚ β€’ Events   β”‚
            β”‚ β€’ Banking   β”‚  Kafka   β”‚ β€’ Alerts    β”‚
            β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β”‚  Banking    β”‚
            β”‚  Service    β”‚
            β”‚   (8006)    β”‚
            β”‚             β”‚
            β”‚ β€’ Accounts  β”‚
            β”‚ β€’ Verify    β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚   Infrastructure        β”‚
         β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
         β”‚ Kafka + Zookeeper       β”‚
         β”‚ PostgreSQL (per service)β”‚
         β”‚ Redis (caching)         β”‚
         β”‚ Jaeger (tracing)        β”‚
         β”‚ Loki + Promtail (logs)  β”‚
         β”‚ Grafana (visualization) β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Technologies Used

Core Framework

Technology Version Purpose
Python 3.11+ Primary programming language
FastAPI 0.104+ High-performance async web framework
Uvicorn Latest ASGI server for production
Pydantic 2.x Data validation and settings management

Databases

Technology Usage
PostgreSQL 15-alpine - Dedicated database per service
Redis 7-alpine - Caching, rate limiting, session storage

Message Broker

Technology Purpose
Apache Kafka Event streaming, async communication
Zookeeper Kafka cluster coordination
Kafka UI Web-based Kafka management

Communication Protocols

  • REST API: HTTP/JSON for synchronous communication
  • gRPC: High-performance RPC between donation-service ↔ campaign-service
  • Kafka Events: Asynchronous event-driven messaging

Observability

Tool Purpose Port
Jaeger Distributed tracing 16686
Loki Log aggregation 3100
Promtail Log collection agent -
Grafana Metrics & logs visualization 3000
OpenTelemetry Instrumentation SDK -

DevOps & Infrastructure

  • Docker - Containerization
  • Docker Compose - Multi-container orchestration
  • GitHub Actions - CI/CD (future)

πŸ”¬ Microservices

1️⃣ API Gateway (Port 8000)

Role: Single entry point for all client requests

Responsibilities:

  • πŸ” Authentication: JWT token validation
  • 🚦 Rate Limiting: Redis-based request throttling
  • ⚑ Circuit Breaking: Fault tolerance for downstream services
  • πŸ”„ Load Balancing: Intelligent request distribution
  • πŸ“Š Request Tracing: Distributed tracing with Jaeger
  • πŸ—‚οΈ Service Registry: Dynamic service discovery

Tech Stack:

  • FastAPI, Redis, OpenTelemetry, JWT

Key Features:

  • Configurable rate limits per endpoint
  • Automatic circuit breaking on service failures
  • Request/Response logging with correlation IDs
  • Health check aggregation

2️⃣ User Service (Port 8001)

Role: User authentication and profile management

Database: userdb (PostgreSQL)

Responsibilities:

  • πŸ‘€ User Management: Registration, login, profile updates
  • πŸ”‘ Authentication: JWT token generation and validation
  • 🎭 Role-Based Access: DONOR, CAMPAIGN_OWNER, ADMIN roles
  • πŸ“ User Profiles: Donor and campaign owner information

Tech Stack:

  • FastAPI, SQLAlchemy, PostgreSQL, JWT, Bcrypt

API Endpoints:

POST   /register          - Create new user account
POST   /login             - Authenticate and get JWT token
GET    /users/me          - Get current user profile
PUT    /users/me          - Update user profile
GET    /users/{id}        - Get user by ID (admin)

Key Features:

  • Password hashing with bcrypt
  • JWT token with expiry
  • Role-based authorization
  • User session management

3️⃣ Campaign Service (Port 8002)

Role: Fundraising campaign management

Database: campaigndb (PostgreSQL)

Responsibilities:

  • πŸ“’ Campaign CRUD: Create, read, update, delete campaigns
  • 🎯 Goal Tracking: Monitor fundraising goals and progress
  • βœ… Status Management: ACTIVE, PAUSED, COMPLETED, CANCELLED
  • πŸ”Œ gRPC Server: High-performance RPC endpoint for donation-service

Tech Stack:

  • FastAPI, SQLAlchemy, PostgreSQL, gRPC, Redis (caching)

API Endpoints:

POST   /campaigns         - Create new campaign
GET    /campaigns         - List all campaigns (paginated)
GET    /campaigns/{id}    - Get campaign details
PUT    /campaigns/{id}    - Update campaign
DELETE /campaigns/{id}    - Delete campaign

gRPC Methods:

rpc GetCampaign(CampaignRequest) returns (CampaignResponse);
rpc UpdateCampaignTotal(UpdateTotalRequest) returns (UpdateTotalResponse);

Key Features:

  • Redis caching for frequently accessed campaigns
  • Real-time goal progress updates via gRPC
  • Campaign owner verification
  • Media attachments support

4️⃣ Donation Service (Port 8004)

Role: Donation pledge and lifecycle management

Database: donation_db (PostgreSQL)

Responsibilities:

  • πŸ’ Donation Creation: Handle donation intents
  • πŸ”„ State Machine: INITIATED β†’ PENDING β†’ AUTHORIZED β†’ CAPTURED β†’ COMPLETED/FAILED/REFUNDED
  • πŸ“€ Event Publishing: Emit donation events to Kafka
  • πŸ“₯ Event Consumption: Listen to payment events
  • πŸ”Œ gRPC Client: Communicate with campaign-service

Tech Stack:

  • FastAPI, SQLAlchemy, PostgreSQL, AIOKafka, gRPC client

Kafka Topics:

  • Produces: donation_created - When new donation is initiated
  • Consumes: payment.events - Payment verification results

API Endpoints:

POST   /donations         - Create new donation
GET    /donations/{id}    - Get donation details
GET    /donations         - List user donations
GET    /campaigns/{id}/donations - List campaign donations

State Machine Flow:

INITIATED β†’ payment verification request
         ↓
PENDING β†’ awaiting payment service
         ↓
AUTHORIZED β†’ payment verified
         ↓
CAPTURED β†’ funds debited
         ↓
COMPLETED βœ…

Key Features:

  • Comprehensive emoji-based logging
  • Automatic campaign total updates via gRPC
  • Kafka-based async payment processing
  • Donation history tracking

5️⃣ Payment Service (Port 8003)

Role: Payment processing and banking integration

Database: payment_db (PostgreSQL)

Responsibilities:

  • πŸ’³ Payment Verification: Validate payment requests
  • 🏦 Banking Integration: Communicate with banking-service
  • πŸ” Idempotent Webhooks: Handle duplicate webhook deliveries
  • πŸ“€ Event Publishing: Emit payment success/failure events

Tech Stack:

  • FastAPI, SQLAlchemy, PostgreSQL, Confluent Kafka, HTTPx

Kafka Topics:

  • Consumes: donation_created - New donation events
  • Produces: payment.events - Payment verification results

Payment Flow:

1. Consume donation_created event
2. Call banking-service to verify funds
3. Debit user account if sufficient balance
4. Publish payment.verified or payment.failed event
5. Update donation-service via Kafka

Key Features:

  • Async payment processing
  • Fund verification before debit
  • Detailed transaction logging
  • Webhook signature verification (future)

6️⃣ Banking Service (Port 8006)

Role: Mock banking system for account operations

Database: banking_db (PostgreSQL)

Responsibilities:

  • πŸ’° Account Management: Create and manage user accounts
  • πŸ’΅ Balance Operations: Check balance, debit, credit
  • βœ… Transaction Validation: Verify sufficient funds
  • πŸ“Š Transaction History: Track all account operations

Tech Stack:

  • FastAPI, SQLAlchemy, PostgreSQL

API Endpoints:

POST   /accounts          - Create new account
GET    /accounts/{id}     - Get account details
POST   /verify            - Verify sufficient funds
POST   /debit             - Debit from account
POST   /credit            - Credit to account
GET    /transactions/{account_id} - Get transaction history

Key Features:

  • Thread-safe balance operations
  • Transaction atomicity
  • Audit trail for all operations
  • Negative balance prevention

7️⃣ Notification Service (Port 8005)

Role: Event-driven notification system

Database: notification_db (PostgreSQL)

Responsibilities:

  • πŸ“§ Email Notifications: Send donation receipts (mocked)
  • πŸ“± In-app Alerts: Store notifications for users
  • πŸ“₯ Event Listening: Consume Kafka events
  • πŸ”” Real-time Updates: WebSocket support (future)

Tech Stack:

  • FastAPI, SQLAlchemy, PostgreSQL, Confluent Kafka

Kafka Topics:

  • Consumes: payment.events - Payment verification results

Notification Types:

  • Donation success confirmation
  • Payment failure alerts
  • Campaign milestone reached
  • Campaign owner updates

Key Features:

  • Async event processing
  • Template-based notifications
  • Notification history
  • User preference management (future)

🏭 Infrastructure Components

Kafka Ecosystem

Component Purpose Port
Zookeeper Kafka cluster coordination 2181
Kafka Broker Message streaming 9092
Kafka UI Web-based management 8080

Topics:

  • donation_created - New donation events
  • payment.events - Payment verification results

Consumer Groups:

  • payment-service-group - Payment processing
  • donation-service-group - Donation status updates
  • notification-service-group - Notification delivery

Databases

Each service has a dedicated PostgreSQL database for data isolation:

Service Database Port
User userdb 5433
Campaign campaigndb 5434
Notification notification_db 5435
Payment payment_db 5436
Donation donation_db 5437
Banking banking_db 5438

Benefits:

  • Service autonomy
  • Independent scaling
  • Failure isolation
  • Schema evolution flexibility

Redis

Purpose: Distributed caching and session management

Port: 6379

Use Cases:

  • API Gateway rate limiting
  • Campaign data caching
  • Session storage
  • Distributed locks

πŸ“Š Observability Stack

Distributed Tracing - Jaeger

Port: 16686

Features:

  • End-to-end request tracing
  • Service dependency visualization
  • Performance bottleneck identification
  • gRPC call tracing

Access: http://localhost:16686


Log Aggregation - Loki + Promtail

Loki Port: 3100

Features:

  • Centralized log collection from all containers
  • Label-based log filtering
  • Real-time log streaming
  • Long-term log retention (31 days)

Log Labels:

  • container_name - Service identifier
  • service - Service name
  • version - Service version
  • level - Log level (INFO, ERROR, etc.)

Visualization - Grafana

Port: 3000

Credentials: admin/admin

Dashboards:

  1. CareForAll Logs Dashboard - Service-specific log panels
  2. Error Monitoring - Platform-wide error aggregation
  3. Trace-to-Log Correlation - Jump from traces to logs

Datasources:

  • Loki (logs)
  • Jaeger (traces)

Access: http://localhost:3000


πŸš€ Getting Started

Prerequisites

  • Docker Desktop (latest)
  • Docker Compose (latest)
  • 8GB+ RAM
  • 20GB+ disk space

Quick Start

  1. Clone the repository
git clone https://github.com/sleepytmzd/fat32-api-avengers.git
cd fat32-api-avengers
  1. Start all services
docker-compose up -d
  1. Verify services are healthy
docker-compose ps
  1. Access the platform

Development Setup

For individual service development:

# User Service
cd user-service
pip install -r requirements.txt
uvicorn main:app --reload --port 8001

# Similar for other services...

Stop All Services

docker-compose down

Clean Everything (including data)

docker-compose down -v
rm -rf data/

☸️ Kubernetes Deployment

Production Deployment on DigitalOcean

The CareForAll platform is deployed on a production-grade Kubernetes cluster with enterprise features:

🎯 Key Features:

  • βœ… Horizontal Pod Autoscaling (HPA): Automatic scaling based on CPU/Memory utilization
  • βœ… TLS Termination: HTTPS encryption with Let's Encrypt certificates
  • βœ… Ingress Controller: NGINX ingress for intelligent routing
  • βœ… StatefulSets: For Kafka, Zookeeper, and PostgreSQL databases
  • βœ… Persistent Volumes: Durable storage for databases and logs
  • βœ… Resource Limits: CPU/Memory limits per service
  • βœ… Health Checks: Liveness and readiness probes
  • βœ… Rolling Updates: Zero-downtime deployments

Cluster Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 DigitalOcean Kubernetes                  β”‚
β”‚                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚           NGINX Ingress Controller              β”‚    β”‚
β”‚  β”‚         (teamfat32.duckdns.org)                 β”‚    β”‚
β”‚  β”‚              TLS/HTTPS Enabled                  β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                   β”‚                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚           API Gateway (LoadBalancer)            β”‚    β”‚
β”‚  β”‚              Port 8000 (HTTPS)                  β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                   β”‚                                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚              Microservices Layer                β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚    β”‚
β”‚  β”‚  β”‚  User    β”‚ β”‚ Campaign β”‚ β”‚ Donation β”‚       β”‚    β”‚
β”‚  β”‚  β”‚ Service  β”‚ β”‚ Service  β”‚ β”‚ Service  β”‚       β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”‚    β”‚
β”‚  β”‚  β”‚ Payment  β”‚ β”‚ Banking  β”‚ β”‚  Notify  β”‚       β”‚    β”‚
β”‚  β”‚  β”‚ Service  β”‚ β”‚ Service  β”‚ β”‚ Service  β”‚       β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚          Infrastructure Services                β”‚    β”‚
β”‚  β”‚  β€’ Kafka (StatefulSet)                          β”‚    β”‚
β”‚  β”‚  β€’ PostgreSQL Databases (StatefulSet x6)        β”‚    β”‚
β”‚  β”‚  β€’ Redis (Deployment)                           β”‚    β”‚
β”‚  β”‚  β€’ Prometheus (StatefulSet)                     β”‚    β”‚
β”‚  β”‚  β€’ Grafana (Deployment)                         β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Deployment Manifests

All Kubernetes manifests are located in the /k8s folder:

Horizontal Pod Autoscaling (HPA)

All microservices are configured with HPA for automatic scaling:

Scaling Behavior:

  • API Gateway: 2-10 replicas (scales at 70% CPU)
  • Microservices: 2-8 replicas (scales at 70% CPU)
  • Scale-up: 1 pod every 30 seconds
  • Scale-down: 1 pod every 5 minutes (stabilization)

TLS/HTTPS Configuration

TLS termination is handled by cert-manager with Let's Encrypt:

Features:

  • Automatic certificate generation and renewal
  • HTTP to HTTPS redirect
  • TLS 1.2+ only
  • Production-grade Let's Encrypt certificates

Deploy to Kubernetes

# Apply all manifests
kubectl apply -f k8s/

# Check deployment status
kubectl get pods -n default

# View HPA status
kubectl get hpa

# Check ingress
kubectl get ingress

# View logs
kubectl logs -f deployment/api-gateway

# Scale manually (if needed)
kubectl scale deployment/api-gateway --replicas=5

Access Production Services


πŸš€ CI/CD Pipeline

Automated Deployment Workflow

The project uses GitHub Actions for intelligent CI/CD with change detection:

πŸ“¦ Pipeline Features:

  • βœ… Change Detection: Only build/test modified services using dorny/paths-filter
  • βœ… Parallel Testing: 8 concurrent test jobs for each service
  • βœ… Docker Multi-arch Builds: AMD64 and ARM64 support
  • βœ… Image Tagging: Semantic versioning with Git SHA tags
  • βœ… Automated Deployment: Push to DigitalOcean Kubernetes
  • βœ… Rollout Verification: Ensures successful deployment
  • βœ… Rollback on Failure: Automatic rollback if deployment fails

Workflow Structure

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  GitHub Actions Workflow                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β–Ό                                  β–Ό
    Detect Changes                     Run Tests (Parallel)
  (dorny/paths-filter)                       β”‚
          β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                    β–Ό             β–Ό             β–Ό
          β”‚              test-user    test-campaign  test-donation
          β”‚              test-payment test-banking   test-notify
          β”‚              test-api-gw  test-frontend
          β”‚                    β”‚
          └────────────────────┴─────────────┐
                                             β–Ό
                                    Build Docker Images
                                  (only changed services)
                                             β”‚
                                             β–Ό
                                    Push to DockerHub
                                             β”‚
                                             β–Ό
                                   Deploy to Kubernetes
                                             β”‚
                                             β–Ό
                                   Verify Rollout Status

CI/CD Configuration

Workflow files are in the /.github/workflows directory:

Main Pipeline (cicd.yml)

Trigger Conditions:

  • Push to main or develop branches
  • Pull requests to main
  • Manual workflow dispatch

Pipeline Stages:

  1. Detect Changes (30s)

    • Uses dorny/paths-filter@v2
    • Outputs boolean flags for each service
  2. Run Tests (2-5 minutes per service)

    • Parallel execution (8 jobs)
    • Only runs if service changed
    • Runs unit + integration tests
    • Generates coverage reports
  3. Build Docker Images (5-10 minutes)

    • Only builds changed services
    • Multi-stage builds for optimization
    • Tags: latest, v{version}, sha-{git-sha}
    • Caches layers for faster builds
  4. Push to Registry (2-3 minutes)

    • Pushes to DockerHub
    • Credentials from GitHub Secrets
    • Retries on failure (3 attempts)
  5. Deploy to Kubernetes (3-5 minutes)

    • Updates deployment with new image
    • Rolling update strategy
    • Waits for rollout completion
    • Automatic rollback on failure

Branch Protection Rules

For production deployments, branch protection is configured:

  • βœ… Require pull request reviews (1 reviewer)
  • βœ… Require status checks to pass (all test jobs)
  • βœ… Require branches to be up to date
  • βœ… Require conversation resolution
  • βœ… Enforce for administrators

See BRANCH_PROTECTION_SETUP.md for detailed setup instructions.

GitHub Secrets Required

# Docker Hub credentials
DOCKERHUB_USERNAME=sleepytmzd
DOCKERHUB_TOKEN=<your-token>

# DigitalOcean credentials
DIGITALOCEAN_ACCESS_TOKEN=<your-token>
DO_CLUSTER_NAME=careforall-cluster

πŸ“Έ Demo Screenshots

Infrastructure & Deployment

DigitalOcean Kubernetes Cluster

DigitalOcean Cluster

Cluster Insights & Metrics

DigitalOcean Insights

Kubernetes Deployment Dashboard

Kubernetes Deployment

Docker Compose Local Setup

Docker Compose


Observability & Monitoring

Grafana Monitoring Dashboard

Grafana Monitoring

Jaeger Distributed Tracing

Jaeger Tracing

Loki Log Aggregation

Loki Logging


Event-Driven Architecture

Kafka Topics & Messages

Kafka


CI/CD & DevOps

GitHub Actions CI/CD Pipeline

CI/CD Pipeline


πŸ“š API Documentation

Interactive API Docs

Each service exposes Swagger UI documentation:

Example API Flow

1. Register User

curl -X POST http://localhost:8000/api/users/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "donor@example.com",
    "password": "securepass123",
    "name": "John Doe",
    "role": "DONOR"
  }'

2. Login

curl -X POST http://localhost:8000/api/users/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "donor@example.com",
    "password": "securepass123"
  }'

3. Create Campaign

curl -X POST http://localhost:8000/api/campaigns \
  -H "Authorization: Bearer <JWT_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Help Build School",
    "description": "Building school in rural area",
    "goal_amount": 50000,
    "category": "EDUCATION"
  }'

4. Make Donation

curl -X POST http://localhost:8000/api/donations \
  -H "Authorization: Bearer <JWT_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "campaign_id": 1,
    "amount": 1000,
    "is_anonymous": false
  }'

✨ System Features

High Availability

  • βœ… Health checks for all services
  • βœ… Automatic container restart
  • βœ… Circuit breaking for fault tolerance
  • βœ… Database connection pooling

Security

  • βœ… JWT-based authentication
  • βœ… Role-based authorization
  • βœ… Password hashing (bcrypt)
  • βœ… Rate limiting per user/IP
  • βœ… CORS configuration
  • βœ… SQL injection prevention (ORM)

Performance

  • βœ… Async I/O with FastAPI
  • βœ… Redis caching
  • βœ… Database indexing
  • βœ… Connection pooling
  • βœ… gRPC for internal communication
  • βœ… Kafka for async operations

Observability

  • βœ… Distributed tracing (Jaeger)
  • βœ… Centralized logging (Loki)
  • βœ… Metrics visualization (Grafana)
  • βœ… Correlation IDs
  • βœ… Structured logging
  • βœ… Health check endpoints

Scalability

  • βœ… Microservices architecture
  • βœ… Database per service
  • βœ… Stateless services
  • βœ… Event-driven communication
  • βœ… Horizontal scaling ready
  • βœ… Load balancing support

πŸ”§ Configuration

Environment Variables

Each service can be configured via environment variables in docker-compose.yml:

# Example: User Service
environment:
  DATABASE_URL: postgresql+asyncpg://user:password@postgres-user:5432/userdb
  JWT_SECRET: your-secret-key
  JWT_EXPIRY_HOURS: 24
  JAEGER_ENDPOINT: http://jaeger:14268/api/traces
  TRACING_ENABLED: "true"

Kafka Configuration

Topics are auto-created, but you can pre-create them:

docker exec -it kafka-demo kafka-topics --create \
  --bootstrap-server localhost:9092 \
  --topic donation_created \
  --partitions 3 \
  --replication-factor 1

πŸ“ˆ Monitoring & Troubleshooting

Check Service Health

# All services
curl http://localhost:8000/health

# Individual service
curl http://localhost:8001/health

View Logs

# All services
docker-compose logs -f

# Specific service
docker-compose logs -f user-service

# Last 100 lines
docker-compose logs --tail=100 donation-service

View Traces in Jaeger

  1. Open http://localhost:16686
  2. Select service (e.g., "api-gateway")
  3. Click "Find Traces"
  4. Explore request flows

View Logs in Grafana

  1. Open http://localhost:3000
  2. Import careforall-logs-dashboard.json
  3. Filter by service: {container_name="user-service-demo"}

Monitor Kafka

  1. Open http://localhost:8080
  2. View topics, consumers, and message flow

πŸ§ͺ Testing

Health Check All Services

./scripts/health-check.sh

Run Integration Tests

pytest tests/integration/

Load Testing

# Using Apache Bench
ab -n 1000 -c 10 http://localhost:8000/api/campaigns

# Using Locust
locust -f tests/load/locustfile.py

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘₯ Team FAT32

  • Project Lead: CareForAll Platform Development
  • Hackathon: CUET API Avengers Microservice Hackathon 2025
  • Date: November 21, 2025

πŸ™ Acknowledgments

  • FastAPI community for excellent documentation
  • CUET for organizing the hackathon
  • Open source contributors

πŸ“ž Support

For issues and questions:

  • GitHub Issues: Report Bug
  • Documentation: Check service-specific READMEs
  • Logs: Use Grafana dashboard for debugging

Built with ❀️ by Team FAT32

Making donations transparent and accessible

About

Project that made us champion at CUET-API-AVENGERS-2025

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages