# tejakusireddy/falconq-distributed-message-queue architecture

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

- Interactive diagram: https://gitdiagram.com/tejakusireddy/falconq-distributed-message-queue
- Repository: https://github.com/tejakusireddy/falconq-distributed-message-queue

## Overview

FalconQ is a Go message-queue broker. Producers publish topic messages over REST; the broker selects a partition, records the message through its Raft-backed partition state, and returns an acknowledgement. Consumers peek by offset or consume in batches with per-consumer offset tracking. The README also documents topic/partition administration and Raft statistics. The excerpts show routing, partition selection, BadgerDB persistence, and REST setup, but not the full handler implementations or Raft transport wiring; those relationships are omitted where unverified.

Main entry points: [`broker/main.go`](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go) (Broker process)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["REST API"]
  node_broker["Broker process<br/>[main.go]"]
  node_publish["Publish endpoint<br/>[main.go]"]
  node_peek["Peek endpoint<br/>[main.go]"]
  node_consume["Consume endpoint<br/>[main.go]"]
  node_admin["Admin endpoints<br/>[main.go]"]
end

subgraph group_routing["Topics and Partitions"]
  node_topicstate["Topic registry<br/>[main.go]"]
  node_partition["Partition selection<br/>[main.go]"]
  node_hashing["Consistent hashing<br/>[main.go]"]
  node_roundrobin["Round-robin fallback<br/>[main.go]"]
end

subgraph group_consumption["Message Consumption"]
  node_priority["Priority ordering<br/>[main.go]"]
  node_batch["Batch reads<br/>[main.go]"]
  node_offsets["Consumer offsets<br/>[main.go]"]
end

subgraph group_reliability["Persistence and Consensus"]
  node_badger[("BadgerDB<br/>[main.go]")]
  node_fsm["Partition FSM<br/>[main.go]"]
  node_raft["Raft replication<br/>[main.go]"]
  node_stats["Raft statistics<br/>[main.go]"]
end

node_producer(("Producer"))
node_consumer(("Consumer"))

node_producer -->|"publishes"| node_publish
node_consumer -->|"consumes"| node_consume
node_consumer -->|"peeks"| node_peek
node_broker -->|"registers"| node_publish
node_broker -->|"registers"| node_peek
node_broker -->|"registers"| node_consume
node_broker -->|"registers"| node_admin
node_publish -.->|"gets topic"| node_topicstate
node_topicstate -->|"selects partition"| node_partition
node_partition -->|"hashes key"| node_hashing
node_partition -->|"falls back"| node_roundrobin
node_consume -->|"reads batch"| node_batch
node_consume -->|"tracks offset"| node_offsets
node_peek -->|"reads batch"| node_batch
node_batch -->|"prioritizes"| node_priority
node_batch -->|"reads messages"| node_badger
node_offsets -->|"reads offset"| node_badger
node_fsm -->|"writes messages"| node_badger
node_raft -.->|"applies commands"| node_fsm
node_broker -.->|"starts consensus"| node_raft
node_admin -.->|"serves stats"| node_stats
node_admin -.->|"lists topics"| node_topicstate

click node_broker "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_publish "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_peek "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_consume "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_admin "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_topicstate "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_partition "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_hashing "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_roundrobin "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_priority "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_batch "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_offsets "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_badger "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_fsm "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_raft "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go"
click node_stats "https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.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_broker,node_publish,node_peek,node_consume,node_admin toneBlue
class node_topicstate,node_partition,node_hashing,node_roundrobin toneAmber
class node_priority,node_batch,node_offsets toneMint
class node_badger,node_fsm,node_raft,node_stats toneRose
class node_producer,node_consumer toneIndigo
```

## Components

### REST API

- [Broker process](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Publish endpoint](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Peek endpoint](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Consume endpoint](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Admin endpoints](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`

### Topics and Partitions

- [Topic registry](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Partition selection](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Consistent hashing](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Round-robin fallback](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`

### Message Consumption

- [Priority ordering](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Batch reads](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Consumer offsets](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`

### Persistence and Consensus

- [BadgerDB](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Partition FSM](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Raft replication](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`
- [Raft statistics](https://github.com/tejakusireddy/falconq-distributed-message-queue/blob/main/broker/main.go): `broker/main.go`

### Other components

- **Producer**
- **Consumer**

## Connections

- Producer → Publish endpoint: publishes (evidence: `README.md`)
- Consumer → Consume endpoint: consumes (evidence: `README.md`)
- Consumer → Peek endpoint: peeks (evidence: `README.md`)
- Broker process → Publish endpoint: registers (evidence: `broker/main.go`)
- Broker process → Peek endpoint: registers (evidence: `broker/main.go`)
- Broker process → Consume endpoint: registers (evidence: `broker/main.go`)
- Broker process → Admin endpoints: registers (evidence: `broker/main.go`)
- Publish endpoint → Topic registry: gets topic (evidence: `broker/main.go`)
- Topic registry → Partition selection: selects partition (evidence: `broker/main.go`)
- Partition selection → Consistent hashing: hashes key (evidence: `broker/main.go`)
- Partition selection → Round-robin fallback: falls back (evidence: `broker/main.go`)
- Consume endpoint → Batch reads: reads batch (evidence: `README.md`)
- Consume endpoint → Consumer offsets: tracks offset (evidence: `README.md`)
- Peek endpoint → Batch reads: reads batch (evidence: `README.md`)
- Batch reads → Priority ordering: prioritizes (evidence: `README.md`)
- Batch reads → BadgerDB: reads messages (evidence: `broker/main.go`)
- Consumer offsets → BadgerDB: reads offset (evidence: `broker/main.go`)
- Partition FSM → BadgerDB: writes messages (evidence: `broker/main.go`)
- Raft replication → Partition FSM: applies commands (evidence: `broker/main.go`)
- Broker process → Raft replication: starts consensus (evidence: `broker/main.go`)
- Admin endpoints → Raft statistics: serves stats (evidence: `broker/main.go`)
- Admin endpoints → Topic registry: lists topics (evidence: `broker/main.go`)
