# ben174/git-draw architecture

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

- Interactive diagram: https://gitdiagram.com/ben174/git-draw
- Repository: https://github.com/ben174/git-draw

## Overview

##### Project Type and Purpose
- Project Type: A Chrome extension that adds drawing functionality to a GitHub heatmap.

##### Analyzing the File Structure
- Top-level files/directories of interest:
- LICENSE and README.md: Standard project documentation.
- deploy-extension.sh: A script likely for packaging or deploying the extension.
- The “extension” directory: Contains all the Chrome extension source code.
- manifest.json: Defines the extension’s configuration (permissions, content scripts, etc.)
- src folder: Organized into several subdirectories:
▪ css/inject.css: Provides the styling for injected UI elements.
▪ inject directory:
– inject.js: Likely contains the core logic for injecting elements into a GitHub page.
– static.js: Possibly includes supporting functions or static assets.
▪ lib: Potentially holds additional JavaScript libraries or helper modules.
- media folder: Contains a demo video that illustrates how the extension works.

##### Key Components & Relationships
- Chrome Extension Core:
- manifest.json: The configuration file that instructs Chrome what files to run and what permissions are required.
- Content Scripts & Injection Mechanism:
- inject.js and static.js: These files are responsible for injecting the drawing UI onto GitHub pages.
- css/inject.css: Provides styling to the UI components injected into the page.
- Additional Libraries:
- Files located under “src/lib”: Supporting functions to handle tasks like event handling, drawing logic, or export operations.
- Deployment/Packaging:
- deploy-extension.sh: A script that packages or deploys the extension to the Chrome Web Store.

a. And Label Main Components:
▪ “Injection Scripts”: inject.js and static.js.
▪ “CSS Styles”: inject.css.

b. Relationships and Data Flow:
- “CSS Styles” to “Injection Scripts” to indicate that styling is applied during UI rendering.
- Data flows from user actions on the drawn interface (e.g., drawing gestures or export command) to the export functionality, which creates the git commit script.

c. Architectural Patterns and Principles:
- That the project leverages the standard Chrome extension architecture: an entry point via manifest.json instructs Chrome how to load resources.
- Separation of presentation (CSS design), behavior (JS injection scripts), and configuration (manifest.json).
- If applicable, mention the modular design of content scripts versus static libraries. This separation supports better debugging and potential future extensions.

d. Relevant Technologies:
- Chrome Extension API: Used primarily for injecting the scripts and managing extension settings.
- HTML/CSS/JavaScript: Fundamental to how the extension interacts with the GitHub web page.
- Git command log and scripting: While not directly shown through a backend, it’s crucial to note that the exported drawing becomes a git commit log script.

##### Detail and Clarity
- The goal is to capture every essential architectural element, so be as granular as possible.
- Use annotations if needed to briefly describe each component’s role.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Chrome Extension Core
    subgraph "Chrome Extension Core"
        manifest["manifest.json"]:::config
        icons["icons"]:::config
    end

    %% Content Scripts Layer
    subgraph "Content Scripts"
        subgraph "Injection Scripts"
            inject_js["inject.js"]:::ui
            static_js["static.js"]:::ui
        end
        css_styles["inject.css"]:::ui
    end

    %% Supporting Modules and Other Components
    lib["Libraries/Supporting Modules"]:::library
    deploy["Deployment/Packaging (deploy-extension.sh)"]:::deploy
    demo["Media/Demo Assets (demo-video.m4v)"]:::media

    %% External Entities
    gh["GitHub Page (Heatmap)"]:::external
    exportFunc["Export Functionality (Commit Log Script)"]:::external
    store["Chrome Web Store"]:::external

    %% Relationships
    %% manifest.json launches content scripts
    manifest -->|"launches"| inject_js
    manifest -->|"launches"| static_js
    manifest -->|"launches"| css_styles

    %% Content scripts inject UI into GitHub Page (Heatmap)
    inject_js -->|"injects UI"| gh
    static_js -->|"supports UI"| gh
    css_styles -->|"applies styling"| gh

    %% User interactions on GitHub Page trigger export functionality
    gh -->|"user action"| exportFunc

    %% Libraries support the export functionality
    lib -->|"provides helpers"| exportFunc

    %% Deployment scripts package the extension for distribution
    deploy -->|"packages for"| store

    %% Legend
    subgraph "Legend"
        LEG1["Configuration Files (manifest, icons)"]:::config
        LEG2["UI Components (JS, CSS)"]:::ui
        LEG3["Supporting Libraries"]:::library
        LEG4["Deployment Script"]:::deploy
        LEG5["Media Assets"]:::media
        LEG6["External Entities"]:::external
    end

    %% Click Events
    click manifest "https://github.com/ben174/git-draw/blob/master/extension/manifest.json"
    click icons "https://github.com/ben174/git-draw/tree/master/extension/icons"
    click inject_js "https://github.com/ben174/git-draw/blob/master/extension/src/inject/inject.js"
    click static_js "https://github.com/ben174/git-draw/blob/master/extension/src/inject/static.js"
    click css_styles "https://github.com/ben174/git-draw/blob/master/extension/src/css/inject.css"
    click lib "https://github.com/ben174/git-draw/tree/master/extension/src/lib"
    click deploy "https://github.com/ben174/git-draw/blob/master/deploy-extension.sh"
    click demo "https://github.com/ben174/git-draw/blob/master/media/demo-video.m4v"

    %% Style Definitions
    classDef config fill:#ffeb3b,stroke:#000,stroke-width:2px;
    classDef ui fill:#c8e6c9,stroke:#000,stroke-width:2px;
    classDef library fill:#bbdefb,stroke:#000,stroke-width:2px;
    classDef deploy fill:#f8bbd0,stroke:#000,stroke-width:2px;
    classDef media fill:#d1c4e9,stroke:#000,stroke-width:2px;
    classDef external fill:#ffe0b2,stroke:#000,stroke-width:2px;
    classDef legend fill:#e0e0e0,stroke:#000,stroke-width:1px;
```
