Monday, July 7, 2025

๐Ÿšข Dockerizing Fraud-Free Swarajya: Building Forts for Modern-Day Defense

“Code that works is good. Code that runs anywhere is great. Code that stands strong like a fort — that's legendary.”
Inspired by Chhatrapati Shivaji Maharaj’s empire-building wisdom.

๐Ÿงญ Quick Recap

In our open-source journey toward a fraud detection system inspired by the Swarajya movement, we’ve already built:

  • ๐Ÿ›ก️ sindhudurg: Fraud Scoring API (Spring Boot)
  • ๐Ÿง  tanaji: AI Engine (FastAPI + Python)
  • ๐Ÿ“œ dadoji: Rules Engine
  • jiva: Redis-based caching
  • ๐Ÿฆ ramchandrapant: PostgreSQL for transaction storage
  • ๐Ÿ“Š kanhoji: Prometheus + Grafana Monitoring

Now it’s time to bring these warriors together in formation — reliably, portably, and scalably.


๐Ÿฐ Inspired by Shivaji Maharaj’s Fort Strategy

Shivaji Maharaj built over 300 forts — not to dominate land, but to secure Swarajya.
Every fort was:
- Modular
- Self-sufficient
- Strategically connected but independently operational

That’s exactly what Docker does for us today in software.

⚔️ Shivaji’s Forts = Our Containers

Forts of Swarajya Docker Microservices
Had their own food, water Contain dependencies & config
Stood independently Isolated service containers
Could signal one another Docker networking
Decentralized command Compose-managed services
Fortified walls Runtime boundary & security
Moved troops via sea/land Image portability across environments

๐Ÿง  Each microservice is a Fort. Docker is our General. Compose is our battle plan.


๐Ÿ›  Why Docker?

  • Before Docker: Manually ran services, installed dependencies, dealt with port conflicts
  • Now: 1 command spins up the entire system reliably across machines

๐Ÿงฉ What We’re Running in Docker

Container NameModule
sindhudurg-appSpring Boot REST API
tanaji-apiFastAPI AI Service
ramchandrapantPostgreSQL DB
jivaRedis Cache
kanhoji-prometheusPrometheus Monitoring
kanhoji-grafanaGrafana Dashboard

๐Ÿ“‚ docker-compose.yml (Snippet)

services:
  sindhudurg-app:
    build: ./sindhudurg
    ports:
      - "8080:8080"
    depends_on:
      - tanaji-api
      - redis
      - postgres-db

  tanaji-api:
    build: ./tanaji
    ports:
      - "8000:8000"

  redis:
    image: redis:7

  postgres-db:
    image: postgres:15
    environment:
      POSTGRES_DB: transactions_db
      POSTGRES_USER: txn_db_user
      POSTGRES_PASSWORD: transactions_secret

๐Ÿš€ Run the System

docker compose up --build

This command:

  • Starts all services
  • Builds Docker images
  • Connects networks internally


๐Ÿ” Test a Transaction

curl -X POST http://localhost:8080/api/v1/fraud-score \
  -H "Content-Type: application/json" \
  -d '{
    "transactionId": "txn001",
    "userId": "user123",
    "amount": 5000,
    "currency": "INR",
    "paymentMethod": "risky",
    "cardNumberLast4": "1234",
    "transactionTime": "2025-04-22T14:30:00Z",
    "location": "risky",
    "deviceId": "d1234",
    "ipAddress": "192.168.1.10",
    "merchantId": "m123"
  }'

๐Ÿ“Š Monitoring in Action

  • Prometheus: http://localhost:9090
  • Grafana: http://localhost:3000 (Login: admin/admin)

๐Ÿ› Troubleshooting Log

ProblemFix
Port ConflictsMapped to different host ports
Redis not visibleSkipped advanced metrics for MVP
Connection refusedUsed service names, not localhost
Postgres driver errorAdded missing dependency
Grafana not showing dataFixed Prometheus targets

๐ŸŽฏ What I Learned

  • Docker = Forts for Software
  • Each service = A garrison of Swarajya
  • Shivaji Maharaj didn’t wait for chaos — he built resilience.

๐Ÿ“Œ GitHub

https://github.com/pcm1984/fraud-free-swarajya


๐Ÿ›ค What’s Next?

  • ๐Ÿ“ฌ Notification Service (SMS, Email)
  • ๐Ÿ” Santaji – Feedback Learning Loop
  • ๐Ÿงช Integration Testing + Observability

๐Ÿ™ Final Thought

“If Shivaji Maharaj could build forts that confused and defeated the mightiest empires…
...surely we can build software systems that don't fall apart on deploy.” ๐Ÿ‡ฎ๐Ÿ‡ณ

No comments:

Post a Comment