# dvtdat/dvtdit architecture

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

- Interactive diagram: https://gitdiagram.com/dvtdat/dvtdit
- Repository: https://github.com/dvtdat/dvtdit

## Overview

##### Project type and purpose
- This is a small, single-binary command-line application that re-implements core Git functionality for educational purposes (a Git clone). The README confirms: "educational project that want to replicate git and its functionalities."
- It's a C++ project (CMake build) that implements command handlers for init, add, commit, ls-files and a set of utility modules for hashing, binary I/O, index handling, and file utilities.

##### High-level analysis of the file structure
- Top-level:
- CMakeLists.txt — build configuration (C++ project).
- readme.md — project description.
- .gitignore, .vscode — tooling configs.
- src/:
- main.cpp — CLI entry point / dispatcher.
- src/commands/:
- init.cpp, add.cpp, commit.cpp, ls-files.cpp — each command is implemented as its own module (command pattern / handler per command).
- src/utils/:
- binary_io.cpp / .h — reading/writing object files or binary index structures.
- file_utils.cpp / .h — filesystem helpers (read/write files, directory handling).
- hash.cpp / .h and sha1.cpp / .h — cryptographic hashing (SHA-1) used to name objects.
- index_utils.cpp / .h — staging/index file read/write and manipulation.
- types.h — shared type definitions (structs, constants, enums).
- Pattern indications:
- Command separation suggests a CLI "dispatcher -> command handler" architecture.
- Utilities form layered services used by commands.
- There is likely a storage layer (on-disk repository structure similar to .git: objects, index, refs) even if the exact directory names aren't shown in the tree — index_utils and binary_io indicate an on-disk index/objects format.
- Deployment/build:
- CMakeLists.txt indicates build via CMake to produce an executable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top: User / Terminal
    User["User / Terminal"]:::external

    %% CLI Dispatcher
    CLI["CLI Dispatcher<br/><i>src/main.cpp</i>"]:::cli

    %% Commands block (vertical list)
    subgraph "Command Handlers"
        direction TB
        CMD_INIT["init<br/><i>src/commands/init.cpp</i>"]:::command
        CMD_ADD["add<br/><i>src/commands/add.cpp</i>"]:::command
        CMD_COMMIT["commit<br/><i>src/commands/commit.cpp</i>"]:::command
        CMD_LS["ls-files<br/><i>src/commands/ls-files.cpp</i>"]:::command
    end

    %% Utilities / Services layer (stacked)
    subgraph "Utilities / Services"
        direction TB
        UTIL_HASH["Hashing (wrapper)<br/><i>src/utils/hash.cpp/h</i>"]:::util
        UTIL_SHA1["SHA-1 impl.<br/><i>src/utils/sha1.cpp/h</i>"]:::util
        UTIL_BINIO["Binary I/O<br/><i>src/utils/binary_io.cpp/h</i>"]:::util
        UTIL_INDEX["Index Management<br/><i>src/utils/index_utils.cpp/h</i>"]:::util
        UTIL_FILE["File System Helpers<br/><i>src/utils/file_utils.cpp/h</i>"]:::util
        TYPES["Shared Types / Interfaces<br/><i>src/utils/types.h</i>"]:::types
    end

    %% On-disk storage and workspace (stacked)
    subgraph "Storage & Workspace"
        direction TB
        WORKDIR["Working Directory / Files"]:::fs
        REPO["Repository Storage (.git-like)"]:::storage
        REPO_OBJS["objects/ (blobs/trees/commits)"]:::storage
        REPO_INDEX["index (staging file)"]:::storage
        REPO_REFS["refs/ (HEAD, branches)"]:::storage
    end

    %% Build / Docs
    CMAKE["CMake / Build<br/><i>CMakeLists.txt</i>"]:::build
    README["Project README<br/><i>readme.md</i>"]:::doc

    %% Top-down flow (vertical)
    User -->|"runs executable / types command"| CLI
    CLI -->|"dispatches command"| CMD_INIT
    CLI -->|"dispatches command"| CMD_ADD
    CLI -->|"dispatches command"| CMD_COMMIT
    CLI -->|"dispatches command"| CMD_LS

    %% Commands depend on utilities (stacked arrows)
    CMD_INIT -->|"create repo dirs / files"| UTIL_FILE
    CMD_INIT -->|"write structures (binary IO)"| UTIL_BINIO

    CMD_ADD -->|"read file bytes"| UTIL_FILE
    CMD_ADD -->|"compute hash (SHA-1)"| UTIL_HASH
    UTIL_HASH -->|"uses SHA-1 impl"| UTIL_SHA1
    CMD_ADD -->|"write object blob"| UTIL_BINIO
    CMD_ADD -->|"update staging index"| UTIL_INDEX
    UTIL_INDEX -->|"persists index file"| UTIL_BINIO

    CMD_COMMIT -->|"read index (staging)"| UTIL_INDEX
    CMD_COMMIT -->|"create tree/commit objects"| UTIL_BINIO
    CMD_COMMIT -->|"compute object ids"| UTIL_HASH
    CMD_COMMIT -->|"update refs (HEAD)"| UTIL_FILE

    CMD_LS -->|"read index entries"| UTIL_INDEX
    CMD_LS -->|"output file list to CLI"| CLI

    %% Utilities interact with OS-level resources
    UTIL_FILE -->|"reads/writes files"| WORKDIR
    UTIL_BINIO -->|"reads/writes objects & index files"| REPO_OBJS
    UTIL_BINIO -->|"writes index file"| REPO_INDEX
    UTIL_FILE -->|"updates refs files"| REPO_REFS

    %% Relationships within storage
    REPO --> REPO_OBJS
    REPO --> REPO_INDEX
    REPO --> REPO_REFS

    %% Types used across modules (dashed dependency)
    TYPES -.-> CMD_INIT
    TYPES -.-> CMD_ADD
    TYPES -.-> CMD_COMMIT
    TYPES -.-> CMD_LS
    TYPES -.-> UTIL_INDEX
    TYPES -.-> UTIL_BINIO

    %% Build & Docs connections
    CMAKE -->|"builds executable"| CLI
    README -->|"project purpose"| CLI

    %% Annotated example flows (vertical notes to the side)
    subgraph "Example Flow: add (file -> blob -> index)"
        direction TB
        A1["1) CMD_ADD reads file bytes from Working Directory"]:::note
        A2["2) UTIL_HASH / SHA-1 computes hash (object id)"]:::note
        A3["3) UTIL_BINIO writes blob into objects/"]:::note
        A4["4) UTIL_INDEX updates index (staging) and persists via Binary I/O"]:::note
    end
    CMD_ADD --> A1
    A1 --> UTIL_HASH
    UTIL_HASH --> A2
    A2 --> UTIL_BINIO
    UTIL_BINIO --> A3
    UTIL_BINIO --> UTIL_INDEX
    UTIL_INDEX --> A4
    A4 --> REPO_INDEX

    subgraph "Example Flow: commit (index -> commit -> refs)"
        direction TB
        B1["1) CMD_COMMIT reads index via UTIL_INDEX"]:::note
        B2["2) UTIL_BINIO + UTIL_HASH build tree and commit objects"]:::note
        B3["3) UTIL_FILE updates refs/HEAD"]:::note
    end
    CMD_COMMIT --> B1
    B1 --> UTIL_BINIO
    UTIL_BINIO --> B2
    B2 --> UTIL_FILE
    UTIL_FILE --> B3
    B3 --> REPO_REFS

    %% Click events mapping to project files (paths only)
    click CLI "https://github.com/dvtdat/dvtdit/blob/main/src/main.cpp"
    click CMD_INIT "https://github.com/dvtdat/dvtdit/blob/main/src/commands/init.cpp"
    click CMD_ADD "https://github.com/dvtdat/dvtdit/blob/main/src/commands/add.cpp"
    click CMD_COMMIT "https://github.com/dvtdat/dvtdit/blob/main/src/commands/commit.cpp"
    click CMD_LS "https://github.com/dvtdat/dvtdit/blob/main/src/commands/ls-files.cpp"
    click UTIL_BINIO "https://github.com/dvtdat/dvtdit/blob/main/src/utils/binary_io.cpp"
    click UTIL_BINIO "https://github.com/dvtdat/dvtdit/blob/main/src/utils/binary_io.h"
    click UTIL_FILE "https://github.com/dvtdat/dvtdit/blob/main/src/utils/file_utils.cpp"
    click UTIL_FILE "https://github.com/dvtdat/dvtdit/blob/main/src/utils/file_utils.h"
    click UTIL_HASH "https://github.com/dvtdat/dvtdit/blob/main/src/utils/hash.cpp"
    click UTIL_HASH "https://github.com/dvtdat/dvtdit/blob/main/src/utils/hash.h"
    click UTIL_SHA1 "https://github.com/dvtdat/dvtdit/blob/main/src/utils/sha1.cpp"
    click UTIL_SHA1 "https://github.com/dvtdat/dvtdit/blob/main/src/utils/sha1.h"
    click UTIL_INDEX "https://github.com/dvtdat/dvtdit/blob/main/src/utils/index_utils.cpp"
    click UTIL_INDEX "https://github.com/dvtdat/dvtdit/blob/main/src/utils/index_utils.h"
    click TYPES "https://github.com/dvtdat/dvtdit/blob/main/src/utils/types.h"
    click CMAKE "https://github.com/dvtdat/dvtdit/blob/main/CMakeLists.txt"
    click README "https://github.com/dvtdat/dvtdit/blob/main/readme.md"

    %% Styling / Legend
    classDef external fill:#cbeafe,stroke:#2b6cb0,stroke-width:1px,color:#042a56;
    classDef cli fill:#bfdbfe,stroke:#1e40af,stroke-width:1px,color:#072146;
    classDef command fill:#bbf7d0,stroke:#16a34a,stroke-width:1px,color:#064e3b;
    classDef util fill:#ffdca8,stroke:#c2410c,stroke-width:1px,color:#4c1d03;
    classDef types fill:#f3e8ff,stroke:#7c3aed,stroke-width:1px,color:#2a0944;
    classDef storage fill:#f4e1d2,stroke:#a35709,stroke-width:1px,color:#3a1700;
    classDef fs fill:#e5e7eb,stroke:#6b7280,stroke-width:1px,color:#111827;
    classDef build fill:#e6f4ea,stroke:#0f766e,stroke-width:1px,color:#04281f;
    classDef doc fill:#f8fafc,stroke:#475569,stroke-width:1px,color:#0f1724;
    classDef note fill:#fff7ed,stroke:#92400e,stroke-width:1px,color:#3b1700;

    %% Ensure classes applied to nodes
    class User external
    class CLI cli
    class CMD_INIT,CMD_ADD,CMD_COMMIT,CMD_LS command
    class UTIL_HASH,UTIL_SHA1,UTIL_BINIO,UTIL_INDEX,UTIL_FILE util
    class TYPES types
    class REPO,REPO_OBJS,REPO_INDEX,REPO_REFS storage
    class WORKDIR fs
    class CMAKE build
    class README doc
    class A1,A2,A3,A4,B1,B2,B3 note
```
