# grizzly4ctual/gopherstore architecture

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

- Interactive diagram: https://gitdiagram.com/grizzly4ctual/gopherstore
- Repository: https://github.com/grizzly4ctual/gopherstore

## Overview

Gopher Store is a Go relational database exposed as an interactive command shell. The main workflow is user input through command dispatch, then transactional table operations and indexed or scanned retrieval, backed by a persistent page store. The README also describes key constraints, concurrent access, and query filtering. The graph follows relationships explicit in sampled code or README; implementation detail for some documented capabilities is unsampled, so those links are documented rather than inferred from module names.

Main entry points: [`database/persist.go`](https://github.com/grizzly4ctual/gopherstore/blob/main/database/persist.go) (KV Store), [`database/commands.go`](https://github.com/grizzly4ctual/gopherstore/blob/main/database/commands.go) (Command Handlers), [`database/updates.go`](https://github.com/grizzly4ctual/gopherstore/blob/main/database/updates.go) (Table Operations), [`database/b_tree.go`](https://github.com/grizzly4ctual/gopherstore/blob/main/database/b_tree.go) (B+ Tree)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["Interactive Shell"]
  node_entry["Program Entry<br/>[main.go]"]
  node_shell_runtime["Shell Runtime<br/>[database_impl.go]"]
  node_command_handlers["Command Handlers<br/>[commands.go]"]
  node_input_helpers["Input Helpers<br/>[helper.go]"]
end

subgraph group_relational["Relational Operations"]
  node_records["Records and Schema<br/>[record.go]"]
  node_table_updates["Table Operations<br/>[updates.go]"]
  node_transactions["Transactions<br/>[transactions.go]"]
  node_indexes["Index Management<br/>[indexes.go]"]
end

subgraph group_query["Query Retrieval"]
  node_query_dispatch["Query Dispatch<br/>[commands.go]"]
  node_range_scanner["Range Scanner<br/>[range.go]"]
  node_table_scan["Table Scanner<br/>[table_scanner.go]"]
end

subgraph group_storage["Storage Engine"]
  node_kv_store[("KV Store<br/>[persist.go]")]
  node_btree["B+ Tree<br/>[b_tree.go]"]
  node_free_list["Page Free List<br/>[free_list.go]"]
  node_mmap["Memory Mapping<br/>[mmap_windows.go]"]
end

subgraph group_concurrency["Concurrency"]
  node_worker_pool["Worker Pool<br/>[workers.go]"]
end

node_user(("Database User"))
node_user_data[("Database File")]

node_user -->|"starts"| node_entry
node_entry -->|"starts shell"| node_shell_runtime
node_shell_runtime -->|"dispatches commands"| node_command_handlers
node_command_handlers -->|"prompts for input"| node_input_helpers
node_command_handlers -->|"runs mutations"| node_table_updates
node_command_handlers -->|"controls transactions"| node_transactions
node_command_handlers -->|"submits queries"| node_query_dispatch
node_table_updates -->|"validates and encodes"| node_records
node_table_updates -->|"maintains indexes"| node_indexes
node_table_updates -->|"updates keys"| node_kv_store
node_transactions -->|"commits changes"| node_kv_store
node_query_dispatch -->|"runs range scans"| node_range_scanner
node_query_dispatch -.->|"runs filtered scans"| node_table_scan
node_query_dispatch -->|"submits work"| node_worker_pool
node_range_scanner -->|"seeks keys"| node_btree
node_table_scan -.->|"scans records"| node_btree
node_kv_store -->|"persists pages"| node_btree
node_kv_store -->|"allocates pages"| node_free_list
node_kv_store -->|"maps database file"| node_mmap
node_kv_store -->|"reads and writes"| node_user_data

click node_entry "https://github.com/grizzly4ctual/gopherstore/blob/main/main.go"
click node_shell_runtime "https://github.com/grizzly4ctual/gopherstore/blob/main/database/database_impl.go"
click node_command_handlers "https://github.com/grizzly4ctual/gopherstore/blob/main/database/commands.go"
click node_input_helpers "https://github.com/grizzly4ctual/gopherstore/blob/main/database/helper/helper.go"
click node_records "https://github.com/grizzly4ctual/gopherstore/blob/main/database/record.go"
click node_table_updates "https://github.com/grizzly4ctual/gopherstore/blob/main/database/updates.go"
click node_transactions "https://github.com/grizzly4ctual/gopherstore/blob/main/database/transactions.go"
click node_indexes "https://github.com/grizzly4ctual/gopherstore/blob/main/database/indexes.go"
click node_query_dispatch "https://github.com/grizzly4ctual/gopherstore/blob/main/database/commands.go"
click node_range_scanner "https://github.com/grizzly4ctual/gopherstore/blob/main/database/range.go"
click node_table_scan "https://github.com/grizzly4ctual/gopherstore/blob/main/database/table_scanner.go"
click node_worker_pool "https://github.com/grizzly4ctual/gopherstore/blob/main/database/workers.go"
click node_kv_store "https://github.com/grizzly4ctual/gopherstore/blob/main/database/persist.go"
click node_btree "https://github.com/grizzly4ctual/gopherstore/blob/main/database/b_tree.go"
click node_free_list "https://github.com/grizzly4ctual/gopherstore/blob/main/database/free_list.go"
click node_mmap "https://github.com/grizzly4ctual/gopherstore/blob/main/database/mmap_windows.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_entry,node_shell_runtime,node_command_handlers,node_input_helpers toneBlue
class node_records,node_table_updates,node_transactions,node_indexes,node_user,node_user_data toneAmber
class node_query_dispatch,node_range_scanner,node_table_scan toneMint
class node_kv_store,node_btree,node_free_list,node_mmap toneRose
class node_worker_pool toneIndigo
```

## Components

### Interactive Shell

- [Program Entry](https://github.com/grizzly4ctual/gopherstore/blob/main/main.go): `main.go`
- [Shell Runtime](https://github.com/grizzly4ctual/gopherstore/blob/main/database/database_impl.go): `database/database_impl.go`
- [Command Handlers](https://github.com/grizzly4ctual/gopherstore/blob/main/database/commands.go): `database/commands.go`
- [Input Helpers](https://github.com/grizzly4ctual/gopherstore/blob/main/database/helper/helper.go): `database/helper/helper.go`

### Relational Operations

- [Records and Schema](https://github.com/grizzly4ctual/gopherstore/blob/main/database/record.go): `database/record.go`
- [Table Operations](https://github.com/grizzly4ctual/gopherstore/blob/main/database/updates.go): `database/updates.go`
- [Transactions](https://github.com/grizzly4ctual/gopherstore/blob/main/database/transactions.go): `database/transactions.go`
- [Index Management](https://github.com/grizzly4ctual/gopherstore/blob/main/database/indexes.go): `database/indexes.go`

### Query Retrieval

- [Query Dispatch](https://github.com/grizzly4ctual/gopherstore/blob/main/database/commands.go): `database/commands.go`
- [Range Scanner](https://github.com/grizzly4ctual/gopherstore/blob/main/database/range.go): `database/range.go`
- [Table Scanner](https://github.com/grizzly4ctual/gopherstore/blob/main/database/table_scanner.go): `database/table_scanner.go`

### Storage Engine

- [KV Store](https://github.com/grizzly4ctual/gopherstore/blob/main/database/persist.go): `database/persist.go`
- [B+ Tree](https://github.com/grizzly4ctual/gopherstore/blob/main/database/b_tree.go): `database/b_tree.go`
- [Page Free List](https://github.com/grizzly4ctual/gopherstore/blob/main/database/free_list.go): `database/free_list.go`
- [Memory Mapping](https://github.com/grizzly4ctual/gopherstore/blob/main/database/mmap_windows.go): `database/mmap_windows.go`

### Concurrency

- [Worker Pool](https://github.com/grizzly4ctual/gopherstore/blob/main/database/workers.go): `database/workers.go`

### Other components

- **Database User**
- **Database File**

## Connections

- Database User → Program Entry: starts (evidence: `README.md`)
- Program Entry → Shell Runtime: starts shell (evidence: `main.go`)
- Shell Runtime → Command Handlers: dispatches commands (evidence: `database/database_impl.go`)
- Command Handlers → Input Helpers: prompts for input (evidence: `database/commands.go`)
- Command Handlers → Table Operations: runs mutations (evidence: `database/commands.go`)
- Command Handlers → Transactions: controls transactions (evidence: `database/commands.go`)
- Command Handlers → Query Dispatch: submits queries (evidence: `database/commands.go`)
- Table Operations → Records and Schema: validates and encodes (evidence: `database/updates.go`)
- Table Operations → Index Management: maintains indexes (evidence: `database/updates.go`)
- Table Operations → KV Store: updates keys (evidence: `database/updates.go`)
- Transactions → KV Store: commits changes
- Query Dispatch → Range Scanner: runs range scans (evidence: `database/commands.go`)
- Query Dispatch → Table Scanner: runs filtered scans
- Query Dispatch → Worker Pool: submits work (evidence: `database/commands.go`)
- Range Scanner → B+ Tree: seeks keys (evidence: `database/range.go`)
- Table Scanner → B+ Tree: scans records
- KV Store → B+ Tree: persists pages (evidence: `database/persist.go`)
- KV Store → Page Free List: allocates pages (evidence: `database/persist.go`)
- KV Store → Memory Mapping: maps database file (evidence: `database/persist.go`)
- KV Store → Database File: reads and writes (evidence: `database/persist.go`)
