# nammayatri/shudhi architecture

> Architecture diagram of the GitHub repository nammayatri/shudhi, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nammayatri/shudhi
- Repository: https://github.com/nammayatri/shudhi

## Overview

Shudhi is a Go sidecar for discovering, inspecting, and invalidating in-memory cache entries across service pods. The main workflow is: a sidecar identifies its app and registers in Redis; an operator uses the dashboard to browse registered keys and request a value or fleet-wide clear; sidecars route reads to a target pod and deliver clears to each pod, which calls its local app. Redis provides discovery, request/response messaging, key metadata, and a durable per-service refresh log. Dashboard internals and some HTTP handlers are unsampled, so those links rely on README statements.

Main entry points: [`dashboard/nginx.conf`](https://github.com/nammayatri/shudhi/blob/main/dashboard/nginx.conf) (Dashboard proxy), [`handlers.go`](https://github.com/nammayatri/shudhi/blob/main/handlers.go) (Key browsing), [`main.go`](https://github.com/nammayatri/shudhi/blob/main/main.go) (HTTP server), [`pubsub.go`](https://github.com/nammayatri/shudhi/blob/main/pubsub.go) (Pod request relay)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dashboard["Dashboard"]
  node_dashboard_ui["Cache dashboard<br/>[index.html]"]
  node_dashboard_proxy["Dashboard proxy<br/>[nginx.conf]"]
end

subgraph group_api["Sidecar API"]
  node_api_services["Service discovery<br/>[handlers.go]"]
  node_api_pods["Pod discovery<br/>[handlers.go]"]
  node_api_keys["Key browsing<br/>[handlers.go]"]
  node_key_registry["Key registration<br/>[handlers.go]"]
  node_api_get["Value inspection<br/>[handlers.go]"]
  node_api_refresh["Clear orchestration<br/>[handlers.go]"]
end

subgraph group_coordination["Coordination"]
  node_redis[("Redis coordination")]
  node_pubsub["Pod request relay<br/>[pubsub.go]"]
  node_refresh_log["Durable clear log<br/>[pubsub.go]"]
  node_local_clear["Local clear worker<br/>[pubsub.go]"]
end

subgraph group_runtime["Sidecar runtime"]
  node_entrypoint["HTTP server<br/>[main.go]"]
  node_config["Configuration<br/>[config.go]"]
  node_lifecycle["App connection<br/>[config.go]"]
  node_registration["Pod registration<br/>[lifecycle.go]"]
end

node_operator(("Operator"))
node_app["Service apps"]
node_peer_sidecars["Peer sidecars"]

node_operator -->|"uses"| node_dashboard_ui
node_dashboard_ui -->|"sends requests"| node_dashboard_proxy
node_dashboard_proxy -->|"proxies API"| node_api_services
node_dashboard_proxy -->|"proxies API"| node_api_pods
node_dashboard_proxy -->|"proxies API"| node_api_keys
node_dashboard_proxy -->|"proxies API"| node_api_get
node_dashboard_proxy -->|"proxies API"| node_api_refresh
node_entrypoint -->|"loads"| node_config
node_entrypoint -->|"starts connection"| node_lifecycle
node_entrypoint -->|"serves routes"| node_api_services
node_lifecycle -->|"fetches identity"| node_app
node_lifecycle -->|"registers pod"| node_registration
node_registration -->|"writes presence"| node_redis
node_api_services -->|"scans registry"| node_redis
node_api_pods -->|"reads pod records"| node_redis
node_key_registry -->|"stores key metadata"| node_redis
node_api_keys -->|"aggregates keys"| node_redis
node_api_keys -->|"proxies pod query"| node_peer_sidecars
node_api_keys -->|"queries local keys"| node_app
node_api_get -->|"routes pod read"| node_peer_sidecars
node_peer_sidecars -.->|"relays if needed"| node_pubsub
node_pubsub -->|"publishes requests"| node_redis
node_pubsub -->|"requests cached value"| node_app
node_api_refresh -->|"appends clear"| node_refresh_log
node_api_refresh -->|"broadcasts clear"| node_peer_sidecars
node_refresh_log -->|"stores stream and cursors"| node_redis
node_local_clear -->|"reads per-pod entries"| node_refresh_log
node_local_clear -->|"calls refresh endpoint"| node_app
node_api_refresh -->|"updates key registry"| node_redis

click node_dashboard_ui "https://github.com/nammayatri/shudhi/blob/main/dashboard/index.html"
click node_dashboard_proxy "https://github.com/nammayatri/shudhi/blob/main/dashboard/nginx.conf"
click node_entrypoint "https://github.com/nammayatri/shudhi/blob/main/main.go"
click node_config "https://github.com/nammayatri/shudhi/blob/main/config.go"
click node_lifecycle "https://github.com/nammayatri/shudhi/blob/main/config.go"
click node_registration "https://github.com/nammayatri/shudhi/blob/main/lifecycle.go"
click node_api_services "https://github.com/nammayatri/shudhi/blob/main/handlers.go"
click node_api_pods "https://github.com/nammayatri/shudhi/blob/main/handlers.go"
click node_api_keys "https://github.com/nammayatri/shudhi/blob/main/handlers.go"
click node_key_registry "https://github.com/nammayatri/shudhi/blob/main/handlers.go"
click node_api_get "https://github.com/nammayatri/shudhi/blob/main/handlers.go"
click node_api_refresh "https://github.com/nammayatri/shudhi/blob/main/handlers.go"
click node_pubsub "https://github.com/nammayatri/shudhi/blob/main/pubsub.go"
click node_refresh_log "https://github.com/nammayatri/shudhi/blob/main/pubsub.go"
click node_local_clear "https://github.com/nammayatri/shudhi/blob/main/pubsub.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_dashboard_ui,node_dashboard_proxy toneBlue
class node_api_services,node_api_pods,node_api_keys,node_key_registry,node_api_get,node_api_refresh toneAmber
class node_redis,node_pubsub,node_refresh_log,node_local_clear toneMint
class node_entrypoint,node_config,node_lifecycle,node_registration toneRose
class node_operator,node_app,node_peer_sidecars toneIndigo
```

## Components

### Dashboard

- [Cache dashboard](https://github.com/nammayatri/shudhi/blob/main/dashboard/index.html): `dashboard/index.html`
- [Dashboard proxy](https://github.com/nammayatri/shudhi/blob/main/dashboard/nginx.conf): `dashboard/nginx.conf`

### Sidecar API

- [Service discovery](https://github.com/nammayatri/shudhi/blob/main/handlers.go): `handlers.go`
- [Pod discovery](https://github.com/nammayatri/shudhi/blob/main/handlers.go): `handlers.go`
- [Key browsing](https://github.com/nammayatri/shudhi/blob/main/handlers.go): `handlers.go`
- [Key registration](https://github.com/nammayatri/shudhi/blob/main/handlers.go): `handlers.go`
- [Value inspection](https://github.com/nammayatri/shudhi/blob/main/handlers.go): `handlers.go`
- [Clear orchestration](https://github.com/nammayatri/shudhi/blob/main/handlers.go): `handlers.go`

### Coordination

- **Redis coordination**
- [Pod request relay](https://github.com/nammayatri/shudhi/blob/main/pubsub.go): `pubsub.go`
- [Durable clear log](https://github.com/nammayatri/shudhi/blob/main/pubsub.go): `pubsub.go`
- [Local clear worker](https://github.com/nammayatri/shudhi/blob/main/pubsub.go): `pubsub.go`

### Sidecar runtime

- [HTTP server](https://github.com/nammayatri/shudhi/blob/main/main.go): `main.go`
- [Configuration](https://github.com/nammayatri/shudhi/blob/main/config.go): `config.go`
- [App connection](https://github.com/nammayatri/shudhi/blob/main/config.go): `config.go`
- [Pod registration](https://github.com/nammayatri/shudhi/blob/main/lifecycle.go): `lifecycle.go`

### Other components

- **Operator**
- **Service apps**
- **Peer sidecars**

## Connections

- Operator → Cache dashboard: uses (evidence: `README.md`)
- Cache dashboard → Dashboard proxy: sends requests (evidence: `README.md`)
- Dashboard proxy → Service discovery: proxies API (evidence: `README.md`)
- Dashboard proxy → Pod discovery: proxies API (evidence: `README.md`)
- Dashboard proxy → Key browsing: proxies API (evidence: `README.md`)
- Dashboard proxy → Value inspection: proxies API (evidence: `README.md`)
- Dashboard proxy → Clear orchestration: proxies API (evidence: `README.md`)
- HTTP server → Configuration: loads (evidence: `main.go`)
- HTTP server → App connection: starts connection (evidence: `main.go`)
- HTTP server → Service discovery: serves routes (evidence: `main.go`)
- App connection → Service apps: fetches identity (evidence: `config.go`)
- App connection → Pod registration: registers pod (evidence: `config.go`)
- Pod registration → Redis coordination: writes presence (evidence: `lifecycle.go`)
- Service discovery → Redis coordination: scans registry (evidence: `handlers.go`)
- Pod discovery → Redis coordination: reads pod records (evidence: `handlers.go`)
- Key registration → Redis coordination: stores key metadata (evidence: `handlers.go`)
- Key browsing → Redis coordination: aggregates keys (evidence: `handlers.go`)
- Key browsing → Peer sidecars: proxies pod query (evidence: `handlers.go`)
- Key browsing → Service apps: queries local keys (evidence: `handlers.go`)
- Value inspection → Peer sidecars: routes pod read (evidence: `handlers.go`)
- Peer sidecars → Pod request relay: relays if needed (evidence: `README.md`)
- Pod request relay → Redis coordination: publishes requests (evidence: `pubsub.go`)
- Pod request relay → Service apps: requests cached value (evidence: `pubsub.go`)
- Clear orchestration → Durable clear log: appends clear (evidence: `README.md`)
- Clear orchestration → Peer sidecars: broadcasts clear (evidence: `README.md`)
- Durable clear log → Redis coordination: stores stream and cursors (evidence: `pubsub.go`)
- Local clear worker → Durable clear log: reads per-pod entries (evidence: `pubsub.go`)
- Local clear worker → Service apps: calls refresh endpoint (evidence: `pubsub.go`)
- Clear orchestration → Redis coordination: updates key registry (evidence: `handlers.go`)
