# harelba/q architecture

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

- Interactive diagram: https://gitdiagram.com/harelba/q
- Repository: https://github.com/harelba/q

## Overview

q is a command-line SQL interface for querying delimited text files and SQLite databases. The main workflow takes a user’s SQL query and file inputs, makes them queryable, executes SQL, and presents results. README documents automatic caching, joins across separate SQLite files, column/type detection, and encoding support. The runtime is concentrated in bin/q.py; sampled excerpts show parsing/inference, materialization, and output components, but omit the main execution path, so links beyond documented behavior are limited to README evidence.

Main entry points: [`bin/q.py`](https://github.com/harelba/q/blob/master/bin/q.py) (SQL query)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Command interface"]
  node_q_cli["q command<br/>[q.py]"]
end

subgraph group_query["Query processing"]
  node_sql_query["SQL query<br/>[q.py]"]
  node_sqlite_engine["SQLite query engine<br/>[q.py]"]
end

subgraph group_sources["Data sources"]
  node_file_detection["Input inference<br/>[q.py]"]
  node_delimited_reader["Delimited reader<br/>[q.py]"]
  node_materialization["Table materialization<br/>[q.py]"]
end

subgraph group_results["Results and cache"]
  node_cache[("Query cache<br/>[q.py]")]
  node_output_format["Output formatting<br/>[q.py]"]
end

node_user(("CLI user"))
node_text_files["Delimited text files"]
node_sqlite_files[("SQLite files")]
node_terminal(("CLI output"))

node_user -->|"runs query"| node_q_cli
node_q_cli -->|"accepts SQL"| node_sql_query
node_sql_query -->|"queries as tables"| node_text_files
node_sql_query -->|"queries directly"| node_sqlite_files
node_sql_query -->|"executes SQL"| node_sqlite_engine
node_file_detection -.->|"infers input"| node_delimited_reader
node_delimited_reader -.->|"provides rows"| node_materialization
node_materialization -->|"caches data"| node_cache
node_sqlite_engine -.->|"produces results"| node_output_format
node_output_format -.->|"prints results"| node_terminal

click node_q_cli "https://github.com/harelba/q/blob/master/bin/q.py"
click node_sql_query "https://github.com/harelba/q/blob/master/bin/q.py"
click node_file_detection "https://github.com/harelba/q/blob/master/bin/q.py"
click node_delimited_reader "https://github.com/harelba/q/blob/master/bin/q.py"
click node_materialization "https://github.com/harelba/q/blob/master/bin/q.py"
click node_sqlite_engine "https://github.com/harelba/q/blob/master/bin/q.py"
click node_cache "https://github.com/harelba/q/blob/master/bin/q.py"
click node_output_format "https://github.com/harelba/q/blob/master/bin/q.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_q_cli,node_user toneBlue
class node_sql_query,node_sqlite_engine,node_sqlite_files toneAmber
class node_file_detection,node_delimited_reader,node_materialization toneMint
class node_cache,node_output_format toneRose
class node_text_files,node_terminal toneIndigo
```

## Components

### Command interface

- [q command](https://github.com/harelba/q/blob/master/bin/q.py): `bin/q.py`

### Query processing

- [SQL query](https://github.com/harelba/q/blob/master/bin/q.py): `bin/q.py`
- [SQLite query engine](https://github.com/harelba/q/blob/master/bin/q.py): `bin/q.py`

### Data sources

- [Input inference](https://github.com/harelba/q/blob/master/bin/q.py): `bin/q.py`
- [Delimited reader](https://github.com/harelba/q/blob/master/bin/q.py): `bin/q.py`
- [Table materialization](https://github.com/harelba/q/blob/master/bin/q.py): `bin/q.py`

### Results and cache

- [Query cache](https://github.com/harelba/q/blob/master/bin/q.py): `bin/q.py`
- [Output formatting](https://github.com/harelba/q/blob/master/bin/q.py): `bin/q.py`

### Other components

- **CLI user**
- **Delimited text files**
- **SQLite files**
- **CLI output**

## Connections

- CLI user → q command: runs query (evidence: `README.markdown`)
- q command → SQL query: accepts SQL (evidence: `README.markdown`)
- SQL query → Delimited text files: queries as tables (evidence: `README.markdown`)
- SQL query → SQLite files: queries directly (evidence: `README.markdown`)
- SQL query → SQLite query engine: executes SQL (evidence: `README.markdown`)
- Input inference → Delimited reader: infers input (evidence: `bin/q.py`)
- Delimited reader → Table materialization: provides rows (evidence: `bin/q.py`)
- Table materialization → Query cache: caches data (evidence: `README.markdown`)
- SQLite query engine → Output formatting: produces results (evidence: `bin/q.py`)
- Output formatting → CLI output: prints results
