# chrislloyd/git-remote-sqlite architecture

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

- Interactive diagram: https://gitdiagram.com/chrislloyd/git-remote-sqlite
- Repository: https://github.com/chrislloyd/git-remote-sqlite

## Overview

#### Purpose and Invocation
`git-remote-sqlite` is a Zig-built Git remote helper that maps Git fetch/push operations onto a SQLite database. Git invokes the installed `git-remote-sqlite` executable for `sqlite://…` remotes; the same binary also exposes direct database configuration commands. Primary entry and command dispatch are in `src/main.zig`, `src/cli.zig`, and `src/cmd.zig`.

#### Git Remote-Helper Protocol Boundary
The helper communicates with Git through the standard remote-helper line protocol over stdin/stdout. Protocol parsing, command negotiation, and responses form the main compatibility boundary with Git. `src/protocol.zig` defines this protocol-facing behavior, while `src/transport.zig` implements object/ref transfer mechanics and `src/help.zig` supports command-facing help behavior.

#### Repository Storage Model
Git’s content-addressed objects and references are persisted as SQLite rows rather than loose objects or pack files. The documented persistent model centers on Git objects, direct refs, and symbolic refs. SQLite access and schema-oriented persistence belong in `src/sqlite.zig`; the durable schema contract is documented in `docs/schema.md`.

#### Push and Fetch Data Flow
For a push, Git negotiates commands with the helper, which resolves the SQLite remote, receives or reads Git objects, writes object records, and updates refs. For pull/fetch, it reads refs and objects from SQLite and streams the requested Git data back through the helper protocol. The cross-cutting Git object/ref representation is handled by `src/git.zig`; remote location handling is in `src/remote.zig`; transfer orchestration spans `src/transport.zig` and `src/protocol.zig`.

#### Remote and Configuration Handling
SQLite remotes are addressed through `sqlite://` URLs and database paths. The CLI also supports server-side-style configuration CRUD stored with the repository, although the README states those settings do not yet alter behavior. URL/database resolution is isolated in `src/remote.zig`; configuration persistence and commands are represented by `src/config.zig` and `src/cmd.zig`.

#### Runtime and External Dependencies
The shipped artifact is a native Zig executable, built from `build.zig` with package metadata in `build.zig.zon`. Runtime interoperability depends on Git (remote-helper protocol) and SQLite (database engine and file format). The design intentionally leaves authentication and authorization outside the helper; deployments needing replication may pair the SQLite file with external tools such as Litestream and storage services such as S3.

#### Operational Constraints
This is a local/trusted-environment storage backend rather than a Git forge or network server. It currently favors simple object-row storage over pack-file efficiency, so large repositories and clones may have performance limits. Planned architecture extensions include pack management, Git hooks, and broader protocol command coverage; these concerns attach primarily to `src/sqlite.zig`, `src/transport.zig`, and `src/protocol.zig`.

