# akkshatbhandari/dislog architecture

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

- Interactive diagram: https://gitdiagram.com/akkshatbhandari/dislog
- Repository: https://github.com/akkshatbhandari/dislog

## Overview

DisLog is an event-ingestion and persistence service: a Node.js gateway receives requests, FastAPI accepts events and publishes them to Kafka, and a background consumer validates and batches records into PostgreSQL. The graph also shows event retrieval, offset tracking, bounded work, retries, and dead-letter handling. The worker excerpt is partial, so internal worker relationships are included only where it shows the relevant behavior; the gateway-to-API handoff follows the README, not inspected gateway source.

Main entry points: [`services/ingestion/main.py`](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/main.py) (FastAPI), [`services/ingestion/app/worker.py`](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py) (Stream Consumer), [`services/ingestion/app/database.py`](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/database.py) (Database Sessions), [`services/gateway/src/server.ts`](https://github.com/akkshatbhandari/dislog/blob/main/services/gateway/src/server.ts) (Node Gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingress["Request Ingress"]
  node_gateway["Node Gateway<br/>[server.ts]"]
end

subgraph group_api["Ingestion API"]
  node_fastapi["FastAPI<br/>[main.py]"]
  node_event_schemas["Event Schemas<br/>[schemas.py]"]
  node_producer["Kafka Producer<br/>[kafka.py]"]
  node_event_lookup["Event Retrieval<br/>[main.py]"]
end

subgraph group_stream["Kafka Processing"]
  node_consumer["Stream Consumer<br/>[worker.py]"]
  node_validation["Event Validation<br/>[worker.py]"]
  node_work_queue["Bounded Work Queue<br/>[worker.py]"]
  node_offsets["Offset Tracking<br/>[worker.py]"]
  node_batch_retry["Batch and Retry<br/>[worker.py]"]
  node_dead_letter["Dead Letter Queue<br/>[worker.py]"]
end

subgraph group_storage["Persistence"]
  node_db_access["Database Sessions<br/>[database.py]"]
  node_event_model["Event Model<br/>[models.py]"]
end

node_client(("Event Client"))
node_broker["Kafka Broker"]
node_postgres[("Neon PostgreSQL")]

node_client -->|"sends events"| node_gateway
node_gateway -->|"forwards requests"| node_fastapi
node_fastapi -->|"validates with"| node_event_schemas
node_fastapi -->|"publishes events"| node_producer
node_producer -->|"sends events"| node_broker
node_broker -.->|"delivers records"| node_consumer
node_consumer -->|"validates records"| node_validation
node_consumer -->|"enqueues records"| node_work_queue
node_consumer -->|"registers offsets"| node_offsets
node_consumer -->|"sends failures"| node_dead_letter
node_work_queue -->|"dispatches batches"| node_batch_retry
node_batch_retry -->|"persists events"| node_db_access
node_batch_retry -->|"inserts records"| node_event_model
node_db_access -->|"opens sessions"| node_postgres
node_event_model -.->|"maps event rows"| node_postgres
node_fastapi -->|"queries events"| node_db_access
node_fastapi -->|"routes retrieval"| node_event_lookup
node_event_lookup -->|"reads event"| node_postgres

click node_gateway "https://github.com/akkshatbhandari/dislog/blob/main/services/gateway/src/server.ts"
click node_fastapi "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/main.py"
click node_event_schemas "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/schemas.py"
click node_producer "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/kafka.py"
click node_consumer "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py"
click node_validation "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py"
click node_work_queue "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py"
click node_offsets "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py"
click node_batch_retry "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py"
click node_dead_letter "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py"
click node_db_access "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/database.py"
click node_event_model "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/models.py"
click node_event_lookup "https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/main.py"

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_gateway,node_client toneBlue
class node_fastapi,node_event_schemas,node_producer,node_event_lookup,node_postgres toneAmber
class node_consumer,node_validation,node_work_queue,node_offsets,node_batch_retry,node_dead_letter toneMint
class node_db_access,node_event_model toneRose
class node_broker toneIndigo
```

## Components

### Request Ingress

- [Node Gateway](https://github.com/akkshatbhandari/dislog/blob/main/services/gateway/src/server.ts): `services/gateway/src/server.ts`

### Ingestion API

- [FastAPI](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/main.py): `services/ingestion/main.py`
- [Event Schemas](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/schemas.py): `services/ingestion/app/schemas.py`
- [Kafka Producer](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/kafka.py): `services/ingestion/app/kafka.py`
- [Event Retrieval](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/main.py): `services/ingestion/main.py`

### Kafka Processing

- [Stream Consumer](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py): `services/ingestion/app/worker.py`
- [Event Validation](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py): `services/ingestion/app/worker.py`
- [Bounded Work Queue](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py): `services/ingestion/app/worker.py`
- [Offset Tracking](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py): `services/ingestion/app/worker.py`
- [Batch and Retry](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py): `services/ingestion/app/worker.py`
- [Dead Letter Queue](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/worker.py): `services/ingestion/app/worker.py`

### Persistence

- [Database Sessions](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/database.py): `services/ingestion/app/database.py`
- [Event Model](https://github.com/akkshatbhandari/dislog/blob/main/services/ingestion/app/models.py): `services/ingestion/app/models.py`

### Other components

- **Event Client**
- **Kafka Broker**
- **Neon PostgreSQL**

## Connections

- Event Client → Node Gateway: sends events (evidence: `README.md`)
- Node Gateway → FastAPI: forwards requests (evidence: `README.md`)
- FastAPI → Event Schemas: validates with (evidence: `services/ingestion/main.py`)
- FastAPI → Kafka Producer: publishes events (evidence: `services/ingestion/main.py`)
- Kafka Producer → Kafka Broker: sends events (evidence: `services/ingestion/app/kafka.py`)
- Kafka Broker → Stream Consumer: delivers records
- Stream Consumer → Event Validation: validates records (evidence: `services/ingestion/app/worker.py`)
- Stream Consumer → Bounded Work Queue: enqueues records (evidence: `services/ingestion/app/worker.py`)
- Stream Consumer → Offset Tracking: registers offsets (evidence: `services/ingestion/app/worker.py`)
- Stream Consumer → Dead Letter Queue: sends failures (evidence: `services/ingestion/app/worker.py`)
- Bounded Work Queue → Batch and Retry: dispatches batches (evidence: `services/ingestion/app/worker.py`)
- Batch and Retry → Database Sessions: persists events (evidence: `services/ingestion/app/worker.py`)
- Batch and Retry → Event Model: inserts records (evidence: `services/ingestion/app/worker.py`)
- Database Sessions → Neon PostgreSQL: opens sessions (evidence: `services/ingestion/app/database.py`)
- Event Model → Neon PostgreSQL: maps event rows
- FastAPI → Database Sessions: queries events (evidence: `services/ingestion/main.py`)
- FastAPI → Event Retrieval: routes retrieval (evidence: `services/ingestion/main.py`)
- Event Retrieval → Neon PostgreSQL: reads event (evidence: `services/ingestion/main.py`)
