# ojitoss/git-2005-small-fixed architecture

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

- Interactive diagram: https://gitdiagram.com/ojitoss/git-2005-small-fixed
- Repository: https://github.com/ojitoss/git-2005-small-fixed

## Overview

#### Purpose and Build Surface
This is a compiler-modernized snapshot of Git’s April 2005 prototype: a small set of standalone C executables implementing content-addressed storage, an index, trees, and commits. `Makefile` builds the command binaries; each `*.c` command has its own `main` entry point.

Paths: `Makefile`, `README`, `README.md`

#### Repository Initialization and Storage Layout
`init-db` establishes the repository-local `.dircache` database, including `.dircache/index` and a fan-out `.dircache/objects/00..ff` loose-object store. Object IDs address compressed objects by SHA-1-derived path split, separating command logic from persistent storage layout.

Paths: `init-db.c`, `cache.h`

#### Shared Object and Index Contract
`cache.h` is the central cross-command contract: it defines index/cache entry structures, shared globals, SHA-1/object-writing interfaces, and repository path assumptions. The index is the staging boundary between working-tree files and immutable object creation.

Paths: `cache.h`, `read-cache.c`

#### Working Tree to Blob / Index Pipeline
`update-cache` accepts one path, reads its working-tree content, creates a blob object, and records file metadata plus the blob ID in `.dircache/index`. It relies on index loading/writing and object persistence rather than a long-running daemon or library process.

Paths: `update-cache.c`, `read-cache.c`, `cache.h`

#### Index Inspection and Change Detection
`show-diff` reads staged cache entries and compares them with the current filesystem state to report whether indexed files remain valid. This is an early status/diff-like control point; it does not represent a full patch-generation subsystem.

Paths: `show-diff.c`, `read-cache.c`, `cache.h`

#### Tree Construction and Traversal
`write-tree` converts index entries into a root tree object whose records carry mode, filename, and blob SHA-1; it prints the resulting tree ID for downstream commit creation. `read-tree` resolves a supplied tree ID and renders its entries. The model is root-tree oriented, with no evidence in this file set of recursive directory/tree construction.

Paths: `write-tree.c`, `read-tree.c`, `read-cache.c`

#### Commit and Object Access Boundary
`commit-tree` takes a tree ID, optional parent IDs, author/committer environment data, and stdin message to persist a commit object. Parent linkage is caller-managed. `cat-file` is the raw object retrieval path, resolving an object ID from loose storage and materializing its content into a temporary file rather than streaming it directly.

Paths: `commit-tree.c`, `cat-file.c`, `cache.h`

#### Runtime and External Dependencies
The system is native C, invoked as separate CLI processes in the current working directory. Its material infrastructure is the local filesystem (`.dircache`, working files, temporary files); there is no network transport, remote service, server, or database. The README identifies GCC/Make compatibility work and zlib-compressed loose objects.

Paths: `Makefile`, `README.md`, `README`

