# progate/git-intern-2025-term1 architecture

> Architecture diagram of the GitHub repository progate/git-intern-2025-term1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/progate/git-intern-2025-term1
- Repository: https://github.com/progate/git-intern-2025-term1

## Overview

##### Main Components
- CLI Entry Point: The binary in the bin/ directory (bin/main.mjs) serves as the entry point when the “mygit” command is executed. This component is responsible for parsing the user’s command-line input and dispatching it to the appropriate command implementation.
- Command Handlers: In src/commands, you have several files (add.ts, commit.ts, hello.ts, log.ts) that implement different commands. These modules each encapsulate a specific command’s functionality and interact with the core logic.
- Core Logic Modules: The src/ directory also includes key files such as mygit.ts, gitIndex.ts, commit.ts, tree.ts, and blob.ts. These contain the fundamental business logic mimicking Git functionalities (like handling commits, indexing, and managing file trees).
- Type Definitions and Interfaces: Located in src/types, these files (for blob, command, commit, etc.) help maintain clarity in the structure and ensure type safety. They are critical for understanding the data models used across the project.
- Utility Functions: The src/utils folder (with files like logger.ts) provides cross-cutting concerns such as logging and error handling.
- Testing: Although not isolated in a dedicated “tests” directory, the presence of mygit.test.ts indicates that unit tests help validate the core functionality of the system.
- Configuration and Build Tools: Files like tsconfig.json, package.json, eslint.config.js, and prettier.config.js indicate the use of TypeScript, code quality, and formatting tools. While these are not “runtime components,” they are essential for the development and build lifecycle.

##### Relationships and Interactions
- The CLI entry (bin/main.mjs) interprets user commands and delegates processing to the relevant command module in src/commands.
- Command modules interact with the core logic (e.g., mygit.ts, gitIndex.ts), which in turn may update or query the internal state of the repository simulation (commits, index, trees, blobs).
- The type definitions provide a contract between these components, ensuring that data objects like commits and blobs are consistently used.
- Utility modules provide shared services such as logging, which can be used across command handlers and core logic components.
- Additionally, there are debug scripts in src/scripts/debug to test or inspect parts of the core logic (e.g., tree.ts and commit.ts).

