# hihihi-sigma/tinydb architecture

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

- Interactive diagram: https://gitdiagram.com/hihihi-sigma/tinydb
- Repository: https://github.com/hihihi-sigma/tinydb

## Overview

Tinydb is a small interactive database: the user enters meta-commands or SQL-like INSERT, SELECT, DEL, and UPDATE statements; input is parsed, dispatched, and applied to rows in a paged file-backed table. The sampled code establishes the command loop, parser, execution dispatch, table operations, and pager persistence. The `where` type is defined in a header; its implementation file was read but provides no additional behavior. No README was supplied, so capability coverage is based on the sampled source.

Main entry points: [`src/main.c`](https://github.com/hihihi-sigma/tinydb/blob/main/src/main.c) (Command Loop), [`src/table.c`](https://github.com/hihihi-sigma/tinydb/blob/main/src/table.c) (Row Table), [`src/parser.c`](https://github.com/hihihi-sigma/tinydb/blob/main/src/parser.c) (Statement Parser), [`src/execute.c`](https://github.com/hihihi-sigma/tinydb/blob/main/src/execute.c) (Statement Executor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli["Interactive CLI"]
  node_main["Command Loop<br/>[main.c]"]
  node_input["Input Buffer<br/>[input_buffer.c]"]
end

subgraph group_query["Query Processing"]
  node_parser["Statement Parser<br/>[parser.c]"]
  node_where["Where Clause<br/>[where.c]"]
  node_executor["Statement Executor<br/>[execute.c]"]
end

subgraph group_storage["Table Storage"]
  node_table["Row Table<br/>[table.c]"]
  node_pager["Page Cache<br/>[pager.c]"]
  node_dbfile[("Database File")]
end

node_user(("User"))

node_user -->|"enters commands"| node_main
node_main -->|"reads input"| node_input
node_main -->|"parses statements"| node_parser
node_parser -->|"sets filters"| node_where
node_main -->|"dispatches statements"| node_executor
node_executor -->|"calls row operations"| node_table
node_table -->|"reads and writes pages"| node_pager
node_table -->|"checks filters"| node_where
node_pager -->|"loads and flushes"| node_dbfile

click node_main "https://github.com/hihihi-sigma/tinydb/blob/main/src/main.c"
click node_input "https://github.com/hihihi-sigma/tinydb/blob/main/src/input_buffer.c"
click node_parser "https://github.com/hihihi-sigma/tinydb/blob/main/src/parser.c"
click node_where "https://github.com/hihihi-sigma/tinydb/blob/main/src/where.c"
click node_executor "https://github.com/hihihi-sigma/tinydb/blob/main/src/execute.c"
click node_table "https://github.com/hihihi-sigma/tinydb/blob/main/src/table.c"
click node_pager "https://github.com/hihihi-sigma/tinydb/blob/main/src/pager.c"

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_main,node_input,node_user toneBlue
class node_parser,node_where,node_executor toneAmber
class node_table,node_pager,node_dbfile toneMint
```

## Components

### Interactive CLI

- [Command Loop](https://github.com/hihihi-sigma/tinydb/blob/main/src/main.c): `src/main.c`
- [Input Buffer](https://github.com/hihihi-sigma/tinydb/blob/main/src/input_buffer.c): `src/input_buffer.c`

### Query Processing

- [Statement Parser](https://github.com/hihihi-sigma/tinydb/blob/main/src/parser.c): `src/parser.c`
- [Where Clause](https://github.com/hihihi-sigma/tinydb/blob/main/src/where.c): `src/where.c`
- [Statement Executor](https://github.com/hihihi-sigma/tinydb/blob/main/src/execute.c): `src/execute.c`

### Table Storage

- [Row Table](https://github.com/hihihi-sigma/tinydb/blob/main/src/table.c): `src/table.c`
- [Page Cache](https://github.com/hihihi-sigma/tinydb/blob/main/src/pager.c): `src/pager.c`
- **Database File**

### Other components

- **User**

## Connections

- User → Command Loop: enters commands (evidence: `src/main.c`)
- Command Loop → Input Buffer: reads input (evidence: `src/main.c`)
- Command Loop → Statement Parser: parses statements (evidence: `src/main.c`)
- Statement Parser → Where Clause: sets filters (evidence: `src/parser.c`)
- Command Loop → Statement Executor: dispatches statements (evidence: `src/main.c`)
- Statement Executor → Row Table: calls row operations (evidence: `src/execute.c`)
- Row Table → Page Cache: reads and writes pages (evidence: `src/table.c`)
- Row Table → Where Clause: checks filters (evidence: `src/table.c`)
- Page Cache → Database File: loads and flushes (evidence: `src/pager.c`)
