# drhsqlite/fossil-mirror architecture

> Architecture diagram of the GitHub repository drhsqlite/fossil-mirror, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/drhsqlite/fossil-mirror
- Repository: https://github.com/drhsqlite/fossil-mirror

## Overview

##### Main Components
- Repository Engine & Core Library:
– Located in the “src” directory, this core contains all the commands (e.g., checkin, checkout, diff, merge, branching) along with the logic for delta encoding, repository storage, and synchronization.
- Command-Line Interface (CLI):
– Fossil’s CLI calls into the core libraries and executes version control operations. Many of the “.c” files in “src” (like main.c, login.c, diff.c, merge.c, etc.) and accompanying scripts support this.
- Web Interface & HTTP/CGI Module:
– Fossil runs as its own web server and presents a web UI. Files under “src” (e.g., cgi.c, http.c, http_ssl.c) and the “www” directory (which holds various wiki pages, JSON APIs, and server configuration documents) indicate this dual usage.
- Database / Repository Storage:
- External Tools & Utilities:
– The “tools” directory includes various conversion utilities (e.g., cvs2fossil), build utilities, and scripts for maintenance and automation.
- Compatibility & Auxiliary Libraries:
– The “compat” folder provides bundled versions of third-party libraries such as zlib and Tcl, which are essential for compression and script execution functions.

##### Relationships and Interactions
- User Interfaces (CLI & Web UI) act as entry points that invoke corresponding commands in the core repository engine.
- The core repository engine communicates with external libraries (e.g., zlib for compression and Tcl scripts for automation/merging) that are bundled in “compat” and “autosetup” respectively.
- The “tools” and “extsrc” directories represent auxiliary components for tasks such as repository maintenance, migration, or additional scripting features.
- The web interface also exposes a REST/JSON API (as seen in the “www/json-api” folder) to support programmatic access.

##### Architectural Patterns and Design Principles
- Modular Monolith: Despite being a single repository, Fossil logically separates functionality into discrete modules (UI, core logic, database, and external integrations) which communicate via clear APIs.
- Self-Hosting & Integration: The architecture supports self-hosting (it serves its own web pages and documentation) so the web server component is embedded.
- Extensibility: The use of external tools and compatibility layers suggests plug-in points where additional functionality or alternative libraries can be integrated.
- Robustness via Extensive Testing: The “test” directory indicates a rigorous testing strategy, which should be noted as part of the quality assurance in the overall architecture.

##### Relevant Technologies
- Language & Build: Primarily C (with auxiliary Tcl scripts) and make/CMake based build configuration.
- Database: Embedded SQLite (implied by the README) for repository storage.
- Libraries: zlib (for compression), Tcl (for scripting), and potentially CSS/JS for the web UI.
- Web Protocols: HTTP/HTTPS handling as indicated by the “http.c” and “http_ssl.c” files.
- Version Control components: Core command handlers for operations like checkin, diff, merge, branch, as detailed in “src”.

## Diagram (Mermaid)

```mermaid
flowchart TB
    User["User"]:::user

    subgraph "User Interfaces"
        CLI["CLI (Command-Line Interface)"]:::interface
        Web_UI["Web Interface (HTTP/CGI)"]:::interface
    end

    Core_Engine["Repository Engine & Core Library"]:::core
    Embedded_DB["Embedded SQLite Database"]:::database
    Compat_Libraries["Compatibility & Auxiliary Libraries"]:::external
    External_Tools["External Tools & Utilities"]:::external

    User --> CLI
    User --> Web_UI
    CLI -->|"invokes"| Core_Engine
    Web_UI -->|"invokes"| Core_Engine
    Core_Engine -->|"stores data"| Embedded_DB
    Core_Engine -->|"uses"| Compat_Libraries
    Core_Engine -->|"integrates"| External_Tools

    click CLI "https://github.com/drhsqlite/fossil-mirror/blob/master/src/main.c"
    click Web_UI "https://github.com/drhsqlite/fossil-mirror/blob/master/src/cgi.c"
    click Core_Engine "https://github.com/drhsqlite/fossil-mirror/tree/master/src"
    click Embedded_DB "https://github.com/drhsqlite/fossil-mirror/blob/master/extsrc/sqlite3.c"
    click External_Tools "https://github.com/drhsqlite/fossil-mirror/tree/master/tools"
    click Compat_Libraries "https://github.com/drhsqlite/fossil-mirror/tree/master/compat"

    classDef user fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef interface fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef core fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef database fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
    classDef external fill:#D1C4E9,stroke:#512DA8,stroke-width:2px;
```
