# manosriram/nimbusdb architecture

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

- Interactive diagram: https://gitdiagram.com/manosriram/nimbusdb
- Repository: https://github.com/manosriram/nimbusdb

## Overview

nimbusdb is an embedded, persistent Bitcask-style key-value store. The main workflow is callers opening a database, then reading, writing, expiring, or deleting keys backed by append-oriented data files and an in-memory key directory. Separate capabilities include batch operations, prefix iteration, change watching, and merge compaction. The excerpts show key-directory, segment, cache, batch, and watch interactions; some storage and lifecycle details are documented only at a high level, so those links cite the README.

Main entry points: [`db.go`](https://github.com/manosriram/nimbusdb/blob/main/db.go) (Database Operations), [`reader.go`](https://github.com/manosriram/nimbusdb/blob/main/reader.go) (Prefix Readers), [`segment.go`](https://github.com/manosriram/nimbusdb/blob/main/segment.go) (Segment Index), [`wal.go`](https://github.com/manosriram/nimbusdb/blob/main/wal.go) (Entry Encoding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Database API"]
  node_db["Database Operations<br/>[db.go]"]
  node_options["Options and Types<br/>[types.go]"]
end

subgraph group_index["Lookup and Cache"]
  node_keydir["Key Directory<br/>[btree.go]"]
  node_cache["Block Cache<br/>[db.go]"]
  node_segments["Segment Index<br/>[segment.go]"]
end

subgraph group_storage["Persistent Storage"]
  node_entry["Entry Encoding<br/>[wal.go]"]
  node_datafiles[("Data Files<br/>[db.go]")]
  node_merge["Merge Compaction<br/>[db.go]"]
  node_fileutils["File Utilities<br/>[file.go]"]
end

subgraph group_features["Database Features"]
  node_batch["Batch Operations<br/>[batch.go]"]
  node_reader["Prefix Readers<br/>[reader.go]"]
  node_watch["Change Watcher<br/>[watch.go]"]
end

node_caller(("Application"))

node_caller -->|"opens and operates"| node_db
node_caller -->|"starts batch"| node_batch
node_caller -->|"iterates keys"| node_reader
node_caller -->|"subscribes"| node_watch
node_db -->|"configures"| node_options
node_db -->|"looks up keys"| node_keydir
node_db -->|"caches blocks"| node_cache
node_db -->|"locates blocks"| node_segments
node_db -->|"reads and appends"| node_datafiles
node_db -->|"encodes entries"| node_entry
node_db -->|"runs compaction"| node_merge
node_db -->|"sends events"| node_watch
node_batch -->|"commits through"| node_db
node_reader -->|"iterates index"| node_keydir
node_reader -->|"loads values"| node_db
node_segments -->|"tracks file blocks"| node_datafiles
node_entry -->|"encodes fields"| node_fileutils
node_merge -->|"rewrites live entries"| node_datafiles

click node_db "https://github.com/manosriram/nimbusdb/blob/main/db.go"
click node_options "https://github.com/manosriram/nimbusdb/blob/main/types.go"
click node_batch "https://github.com/manosriram/nimbusdb/blob/main/batch.go"
click node_reader "https://github.com/manosriram/nimbusdb/blob/main/reader.go"
click node_watch "https://github.com/manosriram/nimbusdb/blob/main/watch.go"
click node_keydir "https://github.com/manosriram/nimbusdb/blob/main/btree.go"
click node_cache "https://github.com/manosriram/nimbusdb/blob/main/db.go"
click node_segments "https://github.com/manosriram/nimbusdb/blob/main/segment.go"
click node_entry "https://github.com/manosriram/nimbusdb/blob/main/wal.go"
click node_datafiles "https://github.com/manosriram/nimbusdb/blob/main/db.go"
click node_merge "https://github.com/manosriram/nimbusdb/blob/main/db.go"
click node_fileutils "https://github.com/manosriram/nimbusdb/blob/main/utils/file.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_db,node_options toneBlue
class node_keydir,node_cache,node_segments toneAmber
class node_entry,node_datafiles,node_merge,node_fileutils toneMint
class node_batch,node_reader,node_watch toneRose
class node_caller toneIndigo
```

## Components

### Database API

- [Database Operations](https://github.com/manosriram/nimbusdb/blob/main/db.go): `db.go`
- [Options and Types](https://github.com/manosriram/nimbusdb/blob/main/types.go): `types.go`

### Lookup and Cache

- [Key Directory](https://github.com/manosriram/nimbusdb/blob/main/btree.go): `btree.go`
- [Block Cache](https://github.com/manosriram/nimbusdb/blob/main/db.go): `db.go`
- [Segment Index](https://github.com/manosriram/nimbusdb/blob/main/segment.go): `segment.go`

### Persistent Storage

- [Entry Encoding](https://github.com/manosriram/nimbusdb/blob/main/wal.go): `wal.go`
- [Data Files](https://github.com/manosriram/nimbusdb/blob/main/db.go): `db.go`
- [Merge Compaction](https://github.com/manosriram/nimbusdb/blob/main/db.go): `db.go`
- [File Utilities](https://github.com/manosriram/nimbusdb/blob/main/utils/file.go): `utils/file.go`

### Database Features

- [Batch Operations](https://github.com/manosriram/nimbusdb/blob/main/batch.go): `batch.go`
- [Prefix Readers](https://github.com/manosriram/nimbusdb/blob/main/reader.go): `reader.go`
- [Change Watcher](https://github.com/manosriram/nimbusdb/blob/main/watch.go): `watch.go`

### Other components

- **Application**

## Connections

- Application → Database Operations: opens and operates (evidence: `README.md`)
- Application → Batch Operations: starts batch (evidence: `README.md`)
- Application → Prefix Readers: iterates keys (evidence: `reader.go`)
- Application → Change Watcher: subscribes (evidence: `README.md`)
- Database Operations → Options and Types: configures (evidence: `db.go`)
- Database Operations → Key Directory: looks up keys (evidence: `db.go`)
- Database Operations → Block Cache: caches blocks (evidence: `db.go`)
- Database Operations → Segment Index: locates blocks (evidence: `db.go`)
- Database Operations → Data Files: reads and appends (evidence: `README.md`)
- Database Operations → Entry Encoding: encodes entries (evidence: `wal.go`)
- Database Operations → Merge Compaction: runs compaction (evidence: `README.md`)
- Database Operations → Change Watcher: sends events (evidence: `db.go`)
- Batch Operations → Database Operations: commits through (evidence: `batch.go`)
- Prefix Readers → Key Directory: iterates index (evidence: `reader.go`)
- Prefix Readers → Database Operations: loads values (evidence: `reader.go`)
- Segment Index → Data Files: tracks file blocks (evidence: `segment.go`)
- Entry Encoding → File Utilities: encodes fields (evidence: `wal.go`)
- Merge Compaction → Data Files: rewrites live entries (evidence: `README.md`)