Main entry points: [`src/sqlite.zig`](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/sqlite.zig) (SQLite persistence), [`src/protocol.zig`](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/protocol.zig) (Remote-helper protocol), [`src/cmd.zig`](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/cmd.zig) (Command dispatch), [`src/transport.zig`](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/transport.zig) (Transfer orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_git{{"Git client<br/>external runtime"}}
  node_build["Zig build<br/>build definition<br/>[build.zig]"]
end

subgraph group_helper["Remote helper"]
  node_main["Executable entry<br/>Zig entrypoint<br/>[main.zig]"]
  node_cli["CLI parsing<br/>command interface<br/>[cli.zig]"]
  node_commands["Command dispatch<br/>command handler<br/>[cmd.zig]"]
  node_protocol["Remote-helper protocol<br/>Git protocol boundary<br/>[protocol.zig]"]
  node_transport["Transfer orchestration<br/>fetch/push transport<br/>[transport.zig]"]
  node_remote["Remote resolution<br/>SQLite URL resolver<br/>[remote.zig]"]
end

subgraph group_storage["SQLite storage"]
  node_gitmodel["Git objects and refs<br/>Git data model<br/>[git.zig]"]
  node_sqlite["SQLite persistence<br/>storage adapter<br/>[sqlite.zig]"]
  node_config["Repository configuration<br/>configuration persistence<br/>[config.zig]"]
  node_database[("SQLite database file<br/>durable repository")]
  node_schema["Schema contract<br/>storage documentation<br/>[schema.md]"]
end

node_build -->|"builds"| node_main
node_git -->|"invokes"| node_main
node_main -->|"starts"| node_cli
node_cli -->|"parses commands"| node_commands
node_commands -->|"remote-helper mode"| node_protocol
node_commands -->|"configuration CRUD"| node_config
node_protocol -->|"line protocol"| node_git
node_protocol -->|"negotiates transfer"| node_transport
node_protocol -->|"resolves remote"| node_remote
node_transport -->|"reads and writes"| node_gitmodel
node_transport -->|"fetches and pushes"| node_sqlite
node_remote -->|"opens database"| node_sqlite
node_gitmodel -->|"persisted as rows"| node_sqlite
node_config -->|"stores settings"| node_sqlite
node_sqlite -->|"SQLite access"| node_database
node_schema -.->|"documents"| node_database

click node_build "https://github.com/chrislloyd/git-remote-sqlite/blob/main/build.zig"
click node_main "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/main.zig"
click node_cli "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/cli.zig"
click node_commands "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/cmd.zig"
click node_protocol "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/protocol.zig"
click node_transport "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/transport.zig"
click node_remote "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/remote.zig"
click node_gitmodel "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/git.zig"
click node_sqlite "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/sqlite.zig"
click node_config "https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/config.zig"
click node_schema "https://github.com/chrislloyd/git-remote-sqlite/blob/main/docs/schema.md"

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_git,node_build toneBlue
class node_main,node_cli,node_commands,node_protocol,node_transport,node_remote toneAmber
class node_gitmodel,node_sqlite,node_config,node_database,node_schema toneMint
```

## Components

### Runtime

- **Git client**: external runtime · Invokes the helper for sqlite:// remotes.
- [Zig build](https://github.com/chrislloyd/git-remote-sqlite/blob/main/build.zig): build definition · Builds the native helper executable. · `build.zig`

### Remote helper

- [Executable entry](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/main.zig): Zig entrypoint · `src/main.zig`
- [CLI parsing](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/cli.zig): command interface · `src/cli.zig`
- [Command dispatch](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/cmd.zig): command handler · Routes helper and direct configuration commands. · `src/cmd.zig`
- [Remote-helper protocol](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/protocol.zig): Git protocol boundary · Parses and responds on stdin/stdout. · `src/protocol.zig`
- [Transfer orchestration](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/transport.zig): fetch/push transport · Moves requested objects and refs in both directions. · `src/transport.zig`
- [Remote resolution](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/remote.zig): SQLite URL resolver · Resolves sqlite:// URLs and database paths. · `src/remote.zig`

### SQLite storage

- [Git objects and refs](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/git.zig): Git data model · Represents content-addressed objects, direct refs, and symbolic refs. · `src/git.zig`
- [SQLite persistence](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/sqlite.zig): storage adapter · Reads and writes object, ref, and configuration rows. · `src/sqlite.zig`
- [Repository configuration](https://github.com/chrislloyd/git-remote-sqlite/blob/main/src/config.zig): configuration persistence · Stores configuration CRUD data; settings do not yet alter behavior. · `src/config.zig`
- **SQLite database file**: durable repository · Persistent backend for Git objects and refs.
- [Schema contract](https://github.com/chrislloyd/git-remote-sqlite/blob/main/docs/schema.md): storage documentation · Documents durable object and ref tables. · `docs/schema.md`

## Connections

- Zig build → Executable entry: builds
- Git client → Executable entry: invokes
- Executable entry → CLI parsing: starts
- CLI parsing → Command dispatch: parses commands
- Command dispatch → Remote-helper protocol: remote-helper mode
- Command dispatch → Repository configuration: configuration CRUD
- Remote-helper protocol → Git client: line protocol
- Remote-helper protocol → Transfer orchestration: negotiates transfer
- Remote-helper protocol → Remote resolution: resolves remote
- Transfer orchestration → Git objects and refs: reads and writes
- Transfer orchestration → SQLite persistence: fetches and pushes
- Remote resolution → SQLite persistence: opens database
- Git objects and refs → SQLite persistence: persisted as rows
- Repository configuration → SQLite persistence: stores settings
- SQLite persistence → SQLite database file: SQLite access
- Schema contract → SQLite database file: documents