Main entry points: [`read-cache.c`](https://github.com/ojitoss/git-2005-small-fixed/blob/main/read-cache.c) (Index I/O), [`Makefile`](https://github.com/ojitoss/git-2005-small-fixed/blob/main/Makefile) (Makefile), [`update-cache.c`](https://github.com/ojitoss/git-2005-small-fixed/blob/main/update-cache.c) (update-cache), [`write-tree.c`](https://github.com/ojitoss/git-2005-small-fixed/blob/main/write-tree.c) (write-tree)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build Surface"]
  node_makefile["Makefile<br/>build script"]
  node_readme["README docs<br/>documentation<br/>[README.md]"]
end

subgraph group_commands["Standalone CLI Commands"]
  node_cache_contract["Shared cache contract<br/>C header<br/>[cache.h]"]
  node_index_io["Index I/O<br/>shared C module<br/>[read-cache.c]"]
  node_init_db["init-db<br/>CLI command<br/>[init-db.c]"]
  node_update_cache["update-cache<br/>CLI command<br/>[update-cache.c]"]
  node_show_diff["show-diff<br/>CLI command<br/>[show-diff.c]"]
  node_write_tree["write-tree<br/>CLI command<br/>[write-tree.c]"]
  node_read_tree["read-tree<br/>CLI command<br/>[read-tree.c]"]
  node_commit_tree["commit-tree<br/>CLI command<br/>[commit-tree.c]"]
  node_cat_file["cat-file<br/>CLI command<br/>[cat-file.c]"]
end

subgraph group_storage["Repository Data"]
  node_working_tree[("Working files<br/>local filesystem")]
  node_index[(".dircache/index<br/>staging index")]
  node_object_store[(".dircache/objects<br/>loose object store")]
  node_temporary_file["Temporary file<br/>local filesystem"]
end

node_makefile -->|"builds"| node_init_db
node_makefile -->|"builds"| node_update_cache
node_makefile -->|"builds"| node_write_tree
node_makefile -->|"builds"| node_commit_tree
node_cache_contract -->|"defines contract"| node_index_io
node_init_db -->|"creates"| node_index
node_init_db -->|"creates fan-out store"| node_object_store
node_update_cache -->|"reads file"| node_working_tree
node_update_cache -->|"uses"| node_index_io
node_update_cache -->|"writes blob"| node_object_store
node_index_io -->|"reads and writes"| node_index
node_show_diff -->|"loads staged entries"| node_index_io
node_show_diff -->|"compares state"| node_working_tree
node_write_tree -->|"reads entries"| node_index_io
node_write_tree -->|"writes root tree"| node_object_store
node_read_tree -->|"reads tree"| node_object_store
node_commit_tree -->|"writes commit"| node_object_store
node_cat_file -->|"resolves object"| node_object_store
node_cat_file -->|"materializes content"| node_temporary_file
node_write_tree -.->|"prints tree ID"| node_commit_tree

click node_makefile "https://github.com/ojitoss/git-2005-small-fixed/blob/main/Makefile"
click node_readme "https://github.com/ojitoss/git-2005-small-fixed/blob/main/README.md"
click node_cache_contract "https://github.com/ojitoss/git-2005-small-fixed/blob/main/cache.h"
click node_index_io "https://github.com/ojitoss/git-2005-small-fixed/blob/main/read-cache.c"
click node_init_db "https://github.com/ojitoss/git-2005-small-fixed/blob/main/init-db.c"
click node_update_cache "https://github.com/ojitoss/git-2005-small-fixed/blob/main/update-cache.c"
click node_show_diff "https://github.com/ojitoss/git-2005-small-fixed/blob/main/show-diff.c"
click node_write_tree "https://github.com/ojitoss/git-2005-small-fixed/blob/main/write-tree.c"
click node_read_tree "https://github.com/ojitoss/git-2005-small-fixed/blob/main/read-tree.c"
click node_commit_tree "https://github.com/ojitoss/git-2005-small-fixed/blob/main/commit-tree.c"
click node_cat_file "https://github.com/ojitoss/git-2005-small-fixed/blob/main/cat-file.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_makefile,node_readme toneBlue
class node_cache_contract,node_index_io,node_init_db,node_update_cache,node_show_diff,node_write_tree,node_read_tree,node_commit_tree,node_cat_file toneAmber
class node_working_tree,node_index,node_object_store,node_temporary_file toneMint
```

## Components

### Build Surface

- [Makefile](https://github.com/ojitoss/git-2005-small-fixed/blob/main/Makefile): build script · Builds the standalone C command binaries. · `Makefile`
- [README docs](https://github.com/ojitoss/git-2005-small-fixed/blob/main/README.md): documentation · Documents GCC/Make compatibility and zlib loose objects. · `README.md`

### Standalone CLI Commands

- [Shared cache contract](https://github.com/ojitoss/git-2005-small-fixed/blob/main/cache.h): C header · Defines index entries, object interfaces, and repository paths. · `cache.h`
- [Index I/O](https://github.com/ojitoss/git-2005-small-fixed/blob/main/read-cache.c): shared C module · Loads and writes the staging index. · `read-cache.c`
- [init-db](https://github.com/ojitoss/git-2005-small-fixed/blob/main/init-db.c): CLI command · Creates the repository-local storage layout. · `init-db.c`
- [update-cache](https://github.com/ojitoss/git-2005-small-fixed/blob/main/update-cache.c): CLI command · Stages one working-tree file as a blob and index entry. · `update-cache.c`
- [show-diff](https://github.com/ojitoss/git-2005-small-fixed/blob/main/show-diff.c): CLI command · Checks staged entries against current filesystem state. · `show-diff.c`
- [write-tree](https://github.com/ojitoss/git-2005-small-fixed/blob/main/write-tree.c): CLI command · Converts index entries into a root tree object. · `write-tree.c`
- [read-tree](https://github.com/ojitoss/git-2005-small-fixed/blob/main/read-tree.c): CLI command · Renders entries from a supplied tree ID. · `read-tree.c`
- [commit-tree](https://github.com/ojitoss/git-2005-small-fixed/blob/main/commit-tree.c): CLI command · Persists a commit from a tree, parents, environment, and stdin message. · `commit-tree.c`
- [cat-file](https://github.com/ojitoss/git-2005-small-fixed/blob/main/cat-file.c): CLI command · Retrieves a loose object into a temporary file. · `cat-file.c`

### Repository Data

- **Working files**: local filesystem
- **.dircache/index**: staging index · Mutable boundary between files and immutable objects.
- **.dircache/objects**: loose object store · SHA-1 fan-out paths hold zlib-compressed objects.
- **Temporary file**: local filesystem · Materialized output of raw object retrieval.

## Connections

- Makefile → init-db: builds
- Makefile → update-cache: builds
- Makefile → write-tree: builds
- Makefile → commit-tree: builds
- Shared cache contract → Index I/O: defines contract
- init-db → .dircache/index: creates
- init-db → .dircache/objects: creates fan-out store
- update-cache → Working files: reads file
- update-cache → Index I/O: uses
- update-cache → .dircache/objects: writes blob
- Index I/O → .dircache/index: reads and writes
- show-diff → Index I/O: loads staged entries
- show-diff → Working files: compares state
- write-tree → Index I/O: reads entries
- write-tree → .dircache/objects: writes root tree
- read-tree → .dircache/objects: reads tree
- commit-tree → .dircache/objects: writes commit
- cat-file → .dircache/objects: resolves object
- cat-file → Temporary file: materializes content
- write-tree → commit-tree: prints tree ID