##### Architectural Patterns or Design Principles
- Modularity: Responsibilities are divided across command modules and core utilities to keep each component focused on a specific function.
- Separation of Concerns: The project distinguishes between processing user commands, core functionality (like managing a simplified Git index), and peripheral concerns (utilities, types, and tests).
- CLI Pattern: A common pattern for command-line tools where the main binary parses input and directs the flow to specific subcommands.
- Layered Structure: There is a clear distinction between the presentation (CLI entry point), business logic (command implementations and core modules), and data models (type definitions).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    CLIEntrypoint["CLI Entrypoint<br>(bin/main.mjs)"] 
    click CLIEntrypoint "https://github.com/progate/git-intern-2025-term1/blob/main/bin/main.mjs"
    
    %% Command Handlers
    subgraph "Command Handlers"
        CMD_ADD["add Command<br>(src/commands/add.ts)"]
        click CMD_ADD "https://github.com/progate/git-intern-2025-term1/blob/main/src/commands/add.ts"
        CMD_COMMIT["commit Command<br>(src/commands/commit.ts)"]
        click CMD_COMMIT "https://github.com/progate/git-intern-2025-term1/blob/main/src/commands/commit.ts"
        CMD_HELLO["hello Command<br>(src/commands/hello.ts)"]
        click CMD_HELLO "https://github.com/progate/git-intern-2025-term1/blob/main/src/commands/hello.ts"
        CMD_LOG["log Command<br>(src/commands/log.ts)"]
        click CMD_LOG "https://github.com/progate/git-intern-2025-term1/blob/main/src/commands/log.ts"
    end

    %% Core Logic Modules
    subgraph "Core Logic – Git Operations"
        CORE_MYGIT["mygit.ts<br>(src/mygit.ts)"]
        click CORE_MYGIT "https://github.com/progate/git-intern-2025-term1/blob/main/src/mygit.ts"
        CORE_GITINDEX["gitIndex.ts<br>(src/gitIndex.ts)"]
        click CORE_GITINDEX "https://github.com/progate/git-intern-2025-term1/blob/main/src/gitIndex.ts"
        CORE_COMMIT["commit.ts<br>(src/commit.ts)"]
        click CORE_COMMIT "https://github.com/progate/git-intern-2025-term1/blob/main/src/commit.ts"
        CORE_TREE["tree.ts<br>(src/tree.ts)"]
        click CORE_TREE "https://github.com/progate/git-intern-2025-term1/blob/main/src/tree.ts"
        CORE_BLOB["blob.ts<br>(src/blob.ts)"]
        click CORE_BLOB "https://github.com/progate/git-intern-2025-term1/blob/main/src/blob.ts"
    end

    %% Type Definitions
    TypeDefs["Type Definitions<br>(src/types)"]
    click TypeDefs "https://github.com/progate/git-intern-2025-term1/tree/main/src/types"

    %% Utility Services
    Logger["Utility: logger.ts<br>(src/utils/logger.ts)"]
    click Logger "https://github.com/progate/git-intern-2025-term1/blob/main/src/utils/logger.ts"
    
    %% Testing
    Test["Testing<br>(src/mygit.test.ts)"]
    click Test "https://github.com/progate/git-intern-2025-term1/blob/main/src/mygit.test.ts"
    
    %% Configuration and Build Tools
    subgraph "Configuration & Build Tools"
        Conf_tsconfig["tsconfig.json"]
        click Conf_tsconfig "https://github.com/progate/git-intern-2025-term1/blob/main/tsconfig.json"
        Conf_package["package.json"]
        click Conf_package "https://github.com/progate/git-intern-2025-term1/blob/main/package.json"
        Conf_eslint["eslint.config.js"]
        click Conf_eslint "https://github.com/progate/git-intern-2025-term1/blob/main/eslint.config.js"
        Conf_prettier["prettier.config.js"]
        click Conf_prettier "https://github.com/progate/git-intern-2025-term1/blob/main/prettier.config.js"
    end

    %% Relationships
    CLIEntrypoint -->|"dispatches"| CMD_ADD
    CLIEntrypoint -->|"dispatches"| CMD_COMMIT
    CLIEntrypoint -->|"dispatches"| CMD_HELLO
    CLIEntrypoint -->|"dispatches"| CMD_LOG

    CMD_ADD -->|"stages changes"| CORE_GITINDEX
    CMD_COMMIT -->|"creates commit"| CORE_COMMIT
    CMD_LOG -->|"queries history"| CORE_MYGIT
    CMD_HELLO -->|"triggers action"| CORE_MYGIT

    %% Core modules interacting with utility and type definitions
    CORE_MYGIT -->|"uses"| TypeDefs
    CORE_GITINDEX -->|"uses"| TypeDefs
    CORE_COMMIT -->|"uses"| TypeDefs
    CORE_TREE -->|"uses"| TypeDefs
    CORE_BLOB -->|"uses"| TypeDefs

    CORE_MYGIT -->|"logs via"| Logger
    CORE_GITINDEX -->|"logs via"| Logger
    CORE_COMMIT -->|"logs via"| Logger
    CORE_TREE -->|"logs via"| Logger
    CORE_BLOB -->|"logs via"| Logger

    %% Testing validates core logic
    CORE_MYGIT -->|"validated by"| Test
    CORE_GITINDEX -->|"validated by"| Test
    CORE_COMMIT -->|"validated by"| Test
    CORE_TREE -->|"validated by"| Test
    CORE_BLOB -->|"validated by"| Test

    %% Styling
    classDef cli fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef command fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef types fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef util fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef test fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef config fill:#D8BFD8,stroke:#333,stroke-width:2px;

    class CLIEntrypoint cli;
    class CMD_ADD,CMD_COMMIT,CMD_HELLO,CMD_LOG command;
    class CORE_MYGIT,CORE_GITINDEX,CORE_COMMIT,CORE_TREE,CORE_BLOB core;
    class TypeDefs types;
    class Logger util;
    class Test test;
    class Conf_tsconfig,Conf_package,Conf_eslint,Conf_prettier config;
```
