# kumar306/market-tick-aggregator architecture

> Architecture diagram of the GitHub repository kumar306/market-tick-aggregator, 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/kumar306/market-tick-aggregator
- Repository: https://github.com/kumar306/market-tick-aggregator

## Overview

Market Tick Aggregator is a real-time market-data platform. Exchange feeds enter through the adapter, pass through normalization into separate metrics and order-book processing, then flow to durable storage and a live dashboard. The graph preserves the README’s REST-history and WebSocket-live paths. Relationships are drawn from README statements and the shown entry points; unsampled service internals are represented by their listed runtime paths, without inferring calls between sibling helpers.

Main entry points: [`orderbook/worker/worker.go`](https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/worker/worker.go) (Order-book workers), [`aggregator/worker/worker.go`](https://github.com/kumar306/market-tick-aggregator/blob/master/aggregator/worker/worker.go) (Metric workers), [`ui-backend/main.go`](https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/main.go) (UI backend), [`ui/src/app/page.tsx`](https://github.com/kumar306/market-tick-aggregator/blob/master/ui/src/app/page.tsx) (Next.js dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Feed ingestion"]
  node_adapter["Feed adapter<br/>[main.go]"]
  node_raw["Raw Kafka topics"]
end

subgraph group_processing["Stream processing"]
  node_normalizer["Normalizer workers<br/>[worker.go]"]
  node_normalized["Normalized topics"]
  node_resync["Depth resync<br/>[adapter_signal.go]"]
  node_aggregator["Metric workers<br/>[worker.go]"]
  node_metric_registry["Metric registry<br/>[metric_registry.go]"]
  node_flush_scheduler["Metric flush scheduler<br/>[scheduler.go]"]
  node_orderbook["Order-book workers<br/>[worker.go]"]
  node_book_dispatch["Book dispatcher<br/>[dispatcher.go]"]
  node_book_scheduler["Book flush scheduler<br/>[scheduler.go]"]
  node_redis[("Redis state<br/>[redis.go]")]
end

subgraph group_storage["Persistence"]
  node_aggregated["Aggregated topics"]
  node_flushed_books["Flushed-book topics"]
  node_persistence_consumer["Persistence consumer<br/>[consumer.go]"]
  node_pipeline["Conversion and batching<br/>[pipeline.go]"]
  node_postgres[("Postgres")]
end

subgraph group_serving["Dashboard serving"]
  node_backend["UI backend<br/>[main.go]"]
  node_rest["Historical REST API"]
  node_repository["Market repository"]
  node_live_consumer["Live Kafka stream<br/>[kafka_consumer.go]"]
  node_stream_manager["WebSocket fanout<br/>[stream_manager.go]"]
  node_dashboard["Next.js dashboard<br/>[page.tsx]"]
end

subgraph group_shared["Shared runtime"]
  node_ingest_timestamp["Ingest timestamp<br/>[ingestts.go]"]
end

node_exchanges(("Exchange feeds"))
node_viewer(("Dashboard user"))

node_exchanges -->|"send feeds"| node_adapter
node_adapter -->|"publish events"| node_raw
node_raw -->|"consume events"| node_normalizer
node_normalizer -->|"publish schemas"| node_normalized
node_normalized -->|"consume ticks"| node_aggregator
node_normalized -->|"consume books"| node_orderbook
node_normalizer -->|"request resync"| node_resync
node_aggregator -->|"update metrics"| node_metric_registry
node_aggregator -->|"schedule windows"| node_flush_scheduler
node_aggregator -->|"publish aggregates"| node_aggregated
node_orderbook -->|"dispatch records"| node_book_dispatch
node_orderbook -->|"schedule flushes"| node_book_scheduler
node_orderbook -->|"use state"| node_redis
node_orderbook -->|"publish snapshots"| node_flushed_books
node_aggregated -->|"consume ticks"| node_persistence_consumer
node_flushed_books -->|"consume books"| node_persistence_consumer
node_persistence_consumer -->|"process records"| node_pipeline
node_pipeline -->|"batch writes"| node_postgres
node_viewer -->|"inspect markets"| node_dashboard
node_dashboard -->|"request history"| node_backend
node_backend -->|"route REST"| node_rest
node_rest -->|"query history"| node_repository
node_repository -->|"read history"| node_postgres
node_dashboard -->|"open WebSocket"| node_backend
node_backend -->|"start consumer"| node_live_consumer
node_live_consumer -->|"read live updates"| node_aggregated
node_live_consumer -->|"broadcast updates"| node_stream_manager
node_stream_manager -->|"fan out updates"| node_dashboard

click node_adapter "https://github.com/kumar306/market-tick-aggregator/blob/master/adapter/main.go"
click node_normalizer "https://github.com/kumar306/market-tick-aggregator/blob/master/normalizer/worker/worker.go"
click node_resync "https://github.com/kumar306/market-tick-aggregator/blob/master/normalizer/resync/adapter_signal.go"
click node_aggregator "https://github.com/kumar306/market-tick-aggregator/blob/master/aggregator/worker/worker.go"
click node_metric_registry "https://github.com/kumar306/market-tick-aggregator/blob/master/aggregator/internal/metric_registry.go"
click node_flush_scheduler "https://github.com/kumar306/market-tick-aggregator/blob/master/aggregator/flush/scheduler.go"
click node_orderbook "https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/worker/worker.go"
click node_book_dispatch "https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/dispatcher/dispatcher.go"
click node_book_scheduler "https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/flush/scheduler.go"
click node_redis "https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/redis/redis.go"
click node_persistence_consumer "https://github.com/kumar306/market-tick-aggregator/blob/master/persistence/kafka/consumer.go"
click node_pipeline "https://github.com/kumar306/market-tick-aggregator/blob/master/persistence/pipeline/pipeline.go"
click node_backend "https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/main.go"
click node_rest "https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/controller/market_controller.go"
click node_repository "https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/repository/market_repository.go"
click node_live_consumer "https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/stream/kafka_consumer.go"
click node_stream_manager "https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/stream/stream_manager.go"
click node_dashboard "https://github.com/kumar306/market-tick-aggregator/blob/master/ui/src/app/page.tsx"
click node_ingest_timestamp "https://github.com/kumar306/market-tick-aggregator/blob/master/shared/ingestts/ingestts.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_adapter,node_raw,node_viewer toneBlue
class node_normalizer,node_normalized,node_resync,node_aggregator,node_metric_registry,node_flush_scheduler,node_orderbook,node_book_dispatch,node_book_scheduler,node_redis toneAmber
class node_aggregated,node_flushed_books,node_persistence_consumer,node_pipeline,node_postgres toneMint
class node_backend,node_rest,node_repository,node_live_consumer,node_stream_manager,node_dashboard toneRose
class node_ingest_timestamp,node_exchanges toneIndigo
```

## Components

### Feed ingestion

- [Feed adapter](https://github.com/kumar306/market-tick-aggregator/blob/master/adapter/main.go): `adapter/main.go`
- **Raw Kafka topics**

### Stream processing

- [Normalizer workers](https://github.com/kumar306/market-tick-aggregator/blob/master/normalizer/worker/worker.go): `normalizer/worker/worker.go`
- **Normalized topics**
- [Depth resync](https://github.com/kumar306/market-tick-aggregator/blob/master/normalizer/resync/adapter_signal.go): `normalizer/resync/adapter_signal.go`
- [Metric workers](https://github.com/kumar306/market-tick-aggregator/blob/master/aggregator/worker/worker.go): `aggregator/worker/worker.go`
- [Metric registry](https://github.com/kumar306/market-tick-aggregator/blob/master/aggregator/internal/metric_registry.go): `aggregator/internal/metric_registry.go`
- [Metric flush scheduler](https://github.com/kumar306/market-tick-aggregator/blob/master/aggregator/flush/scheduler.go): `aggregator/flush/scheduler.go`
- [Order-book workers](https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/worker/worker.go): `orderbook/worker/worker.go`
- [Book dispatcher](https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/dispatcher/dispatcher.go): `orderbook/dispatcher/dispatcher.go`
- [Book flush scheduler](https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/flush/scheduler.go): `orderbook/flush/scheduler.go`
- [Redis state](https://github.com/kumar306/market-tick-aggregator/blob/master/orderbook/redis/redis.go): `orderbook/redis/redis.go`

### Persistence

- **Aggregated topics**
- **Flushed-book topics**
- [Persistence consumer](https://github.com/kumar306/market-tick-aggregator/blob/master/persistence/kafka/consumer.go): `persistence/kafka/consumer.go`
- [Conversion and batching](https://github.com/kumar306/market-tick-aggregator/blob/master/persistence/pipeline/pipeline.go): `persistence/pipeline/pipeline.go`
- **Postgres**

### Dashboard serving

- [UI backend](https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/main.go): `ui-backend/main.go`
- [Historical REST API](https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/controller/market_controller.go): `ui-backend/controller/market_controller.go`
- [Market repository](https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/repository/market_repository.go): `ui-backend/repository/market_repository.go`
- [Live Kafka stream](https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/stream/kafka_consumer.go): `ui-backend/stream/kafka_consumer.go`
- [WebSocket fanout](https://github.com/kumar306/market-tick-aggregator/blob/master/ui-backend/stream/stream_manager.go): `ui-backend/stream/stream_manager.go`
- [Next.js dashboard](https://github.com/kumar306/market-tick-aggregator/blob/master/ui/src/app/page.tsx): `ui/src/app/page.tsx`

### Shared runtime

- [Ingest timestamp](https://github.com/kumar306/market-tick-aggregator/blob/master/shared/ingestts/ingestts.go): `shared/ingestts/ingestts.go`

### Other components

- **Exchange feeds**
- **Dashboard user**

## Connections

- Exchange feeds → Feed adapter: send feeds
- Feed adapter → Raw Kafka topics: publish events
- Raw Kafka topics → Normalizer workers: consume events
- Normalizer workers → Normalized topics: publish schemas
- Normalized topics → Metric workers: consume ticks
- Normalized topics → Order-book workers: consume books
- Normalizer workers → Depth resync: request resync
- Metric workers → Metric registry: update metrics
- Metric workers → Metric flush scheduler: schedule windows
- Metric workers → Aggregated topics: publish aggregates
- Order-book workers → Book dispatcher: dispatch records
- Order-book workers → Book flush scheduler: schedule flushes
- Order-book workers → Redis state: use state
- Order-book workers → Flushed-book topics: publish snapshots
- Aggregated topics → Persistence consumer: consume ticks
- Flushed-book topics → Persistence consumer: consume books
- Persistence consumer → Conversion and batching: process records
- Conversion and batching → Postgres: batch writes
- Dashboard user → Next.js dashboard: inspect markets
- Next.js dashboard → UI backend: request history
- UI backend → Historical REST API: route REST (evidence: `ui-backend/main.go`)
- Historical REST API → Market repository: query history (evidence: `ui-backend/controller/market_controller.go`)
- Market repository → Postgres: read history
- Next.js dashboard → UI backend: open WebSocket
- UI backend → Live Kafka stream: start consumer (evidence: `ui-backend/main.go`)
- Live Kafka stream → Aggregated topics: read live updates
- Live Kafka stream → WebSocket fanout: broadcast updates (evidence: `ui-backend/stream/stream_manager.go`)
- WebSocket fanout → Next.js dashboard: fan out updates
