# shanigarapusheshanth2007-wq/hackathon architecture

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

- Interactive diagram: https://gitdiagram.com/shanigarapusheshanth2007-wq/hackathon
- Repository: https://github.com/shanigarapusheshanth2007-wq/hackathon

## Overview

MediGrid coordinates emergency bed reservations and inter-hospital transfers: ambulance requests enter the API, which finds and atomically holds a suitable bed, records patient state and an outbox event, then returns a result to clients. RabbitMQ distributes events to independent tracker, notifier, audit and transfer-saga workers; a sweeper releases expired holds. Redis arbitrates live availability, while Postgres keeps the durable ledger. The README documents the browser map, hospital console and operations dashboard; unsampled UI and worker details are represented at their documented paths, not treated as inspected source.

Main entry points: [`src/api.js`](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js) (REST and WS API), [`src/lib/db.js`](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/db.js) (Postgres ledger), [`src/lib/events.js`](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/events.js) (Outbox and relay), [`src/lib/redis.js`](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/redis.js) (Redis bed state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_clients["Clients and entry"]
  node_browser(("Browser clients<br/>[index.html]"))
  node_simulator["Load simulator<br/>[cli.js]"]
  node_nginx["nginx gateway<br/>[nginx.conf]"]
end

subgraph group_api["API workflows"]
  node_api["REST and WS API<br/>[api.js]"]
  node_dispatch["Bed dispatch<br/>[api.js]"]
  node_transfers["Transfer requests<br/>[api.js]"]
  node_ops["Ops and replay<br/>[api.js]"]
end

subgraph group_events["Event processing"]
  node_events["Outbox and relay<br/>[events.js]"]
  node_broker["RabbitMQ topology<br/>[mq.js]"]
  node_tracker["Occupancy tracker<br/>[workers.js]"]
  node_notifier["Notifications<br/>[workers.js]"]
  node_audit["Audit and dead letters<br/>[workers.js]"]
  node_saga["Transfer saga<br/>[workers.js]"]
  node_sweeper["Hold sweeper<br/>[workers.js]"]
end

subgraph group_state["State and infrastructure"]
  node_seed["Hospital seeding<br/>[seed.js]"]
  node_config["Runtime configuration<br/>[config.js]"]
  node_redis[("Redis bed state<br/>[redis.js]")]
  node_postgres[("Postgres ledger<br/>[db.js]")]
end

subgraph group_live["Live operations"]
  node_metrics["Metrics<br/>[metrics.js]"]
  node_realtime["Realtime fan-out<br/>[rt.js]"]
end

node_browser -->|"REST and WebSocket"| node_nginx
node_nginx -->|"routes requests"| node_api
node_simulator -->|"posts demo requests"| node_api
node_api -->|"handles dispatch"| node_dispatch
node_api -->|"handles transfers"| node_transfers
node_api -->|"serves ops and replay"| node_ops
node_api -->|"reserves and reads beds"| node_redis
node_api -->|"records patient state"| node_postgres
node_api -->|"emits events"| node_events
node_api -->|"seeds and syncs"| node_seed
node_api -->|"records metrics"| node_metrics
node_api -->|"publishes bed updates"| node_realtime
node_dispatch -->|"atomic reservation"| node_redis
node_dispatch -->|"stores patient"| node_postgres
node_dispatch -->|"writes outbox event"| node_events
node_transfers -->|"holds receiver bed"| node_redis
node_transfers -->|"stores transfer"| node_postgres
node_transfers -->|"emits transfer event"| node_events
node_ops -->|"reads dead letters"| node_postgres
node_ops -->|"replays messages"| node_broker
node_seed -->|"seeds hospitals"| node_postgres
node_seed -->|"rebuilds bed state"| node_redis
node_events -->|"writes outbox"| node_postgres
node_events -->|"relays confirmed events"| node_broker
node_broker -->|"delivers events"| node_tracker
node_broker -->|"delivers events"| node_notifier
node_broker -->|"delivers events and DLQ"| node_audit
node_broker -->|"delivers events"| node_saga
node_tracker -->|"updates occupancy"| node_postgres
node_notifier -->|"stores notifications"| node_postgres
node_notifier -->|"publishes notifications"| node_realtime
node_audit -->|"records audit and DLQ"| node_postgres
node_saga -->|"updates transfers"| node_postgres
node_saga -->|"releases source bed"| node_redis
node_saga -->|"emits completion events"| node_events
node_sweeper -->|"releases expired holds"| node_redis
node_sweeper -->|"emits expiry events"| node_events
node_tracker -->|"records processing"| node_metrics
node_api -->|"streams updates to clients"| node_realtime
node_realtime -->|"publishes and subscribes"| node_redis

click node_browser "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/public/index.html"
click node_simulator "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/sim/cli.js"
click node_nginx "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/nginx.conf"
click node_api "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js"
click node_dispatch "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js"
click node_transfers "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js"
click node_ops "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js"
click node_seed "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/seed.js"
click node_config "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/config.js"
click node_redis "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/redis.js"
click node_postgres "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/db.js"
click node_events "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/events.js"
click node_broker "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/mq.js"
click node_tracker "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js"
click node_notifier "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js"
click node_audit "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js"
click node_saga "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js"
click node_sweeper "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js"
click node_metrics "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/metrics.js"
click node_realtime "https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/rt.js"

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_browser,node_simulator,node_nginx toneBlue
class node_api,node_dispatch,node_transfers,node_ops toneAmber
class node_events,node_broker,node_tracker,node_notifier,node_audit,node_saga,node_sweeper toneMint
class node_seed,node_config,node_redis,node_postgres toneRose
class node_metrics,node_realtime toneIndigo
```

## Components

### Clients and entry

- [Browser clients](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/public/index.html): `public/index.html`
- [Load simulator](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/sim/cli.js): `src/sim/cli.js`
- [nginx gateway](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/nginx.conf): `nginx.conf`

### API workflows

- [REST and WS API](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js): `src/api.js`
- [Bed dispatch](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js): `src/api.js`
- [Transfer requests](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js): `src/api.js`
- [Ops and replay](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/api.js): `src/api.js`

### Event processing

- [Outbox and relay](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/events.js): `src/lib/events.js`
- [RabbitMQ topology](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/mq.js): `src/lib/mq.js`
- [Occupancy tracker](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js): `src/workers.js`
- [Notifications](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js): `src/workers.js`
- [Audit and dead letters](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js): `src/workers.js`
- [Transfer saga](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js): `src/workers.js`
- [Hold sweeper](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/workers.js): `src/workers.js`

### State and infrastructure

- [Hospital seeding](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/seed.js): `src/seed.js`
- [Runtime configuration](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/config.js): `src/config.js`
- [Redis bed state](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/redis.js): `src/lib/redis.js`
- [Postgres ledger](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/db.js): `src/lib/db.js`

### Live operations

- [Metrics](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/metrics.js): `src/lib/metrics.js`
- [Realtime fan-out](https://github.com/shanigarapusheshanth2007-wq/hackathon/blob/main/src/lib/rt.js): `src/lib/rt.js`

## Connections

- Browser clients → nginx gateway: REST and WebSocket (evidence: `README.md`)
- nginx gateway → REST and WS API: routes requests (evidence: `README.md`)
- Load simulator → REST and WS API: posts demo requests (evidence: `src/sim/cli.js`)
- REST and WS API → Bed dispatch: handles dispatch (evidence: `src/api.js`)
- REST and WS API → Transfer requests: handles transfers (evidence: `src/api.js`)
- REST and WS API → Ops and replay: serves ops and replay (evidence: `src/api.js`)
- REST and WS API → Redis bed state: reserves and reads beds (evidence: `README.md`)
- REST and WS API → Postgres ledger: records patient state (evidence: `src/api.js`)
- REST and WS API → Outbox and relay: emits events (evidence: `src/api.js`)
- REST and WS API → Hospital seeding: seeds and syncs (evidence: `src/api.js`)
- REST and WS API → Metrics: records metrics (evidence: `src/api.js`)
- REST and WS API → Realtime fan-out: publishes bed updates (evidence: `src/api.js`)
- Bed dispatch → Redis bed state: atomic reservation (evidence: `README.md`)
- Bed dispatch → Postgres ledger: stores patient (evidence: `src/api.js`)
- Bed dispatch → Outbox and relay: writes outbox event (evidence: `src/api.js`)
- Transfer requests → Redis bed state: holds receiver bed (evidence: `README.md`)
- Transfer requests → Postgres ledger: stores transfer (evidence: `src/api.js`)
- Transfer requests → Outbox and relay: emits transfer event (evidence: `src/api.js`)
- Ops and replay → Postgres ledger: reads dead letters (evidence: `src/api.js`)
- Ops and replay → RabbitMQ topology: replays messages (evidence: `src/api.js`)
- Hospital seeding → Postgres ledger: seeds hospitals (evidence: `src/seed.js`)
- Hospital seeding → Redis bed state: rebuilds bed state (evidence: `src/seed.js`)
- Outbox and relay → Postgres ledger: writes outbox (evidence: `src/lib/events.js`)
- Outbox and relay → RabbitMQ topology: relays confirmed events (evidence: `src/lib/events.js`)
- RabbitMQ topology → Occupancy tracker: delivers events (evidence: `README.md`)
- RabbitMQ topology → Notifications: delivers events (evidence: `README.md`)
- RabbitMQ topology → Audit and dead letters: delivers events and DLQ (evidence: `README.md`)
- RabbitMQ topology → Transfer saga: delivers events (evidence: `README.md`)
- Occupancy tracker → Postgres ledger: updates occupancy (evidence: `src/workers.js`)
- Notifications → Postgres ledger: stores notifications (evidence: `src/workers.js`)
- Notifications → Realtime fan-out: publishes notifications (evidence: `src/workers.js`)
- Audit and dead letters → Postgres ledger: records audit and DLQ (evidence: `src/workers.js`)
- Transfer saga → Postgres ledger: updates transfers (evidence: `src/workers.js`)
- Transfer saga → Redis bed state: releases source bed (evidence: `src/workers.js`)
- Transfer saga → Outbox and relay: emits completion events (evidence: `src/workers.js`)
- Hold sweeper → Redis bed state: releases expired holds (evidence: `README.md`)
- Hold sweeper → Outbox and relay: emits expiry events (evidence: `src/workers.js`)
- Occupancy tracker → Metrics: records processing (evidence: `src/workers.js`)
- REST and WS API → Realtime fan-out: streams updates to clients (evidence: `README.md`)
- Realtime fan-out → Redis bed state: publishes and subscribes (evidence: `src/lib/rt.js`)
