# gr1shma/notgit architecture

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

- Interactive diagram: https://gitdiagram.com/gr1shma/notgit
- Repository: https://github.com/gr1shma/notgit

## Overview

##### Project Type and Purpose
- This is a CLI-based version-control tool (“notgit”) implemented in Go.
- Purpose: Provide basic Git-like commands (init, add, commit, status, cat-file, config) using a local on-disk object store and index.

##### File Structure Analysis
Top-level:
- cmd/notgit/main.go — CLI entrypoint and argument parsing.
- internal/commands — handlers for each CLI command.
- internal/objects — domain objects (blob, tree, commit, generic object interface).
- internal/repository — repository abstraction: index management and object storage.
- internal/utils — helper routines (configuration, repo detection).

Architectural hints:
- “cmd” vs. “internal” separation: presentation layer vs. implementation.
- Domain model in internal/objects.
- Persistence layer in internal/repository.
- Utilities for cross-cutting concerns in internal/utils.

##### README Insights
- Minimal description: “git but worse.”

a. Main Components
1. CLI Interface (cmd/notgit)
2. Command Dispatcher & Handlers (internal/commands)
3. Domain Model (internal/objects)
4. Repository Layer (internal/repository)
– Index Manager
– Object Storage (on-disk)
5. Utilities (internal/utils)
6. File System (.notgit directory)

b. Component Relationships & Data Flows
- CLI Interface invokes → Command Dispatcher
- Command Dispatcher calls → Specific Command Handler
- Handler interacts with → Repository Layer (read/write index, store objects)
- Repository Layer uses → Domain Model to serialize/deserialize objects
- Domain Model uses → Utilities (e.g., config lookups, repo path discovery)
- Object Storage writes to → .notgit/objects; Index Manager writes to .notgit/index

c. Architectural Patterns & Principles
- Layered architecture: Presentation → Application → Domain → Infrastructure
- Separation of concerns: each command isolated in its own file/package
- Single Responsibility: blob/tree/commit types each handle their own serialization logic
- Dependency direction: higher-level packages depend on lower-level abstractions

d. Key Technologies & Frameworks
- Go modules (go.mod)
- Standard Go libraries for file I/O and CLI flag parsing
- Testing via _test.go files

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        CLI["CLI Entrypoint\ncmd/notgit/main.go"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        CMD_DISP["Command Dispatcher\ninternal/commands/command.go"]:::application
        ADD["Add Handler\ninternal/commands/add.go"]:::application
        COMMIT["Commit Handler\ninternal/commands/commit.go"]:::application
        STATUS["Status Handler\ninternal/commands/status.go"]:::application
        CONFIG_CMD["Config Handler\ninternal/commands/config.go"]:::application
        INIT["Init Handler\ninternal/commands/init.go"]:::application
        CATFILE["Cat-File Handler\ninternal/commands/cat-file.go"]:::application
    end

    %% Domain Layer
    subgraph "Domain Layer"
        OBJ["Object Interface\ninternal/objects/object.go"]:::domain
        BLOB["Blob\ninternal/objects/blob/blob.go"]:::domain
        TREE["Tree\ninternal/objects/tree/tree.go"]:::domain
        CMTOBJ["Commit Obj\ninternal/objects/commit/commit.go"]:::domain
    end

    %% Infrastructure Layer
    subgraph "Infrastructure Layer"
        REPO["Repository\ninternal/repository/repo.go"]:::infrastructure
        INDEX["Index Manager\ninternal/repository/index.go"]:::infrastructure
        OBJSTORE["Object Storage\ninternal/repository/objects_storage.go"]:::infrastructure
        UTIL_CFG["Config Utils\ninternal/utils/config_utils.go"]:::infrastructure
        UTIL_REPO["Repo Utils\ninternal/utils/repo.go"]:::infrastructure
    end

    %% External Filesystem
    subgraph "Filesystem (.notgit)"
        OZ[".notgit/objects/"]:::external
        IDXFILE[".notgit/index"]:::external
        CFGFILE[".notgit/config"]:::external
    end

    %% Relationships
    CLI -->|"parse args"| CMD_DISP
    CMD_DISP -->|"dispatch"| ADD
    CMD_DISP -->|"dispatch"| COMMIT
    CMD_DISP -->|"dispatch"| STATUS
    CMD_DISP -->|"dispatch"| CONFIG_CMD
    CMD_DISP -->|"dispatch"| INIT
    CMD_DISP -->|"dispatch"| CATFILE

    ADD -->|"calls"| REPO
    COMMIT -->|"calls"| REPO
    STATUS -->|"calls"| REPO
    CONFIG_CMD -->|"calls"| REPO
    INIT -->|"calls"| REPO
    CATFILE -->|"calls"| REPO

    REPO -->|"uses"| INDEX
    REPO -->|"uses"| OBJSTORE
    REPO -->|"interacts with"| OBJ
    REPO -->|"interacts with"| BLOB
    REPO -->|"interacts with"| TREE
    REPO -->|"interacts with"| CMTOBJ

    OBJSTORE -->|-->| OZ
    INDEX -->|-->| IDXFILE
    UTIL_CFG -->|uses| CFGFILE
    UTIL_CFG -->|called by| REPO
    UTIL_REPO -->|called by| REPO
    UTIL_CFG -->|called by| OBJ
    UTIL_REPO -->|called by| OBJ

    %% Click Events
    click CLI "https://github.com/gr1shma/notgit/blob/master/cmd/notgit/main.go"
    click CMD_DISP "https://github.com/gr1shma/notgit/blob/master/internal/commands/command.go"
    click ADD "https://github.com/gr1shma/notgit/blob/master/internal/commands/add.go"
    click COMMIT "https://github.com/gr1shma/notgit/blob/master/internal/commands/commit.go"
    click STATUS "https://github.com/gr1shma/notgit/blob/master/internal/commands/status.go"
    click CONFIG_CMD "https://github.com/gr1shma/notgit/blob/master/internal/commands/config.go"
    click INIT "https://github.com/gr1shma/notgit/blob/master/internal/commands/init.go"
    click CATFILE "https://github.com/gr1shma/notgit/blob/master/internal/commands/cat-file.go"
    click OBJ "https://github.com/gr1shma/notgit/blob/master/internal/objects/object.go"
    click BLOB "https://github.com/gr1shma/notgit/blob/master/internal/objects/blob/blob.go"
    click TREE "https://github.com/gr1shma/notgit/blob/master/internal/objects/tree/tree.go"
    click CMTOBJ "https://github.com/gr1shma/notgit/blob/master/internal/objects/commit/commit.go"
    click REPO "https://github.com/gr1shma/notgit/blob/master/internal/repository/repo.go"
    click INDEX "https://github.com/gr1shma/notgit/blob/master/internal/repository/index.go"
    click OBJSTORE "https://github.com/gr1shma/notgit/blob/master/internal/repository/objects_storage.go"
    click UTIL_CFG "https://github.com/gr1shma/notgit/blob/master/internal/utils/config_utils.go"
    click UTIL_REPO "https://github.com/gr1shma/notgit/blob/master/internal/utils/repo.go"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef application fill:#90EE90,stroke:#333,stroke-width:1px
    classDef domain fill:#FFA500,stroke:#333,stroke-width:1px
    classDef infrastructure fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
