# pratikscfr/coldum architecture

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

- Interactive diagram: https://gitdiagram.com/pratikscfr/coldum
- Repository: https://github.com/pratikscfr/coldum

## Overview

1. **Overall shape**
   - Coldum is a **Python 3.12, HTTP-based Kafka-inspired log system**. The runtime is a single broker process exposed through a versioned REST API under `/v1`, with a client SDK calling that API directly rather than using a Kafka wire protocol.

2. **Broker entrypoint and API surface**
   - `src/coldum/broker/app.py` is the main broker application.
   - The broker is split into route modules by concern: `topics`, `produce`, `fetch`, `groups`, `cluster`, `health`, `metrics`, and `internal`.
   - This makes the API layer the top boundary: request/response schemas live alongside each router, while shared types sit in `broker/schemas.py` and `broker/common.py`.

3. **Topic and partition storage**
   - The core persistence layer is in `src/coldum/storage/`.
   - `topic_store.py` manages topic-level metadata and partition layout, while `partition_log.py` and `record.py` handle the append-only log and individual record encoding.
   - Architecturally, this is the durable “data plane” for produced messages and fetched offsets.

4. **Produce and fetch flow**
   - `POST /v1/produce` appends records into the partition log for a chosen topic/partition.
   - `POST /v1/fetch` reads from partition logs using logical offsets and supports streaming-style consumption semantics, including long polling as covered by the tests.
   - This is the main read/write path through the system: producer writes to storage, consumer fetches from storage.

5. **Consumer group coordination**
   - `src/coldum/broker/groups/` implements group membership, subscription, heartbeat, commit, assignment, and lag endpoints.
   - The coordination flow is: consumers subscribe, send heartbeats to stay active, receive partition assignments, and commit offsets back to the broker.
   - `metadata/group_assignor.py` is the likely placement for assignment logic that maps partitions to members.

6. **Metadata and cluster state**
   - `src/coldum/metadata/` holds persistent coordination state and cluster metadata.
   - `sqlite_store.py` indicates **SQLite-backed metadata persistence**, so the broker keeps cluster/group state locally without an external coordination service.
   - `cluster.py` and the broker’s `/v1/cluster/metadata` endpoint suggest a cluster view is exposed for node/leader awareness, even though the repo currently documents single-broker operation.

7. **Broker service boundaries**
   - `src/coldum/broker/services.py` and `workers.py` likely provide the orchestration layer between HTTP handlers, storage, and metadata.
   - This is the internal service boundary where cross-cutting broker logic lives: validating requests, coordinating storage writes, updating offsets, and running background work.

8. **Client SDK**
   - `src/coldum/client/` contains both sync and async producer/consumer wrappers.
   - The async consumer exposes a streaming API that fetches assigned partitions concurrently and keeps membership alive with a background heartbeat task.
   - This SDK is part of the architecture because it defines the intended client interaction pattern with the broker’s HTTP endpoints.

9. **Operational endpoints**
   - `health` and `metrics` are separate broker subsystems, indicating explicit operational observability.
   - `internal` suggests non-public admin or implementation endpoints that are separated from the public topic/produce/fetch/group API.

10. **Reliability and semantics**
   - The README states **at-least-once delivery**, **int64 logical offsets**, and **7-day default retention**.
   - These guarantees are enforced by the storage/offset/commit model rather than by an external streaming platform.
   - The architecture should therefore show commits and offsets as first-class coordination data, not just message metadata.

11. **Deployment and local persistence**
   - The repo supports local containerized execution via Docker/devcontainer and uses `COLDUM_DATA_DIR` for broker data, which means the broker persists state to a local filesystem-backed data directory.
   - `docker-compose.yml`, `Dockerfile`, and `.devcontainer/` support reproducible local and test environments, but they do not change the core runtime architecture.

12. **Validation and resilience tooling**
   - `tests/integration/` covers end-to-end broker behavior, consumer groups, lag, and long polling; `tests/unit/` covers lower-level storage and codec logic.
   - `scripts/fault_inject.py` and `scripts/load_test.py` indicate the architecture is exercised for resilience and throughput, which is important when diagramming the system’s operational boundaries.

