How nafeytauheed-cyber/medigrid works
MediGrid is a city-wide emergency bed reservation and patient-transfer network. Dispatchers submit a patient’s condition, bed type, priority, and location through the API; SmartMatch filters hospitals, Redis proposes a nearby bed and hold, and PostgreSQL commits the authoritative reservation. Hospital staff confirm arrivals and manage admissions, discharges, and transfer sagas. A worker publishes committed outbox events to RabbitMQ consumers; notification deltas and a database watermark feed live SSE updates. Operations surfaces metrics, queue state, cache recovery, and DLQ replay. Some subsystem wiring is documented in the README; unsampled implementation details are not inferred.
Main entry points: app.py HTTP API · transfers.py Transfer saga · ops.js Operations page · dispatch.py Bed search and hold
Components 24
User interfaces
- Web console
app/web/static/common.js - Dispatch page
app/web/static/dispatch.js - Hospital console
app/web/static/hospital.js - Control map
app/web/static/control.js - Operations page
app/web/static/ops.js - HTTP API
app/web/app.py
Care workflows
- Bed search and hold
app/dispatch.py - Capability matching
app/smartmatch.py - Admission lifecycle
app/beds.py - Transfer saga
app/transfers.py
Event processing
- Outbox and timers
app/worker/loops.py - RabbitMQ
- Consumer groups
app/worker/consumers.py
Live views and operations
- SSE updates
app/web/stream.py - Operations API
app/ops.py - Metrics
app/metrics.py - Scenario controls
app/chaos.py
State and infrastructure
- PostgreSQL
- Redis cache
- Cache recovery
app/cache.py - Synthetic network seed
app/seed.py
Other components
- Dispatcher
- Hospital staff
- Operator
Connections 37
- Dispatcher → Dispatch page: uses
- Hospital staff → Hospital console: uses
- Operator → Operations page: uses
- Web console → HTTP API: calls
app/web/app.py - Dispatch page → HTTP API: submits requests
- Hospital console → HTTP API: manages beds
- Control map → HTTP API: loads map
- Operations page → HTTP API: loads operations
- HTTP API → Bed search and hold: routes dispatch
app/web/app.py - HTTP API → Admission lifecycle: routes bed actions
app/web/app.py - HTTP API → Transfer saga: routes transfers
app/web/app.py - Bed search and hold → Capability matching: filters hospitals
app/dispatch.py - Transfer saga → Capability matching: checks capability
app/transfers.py - Bed search and hold → Redis cache: proposes and holds
- Bed search and hold → PostgreSQL: commits reservation
- Admission lifecycle → PostgreSQL: updates state
app/beds.py - Transfer saga → PostgreSQL: commits saga
app/transfers.py - Admission lifecycle → Redis cache: settles cache hold
app/beds.py - Transfer saga → Redis cache: settles cache hold
app/transfers.py - Outbox and timers → PostgreSQL: reads outbox
- Outbox and timers → RabbitMQ: publishes events
- RabbitMQ → Consumer groups: delivers events
- Consumer groups → PostgreSQL: records processing
app/worker/consumers.py - Consumer groups → Transfer saga: handles saga events
app/worker/consumers.py - Consumer groups → Redis cache: publishes UI deltas
- SSE updates → Redis cache: subscribes to deltas
- SSE updates → PostgreSQL: polls watermark
- HTTP API → SSE updates: serves event stream
app/web/app.py - Operations page → Operations API: requests status
- Operations API → Metrics: reads metrics
app/ops.py - Operations API → RabbitMQ: inspects queues
app/ops.py - Operations API → Cache recovery: shows cache state
app/ops.py - Cache recovery → PostgreSQL: fences generations
app/cache.py - Cache recovery → Redis cache: rebuilds generation
app/cache.py - Synthetic network seed → PostgreSQL: seeds hospitals and beds
app/seed.py - Operations page → Scenario controls: starts scenarios
- Scenario controls → HTTP API: exercises dispatch
app/chaos.py