# zx2c4/cgit architecture

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

- Interactive diagram: https://gitdiagram.com/zx2c4/cgit
- Repository: https://github.com/zx2c4/cgit

## Overview

cgit is a CGI-based web interface for browsing Git repositories, with a built-in response cache. The principal workflow is an HTTP request entering the CGI handler, being resolved to a repository and page command, then rendered as a Git view and returned to the client; cache hits may serve a stored response. The README documents repository listing, history and source views, statistics, snapshots, and clone access. Some route and integration details are inferred only from the source index, so uncertain links are omitted.

Main entry points: [`cmd.c`](https://github.com/zx2c4/cgit/blob/master/cmd.c) (Page dispatch), [`ui-shared.c`](https://github.com/zx2c4/cgit/blob/master/ui-shared.c) (Shared UI helpers), [`cgit.c`](https://github.com/zx2c4/cgit/blob/master/cgit.c) (CGI handler), [`ui-log.c`](https://github.com/zx2c4/cgit/blob/master/ui-log.c) (Commit history)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_request["Request and cache"]
  node_cgi["CGI handler<br/>[cgit.c]"]
  node_page_dispatch["Page dispatch<br/>[cmd.c]"]
  node_response_cache[("Response cache<br/>[cache.c]")]
end

subgraph group_repository["Repository discovery"]
  node_runtime_config["Runtime configuration<br/>[configfile.c]"]
  node_repository_scan["Repository scan<br/>[scan-tree.c]"]
end

subgraph group_browse["Repository browsing"]
  node_repo_list["Repository index<br/>[ui-repolist.c]"]
  node_summary["Repository summary<br/>[ui-summary.c]"]
  node_refs_tags["Refs and tags<br/>[ui-refs.c]"]
  node_commit_history["Commit history<br/>[ui-log.c]"]
  node_commit_detail["Commit details<br/>[ui-commit.c]"]
  node_diff_view["Diff view<br/>[ui-diff.c]"]
  node_side_by_side["Side-by-side diff<br/>[ui-ssdiff.c]"]
  node_tree_browser["Tree browser<br/>[ui-tree.c]"]
  node_blob_view["Blob view<br/>[ui-blob.c]"]
  node_blame_view["Blame view<br/>[ui-blame.c]"]
  node_stats["Repository statistics<br/>[ui-stats.c]"]
  node_snapshot["Source snapshots<br/>[ui-snapshot.c]"]
  node_plain_file["Plain files<br/>[ui-plain.c]"]
  node_clone["Clone access<br/>[ui-clone.c]"]
  node_atom["Atom feed<br/>[ui-atom.c]"]
  node_patch["Patch output<br/>[ui-patch.c]"]
end

subgraph group_render["Rendering"]
  node_shared_ui["Shared UI helpers<br/>[ui-shared.c]"]
  node_html_output["HTML and HTTP output<br/>[html.c]"]
end

subgraph group_integrations["Extensions"]
  node_filter_engine["Content filters<br/>[filter.c]"]
  node_gravatar_filter["Gravatar filter<br/>[email-gravatar.py]"]
  node_syntax_filter["Syntax highlighting"]
end

node_browser(("Web client"))
node_git_repositories[("Git repositories")]

node_browser -->|"sends request"| node_cgi
node_cgi -->|"reads settings"| node_runtime_config
node_cgi -->|"checks cache"| node_response_cache
node_cgi -->|"refreshes index"| node_repository_scan
node_cgi -->|"dispatches page"| node_page_dispatch
node_repository_scan -->|"scans paths"| node_git_repositories
node_page_dispatch -->|"routes requests"| node_repo_list
node_page_dispatch -->|"routes requests"| node_summary
node_page_dispatch -->|"routes requests"| node_refs_tags
node_page_dispatch -->|"routes requests"| node_commit_history
node_page_dispatch -->|"routes requests"| node_commit_detail
node_page_dispatch -->|"routes requests"| node_diff_view
node_page_dispatch -->|"routes requests"| node_tree_browser
node_page_dispatch -->|"routes requests"| node_blob_view
node_page_dispatch -->|"routes requests"| node_blame_view
node_page_dispatch -->|"routes requests"| node_stats
node_page_dispatch -->|"routes requests"| node_snapshot
node_page_dispatch -->|"routes requests"| node_plain_file
node_page_dispatch -->|"routes requests"| node_clone
node_page_dispatch -->|"routes requests"| node_atom
node_page_dispatch -->|"routes requests"| node_patch
node_diff_view -->|"renders variant"| node_side_by_side
node_commit_history -->|"links commits"| node_commit_detail
node_tree_browser -->|"links files"| node_blob_view
node_repo_list -->|"uses helpers"| node_shared_ui
node_commit_history -->|"uses helpers"| node_shared_ui
node_diff_view -->|"uses helpers"| node_shared_ui
node_tree_browser -->|"uses helpers"| node_shared_ui
node_stats -->|"uses helpers"| node_shared_ui
node_shared_ui -->|"emits markup"| node_html_output
node_filter_engine -->|"writes filtered output"| node_html_output
node_gravatar_filter -.->|"optional filter"| node_filter_engine
node_syntax_filter -.->|"optional filter"| node_filter_engine
node_response_cache -->|"returns response"| node_browser

click node_cgi "https://github.com/zx2c4/cgit/blob/master/cgit.c"
click node_page_dispatch "https://github.com/zx2c4/cgit/blob/master/cmd.c"
click node_response_cache "https://github.com/zx2c4/cgit/blob/master/cache.c"
click node_runtime_config "https://github.com/zx2c4/cgit/blob/master/configfile.c"
click node_repository_scan "https://github.com/zx2c4/cgit/blob/master/scan-tree.c"
click node_repo_list "https://github.com/zx2c4/cgit/blob/master/ui-repolist.c"
click node_summary "https://github.com/zx2c4/cgit/blob/master/ui-summary.c"
click node_refs_tags "https://github.com/zx2c4/cgit/blob/master/ui-refs.c"
click node_commit_history "https://github.com/zx2c4/cgit/blob/master/ui-log.c"
click node_commit_detail "https://github.com/zx2c4/cgit/blob/master/ui-commit.c"
click node_diff_view "https://github.com/zx2c4/cgit/blob/master/ui-diff.c"
click node_side_by_side "https://github.com/zx2c4/cgit/blob/master/ui-ssdiff.c"
click node_tree_browser "https://github.com/zx2c4/cgit/blob/master/ui-tree.c"
click node_blob_view "https://github.com/zx2c4/cgit/blob/master/ui-blob.c"
click node_blame_view "https://github.com/zx2c4/cgit/blob/master/ui-blame.c"
click node_stats "https://github.com/zx2c4/cgit/blob/master/ui-stats.c"
click node_snapshot "https://github.com/zx2c4/cgit/blob/master/ui-snapshot.c"
click node_plain_file "https://github.com/zx2c4/cgit/blob/master/ui-plain.c"
click node_clone "https://github.com/zx2c4/cgit/blob/master/ui-clone.c"
click node_atom "https://github.com/zx2c4/cgit/blob/master/ui-atom.c"
click node_patch "https://github.com/zx2c4/cgit/blob/master/ui-patch.c"
click node_shared_ui "https://github.com/zx2c4/cgit/blob/master/ui-shared.c"
click node_html_output "https://github.com/zx2c4/cgit/blob/master/html.c"
click node_filter_engine "https://github.com/zx2c4/cgit/blob/master/filter.c"
click node_gravatar_filter "https://github.com/zx2c4/cgit/blob/master/filters/email-gravatar.py"
click node_syntax_filter "https://github.com/zx2c4/cgit/blob/master/filters/syntax-highlighting.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_cgi,node_page_dispatch,node_response_cache,node_browser toneBlue
class node_runtime_config,node_repository_scan,node_git_repositories toneAmber
class node_repo_list,node_summary,node_refs_tags,node_commit_history,node_commit_detail,node_diff_view,node_side_by_side,node_tree_browser,node_blob_view,node_blame_view,node_stats,node_snapshot,node_plain_file,node_clone,node_atom,node_patch toneMint
class node_shared_ui,node_html_output toneRose
class node_filter_engine,node_gravatar_filter,node_syntax_filter toneIndigo
```

## Components

### Request and cache

- [CGI handler](https://github.com/zx2c4/cgit/blob/master/cgit.c): `cgit.c`
- [Page dispatch](https://github.com/zx2c4/cgit/blob/master/cmd.c): `cmd.c`
- [Response cache](https://github.com/zx2c4/cgit/blob/master/cache.c): `cache.c`

### Repository discovery

- [Runtime configuration](https://github.com/zx2c4/cgit/blob/master/configfile.c): `configfile.c`
- [Repository scan](https://github.com/zx2c4/cgit/blob/master/scan-tree.c): `scan-tree.c`

### Repository browsing

- [Repository index](https://github.com/zx2c4/cgit/blob/master/ui-repolist.c): `ui-repolist.c`
- [Repository summary](https://github.com/zx2c4/cgit/blob/master/ui-summary.c): `ui-summary.c`
- [Refs and tags](https://github.com/zx2c4/cgit/blob/master/ui-refs.c): `ui-refs.c`
- [Commit history](https://github.com/zx2c4/cgit/blob/master/ui-log.c): `ui-log.c`
- [Commit details](https://github.com/zx2c4/cgit/blob/master/ui-commit.c): `ui-commit.c`
- [Diff view](https://github.com/zx2c4/cgit/blob/master/ui-diff.c): `ui-diff.c`
- [Side-by-side diff](https://github.com/zx2c4/cgit/blob/master/ui-ssdiff.c): `ui-ssdiff.c`
- [Tree browser](https://github.com/zx2c4/cgit/blob/master/ui-tree.c): `ui-tree.c`
- [Blob view](https://github.com/zx2c4/cgit/blob/master/ui-blob.c): `ui-blob.c`
- [Blame view](https://github.com/zx2c4/cgit/blob/master/ui-blame.c): `ui-blame.c`
- [Repository statistics](https://github.com/zx2c4/cgit/blob/master/ui-stats.c): `ui-stats.c`
- [Source snapshots](https://github.com/zx2c4/cgit/blob/master/ui-snapshot.c): `ui-snapshot.c`
- [Plain files](https://github.com/zx2c4/cgit/blob/master/ui-plain.c): `ui-plain.c`
- [Clone access](https://github.com/zx2c4/cgit/blob/master/ui-clone.c): `ui-clone.c`
- [Atom feed](https://github.com/zx2c4/cgit/blob/master/ui-atom.c): `ui-atom.c`
- [Patch output](https://github.com/zx2c4/cgit/blob/master/ui-patch.c): `ui-patch.c`

### Rendering

- [Shared UI helpers](https://github.com/zx2c4/cgit/blob/master/ui-shared.c): `ui-shared.c`
- [HTML and HTTP output](https://github.com/zx2c4/cgit/blob/master/html.c): `html.c`

### Extensions

- [Content filters](https://github.com/zx2c4/cgit/blob/master/filter.c): `filter.c`
- [Gravatar filter](https://github.com/zx2c4/cgit/blob/master/filters/email-gravatar.py): `filters/email-gravatar.py`
- [Syntax highlighting](https://github.com/zx2c4/cgit/blob/master/filters/syntax-highlighting.py): `filters/syntax-highlighting.py`

### Other components

- **Web client**
- **Git repositories**

## Connections

- Web client → CGI handler: sends request (evidence: `README`)
- CGI handler → Runtime configuration: reads settings (evidence: `cgit.c`)
- CGI handler → Response cache: checks cache (evidence: `cgit.c`)
- CGI handler → Repository scan: refreshes index (evidence: `cgit.c`)
- CGI handler → Page dispatch: dispatches page (evidence: `cmd.c`)
- Repository scan → Git repositories: scans paths (evidence: `scan-tree.c`)
- Page dispatch → Repository index: routes requests (evidence: `cmd.c`)
- Page dispatch → Repository summary: routes requests (evidence: `cmd.c`)
- Page dispatch → Refs and tags: routes requests (evidence: `cmd.c`)
- Page dispatch → Commit history: routes requests (evidence: `cmd.c`)
- Page dispatch → Commit details: routes requests (evidence: `cmd.c`)
- Page dispatch → Diff view: routes requests (evidence: `cmd.c`)
- Page dispatch → Tree browser: routes requests (evidence: `cmd.c`)
- Page dispatch → Blob view: routes requests (evidence: `cmd.c`)
- Page dispatch → Blame view: routes requests (evidence: `cmd.c`)
- Page dispatch → Repository statistics: routes requests (evidence: `cmd.c`)
- Page dispatch → Source snapshots: routes requests (evidence: `cmd.c`)
- Page dispatch → Plain files: routes requests (evidence: `cmd.c`)
- Page dispatch → Clone access: routes requests (evidence: `cmd.c`)
- Page dispatch → Atom feed: routes requests (evidence: `cmd.c`)
- Page dispatch → Patch output: routes requests (evidence: `cmd.c`)
- Diff view → Side-by-side diff: renders variant (evidence: `ui-diff.c`)
- Commit history → Commit details: links commits (evidence: `ui-log.c`)
- Tree browser → Blob view: links files (evidence: `ui-tree.c`)
- Repository index → Shared UI helpers: uses helpers (evidence: `ui-repolist.c`)
- Commit history → Shared UI helpers: uses helpers (evidence: `ui-log.c`)
- Diff view → Shared UI helpers: uses helpers (evidence: `ui-diff.c`)
- Tree browser → Shared UI helpers: uses helpers (evidence: `ui-tree.c`)
- Repository statistics → Shared UI helpers: uses helpers (evidence: `ui-stats.c`)
- Shared UI helpers → HTML and HTTP output: emits markup (evidence: `ui-shared.c`)
- Content filters → HTML and HTTP output: writes filtered output (evidence: `filter.c`)
- Gravatar filter → Content filters: optional filter
- Syntax highlighting → Content filters: optional filter
- Response cache → Web client: returns response (evidence: `README`)