Main entry points: [`src/coldum/broker/app.py`](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/app.py) (Broker app), [`src/coldum/broker/services.py`](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/services.py) (Services), [`src/coldum/broker/groups/router.py`](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/groups/router.py) (Groups), [`src/coldum/metadata/sqlite_store.py`](https://github.com/pratikscfr/coldum/blob/main/src/coldum/metadata/sqlite_store.py) (SQLite store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_broker["Broker API"]
  node_broker_app["Broker app<br/>entrypoint<br/>[app.py]"]
  node_broker_services["Services<br/>orchestration<br/>[services.py]"]
  node_broker_workers["Workers<br/>background jobs<br/>[workers.py]"]
  node_topics_router["Topics<br/>router<br/>[router.py]"]
  node_produce_router["Produce<br/>router<br/>[router.py]"]
  node_fetch_router["Fetch<br/>router<br/>[router.py]"]
  node_groups_router["Groups<br/>router<br/>[router.py]"]
  node_cluster_router["Cluster<br/>router<br/>[router.py]"]
end

subgraph group_storage["Storage"]
  node_topic_store[("Topic store<br/>storage index<br/>[topic_store.py]")]
  node_partition_log[("Partition log<br/>append-only log<br/>[partition_log.py]")]
  node_record_codec["Record codec<br/>encoding<br/>[record.py]"]
end

subgraph group_metadata["Metadata"]
  node_sqlite_store[("SQLite store<br/>metadata store<br/>[sqlite_store.py]")]
  node_group_assignor{{"Assignor<br/>assignment<br/>[group_assignor.py]"}}
  node_cluster_state["Cluster state<br/>metadata model<br/>[cluster.py]"]
end

subgraph group_client["Client SDK"]
  node_client_sdk["SDK<br/>http client"]
  node_async_consumer["Async consumer<br/>streaming client<br/>[async_consumer.py]"]
  node_async_producer["Async producer<br/>producer client<br/>[async_producer.py]"]
end

subgraph group_ops["Operations"]
  node_health_router(("Health<br/>router<br/>[router.py]"))
  node_metrics_router(("Metrics<br/>router<br/>[router.py]"))
  node_internal_router(("Internal<br/>router<br/>[router.py]"))
end

node_broker_app -->|"mounts"| node_topics_router
node_broker_app -->|"mounts"| node_produce_router
node_broker_app -->|"mounts"| node_fetch_router
node_broker_app -->|"mounts"| node_groups_router
node_broker_app -->|"mounts"| node_cluster_router
node_broker_app -->|"mounts"| node_health_router
node_broker_app -->|"mounts"| node_metrics_router
node_broker_app -->|"mounts"| node_internal_router
node_topics_router -->|"reads/writes"| node_topic_store
node_produce_router -->|"delegates"| node_broker_services
node_fetch_router -->|"delegates"| node_broker_services
node_groups_router -->|"delegates"| node_broker_services
node_broker_services -->|"appends/reads"| node_partition_log
node_broker_services -->|"resolves"| node_topic_store
node_broker_services -->|"persists"| node_sqlite_store
node_groups_router -->|"assigns"| node_group_assignor
node_cluster_router -->|"exposes"| node_cluster_state
node_cluster_state -->|"loads/saves"| node_sqlite_store
node_group_assignor -->|"uses"| node_sqlite_store
node_partition_log -->|"encodes"| node_record_codec
node_client_sdk -->|"includes"| node_async_consumer
node_client_sdk -->|"includes"| node_async_producer
node_async_producer -->|"calls"| node_produce_router
node_async_consumer -->|"calls"| node_fetch_router
node_async_consumer -->|"heartbeats/commits"| node_groups_router
node_broker_workers -.->|"background sync"| node_sqlite_store
node_broker_workers -.->|"maintenance"| node_partition_log

click node_broker_app "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/app.py"
click node_broker_services "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/services.py"
click node_broker_workers "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/workers.py"
click node_topics_router "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/topics/router.py"
click node_produce_router "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/produce/router.py"
click node_fetch_router "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/fetch/router.py"
click node_groups_router "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/groups/router.py"
click node_cluster_router "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/cluster/router.py"
click node_health_router "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/health/router.py"
click node_metrics_router "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/metrics/router.py"
click node_internal_router "https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/internal/router.py"
click node_topic_store "https://github.com/pratikscfr/coldum/blob/main/src/coldum/storage/topic_store.py"
click node_partition_log "https://github.com/pratikscfr/coldum/blob/main/src/coldum/storage/partition_log.py"
click node_record_codec "https://github.com/pratikscfr/coldum/blob/main/src/coldum/storage/record.py"
click node_sqlite_store "https://github.com/pratikscfr/coldum/blob/main/src/coldum/metadata/sqlite_store.py"
click node_group_assignor "https://github.com/pratikscfr/coldum/blob/main/src/coldum/metadata/group_assignor.py"
click node_cluster_state "https://github.com/pratikscfr/coldum/blob/main/src/coldum/metadata/cluster.py"
click node_client_sdk "https://github.com/pratikscfr/coldum/tree/main/src/coldum/client"
click node_async_consumer "https://github.com/pratikscfr/coldum/blob/main/src/coldum/client/async_consumer.py"
click node_async_producer "https://github.com/pratikscfr/coldum/blob/main/src/coldum/client/async_producer.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_broker_app,node_broker_services,node_broker_workers,node_topics_router,node_produce_router,node_fetch_router,node_groups_router,node_cluster_router toneBlue
class node_topic_store,node_partition_log,node_record_codec toneAmber
class node_sqlite_store,node_group_assignor,node_cluster_state toneMint
class node_client_sdk,node_async_consumer,node_async_producer toneRose
class node_health_router,node_metrics_router,node_internal_router toneIndigo
```

## Components

### Broker API

HTTP broker entrypoint and route surface

- [Broker app](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/app.py): entrypoint · Main broker process wiring the HTTP API · `src/coldum/broker/app.py`
- [Services](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/services.py): orchestration · Cross-cutting broker logic between handlers, storage, and metadata · `src/coldum/broker/services.py`
- [Workers](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/workers.py): background jobs · Background tasks and periodic broker work · `src/coldum/broker/workers.py`
- [Topics](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/topics/router.py): router · Topic metadata and partition layout endpoints · `src/coldum/broker/topics/router.py`
- [Produce](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/produce/router.py): router · Append records into partition logs · `src/coldum/broker/produce/router.py`
- [Fetch](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/fetch/router.py): router · Read records by logical offset with long polling · `src/coldum/broker/fetch/router.py`
- [Groups](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/groups/router.py): router · Membership, heartbeats, commits, assignment, and lag · `src/coldum/broker/groups/router.py`
- [Cluster](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/cluster/router.py): router · Cluster metadata and node/leader view · `src/coldum/broker/cluster/router.py`

### Storage

Durable topic and partition log persistence

- [Topic store](https://github.com/pratikscfr/coldum/blob/main/src/coldum/storage/topic_store.py): storage index · Topic metadata and partition layout persistence · `src/coldum/storage/topic_store.py`
- [Partition log](https://github.com/pratikscfr/coldum/blob/main/src/coldum/storage/partition_log.py): append-only log · Durable per-partition record log · `src/coldum/storage/partition_log.py`
- [Record codec](https://github.com/pratikscfr/coldum/blob/main/src/coldum/storage/record.py): encoding · Record serialization and logical offset encoding · `src/coldum/storage/record.py`

### Metadata

Cluster and consumer-group coordination state

- [SQLite store](https://github.com/pratikscfr/coldum/blob/main/src/coldum/metadata/sqlite_store.py): metadata store · Local persistent store for cluster and group state · `src/coldum/metadata/sqlite_store.py`
- [Assignor](https://github.com/pratikscfr/coldum/blob/main/src/coldum/metadata/group_assignor.py): assignment · Maps partitions to consumer-group members · `src/coldum/metadata/group_assignor.py`
- [Cluster state](https://github.com/pratikscfr/coldum/blob/main/src/coldum/metadata/cluster.py): metadata model · Cluster and leader metadata · `src/coldum/metadata/cluster.py`

### Client SDK

Sync and async HTTP client wrappers

- [SDK](https://github.com/pratikscfr/coldum/tree/main/src/coldum/client): http client · Sync and async producer/consumer wrappers · `src/coldum/client`
- [Async consumer](https://github.com/pratikscfr/coldum/blob/main/src/coldum/client/async_consumer.py): streaming client · Concurrent fetch loop with background heartbeats · `src/coldum/client/async_consumer.py`
- [Async producer](https://github.com/pratikscfr/coldum/blob/main/src/coldum/client/async_producer.py): producer client · Async publish wrapper over the HTTP API · `src/coldum/client/async_producer.py`

### Operations

Health, metrics, and internal admin surfaces

- [Health](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/health/router.py): router · Liveness and readiness checks · `src/coldum/broker/health/router.py`
- [Metrics](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/metrics/router.py): router · Operational metrics endpoint · `src/coldum/broker/metrics/router.py`
- [Internal](https://github.com/pratikscfr/coldum/blob/main/src/coldum/broker/internal/router.py): router · Non-public admin and implementation endpoints · `src/coldum/broker/internal/router.py`

## Connections

- Broker app → Topics: mounts · Registers topic routes under the versioned API
- Broker app → Produce: mounts · Registers produce routes
- Broker app → Fetch: mounts · Registers fetch routes
- Broker app → Groups: mounts · Registers consumer-group routes
- Broker app → Cluster: mounts · Registers cluster metadata routes
- Broker app → Health: mounts · Registers health checks
- Broker app → Metrics: mounts · Registers metrics endpoint
- Broker app → Internal: mounts · Registers internal endpoints
- Topics → Topic store: reads/writes · Manages topic and partition metadata
- Produce → Services: delegates · Validates requests and coordinates writes
- Fetch → Services: delegates · Coordinates reads and fetch semantics
- Groups → Services: delegates · Coordinates group membership and commits
- Services → Partition log: appends/reads · Main message data path through partition logs
- Services → Topic store: resolves · Looks up topics, partitions, and layouts
- Services → SQLite store: persists · Stores consumer-group and cluster coordination state
- Groups → Assignor: assigns · Computes partition ownership for members
- Cluster → Cluster state: exposes · Serves cluster and leader view
- Cluster state → SQLite store: loads/saves · Cluster metadata is persisted locally
- Assignor → SQLite store: uses · Reads group state needed for assignment
- Partition log → Record codec: encodes · Stores and decodes records with logical offsets
- SDK → Async consumer: includes · Async consumer is part of the SDK surface
- SDK → Async producer: includes · Async producer is part of the SDK surface
- Async producer → Produce: calls · Publishes records over HTTP
- Async consumer → Fetch: calls · Consumes records from fetch endpoints
- Async consumer → Groups: heartbeats/commits · Keeps membership active and commits offsets
- Workers → SQLite store: background sync · Runs recurring coordination or maintenance work
- Workers → Partition log: maintenance · May support retention or log-related background work
