# frappe/gantt architecture

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

- Interactive diagram: https://gitdiagram.com/frappe/gantt
- Repository: https://github.com/frappe/gantt

## Overview

##### Project type and purpose
- This is an open‑source, frontend JavaScript library (“Frappe Gantt”) for rendering customizable Gantt charts in the browser. It’s not a full‑stack app but a component library that provides an embeddable Gantt chart widget.

##### File structure
- Top‑level:
- styles under src/styles – three theme CSS files
- builder/ – a small demo harness (demo.js, demo.css) used to showcase the library
- tests/ – unit tests for utility functions
- index.html, vite.config.js, package.json, build and config files – build, packaging, CI (publish.yml)

##### Key insights from README
- The library exports a Gantt class (`new Gantt(...)`) that takes a container selector and an array of tasks.
- It’s built to be framework‑agnostic (vanilla JS + CSS + SVG).

##### Main components
a. Core Modules (in src/):
- Gantt Class (index.js) – orchestrator, public API
- Bar Renderer (bar.js) – draws task bars
- SVG Utilities (svg_utils.js) – helper for SVG element creation/manipulation
- Date Utilities (date_utils.js) – date math (intervals, diff, formatting)
- Popup Manager (popup.js) – event handling + dynamic popup generation
- Defaults & Configuration (defaults.js) – default options & override logic
- CSS Themes (dark.css, light.css, gantt.css) – styling layers
b. Build & Packaging
- Vite (vite.config.js) – bundles and outputs ESM and UMD artifacts
- builder/ – demo harness showing integration example
- CI/CD (publish.yml) – on‑push publishing to npm/CDN
c. Tests
- date_utils.test.js – ensures time calculations are correct

##### Relationships and interactions
- Build pipeline: src/ → Vite → dist/frappe-gantt.umd.js + dist/frappe-gantt.esm.js + CSS → published to npm or CDN
- Demo harness: index.html + builder/demo.js/css imports the distributed bundle to illustrate usage

##### Architectural patterns & design principles
- Modular design: each renderer and utility is encapsulated in its own module
- Single Responsibility: date logic, rendering logic, popup logic separated
- Plugin‑style configuration: defaults.js merges with user options to customize behavior
- Build‑time bundling for universal module definition (UMD) and ESM

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Source Modules (src/)"
        subgraph "Rendering Modules"
            Gantt["Gantt Class"]:::render
            Bar["Bar Renderer"]:::render
            Arrow["Arrow Renderer"]:::render
        end
        subgraph "Utilities"
            DateUtils["Date Utilities"]:::util
            SVGUtils["SVG Utilities"]:::util
            Popup["Popup Manager"]:::util
        end
        Defaults["Defaults/Config"]:::config
        subgraph "CSS Themes"
            Dark["dark.css"]:::css
            GanttCSS["gantt.css"]:::css
            Light["light.css"]:::css
        end
    end

    subgraph "Build Pipeline"
        Vite["Vite"]:::build
        Dist["Distribution (dist)"]:::build
        Publish["Publish (npm/CDN)"]:::build
    end

    subgraph "Integration"
        subgraph "Demo Harness"
            DemoJS["demo.js"]:::demo
            DemoCSS["demo.css"]:::demo
        end
        Consumer["User Page"]:::demo
    end

    subgraph "Runtime Flow"
        Gantt -->|"loads defaults"| Defaults
        Gantt -->|"parses tasks"| DateUtils
        Gantt -->|"creates SVG container"| SVGUtils
        Gantt -->|"renders bars"| Bar
        Gantt -->|"renders arrows"| Arrow
        Gantt -->|"attaches popups"| Popup
        SVGUtils -->|"manipulates DOM"| DOM["DOM (SVG Container)"]:::dom
        Defaults <-->|"merge config"| ConsumerOptions["User Options"]:::config
        DOM -->|"applies themes"| CSSThemes["CSS Themes"]:::css
    end

    Tests["Test Suite"]:::test
    Tests -->|"tests"| DateUtils

    CI["CI/CD Pipeline"]:::ci
    CI --> Vite
    CI --> Publish

    Vite -->|builds| Dist
    Dist --> DemoJS
    Dist --> DemoCSS
    Dist --> Consumer

    Consumer -->|instantiates| Gantt

    click Gantt "https://github.com/frappe/gantt/blob/master/src/index.js"
    click Bar "https://github.com/frappe/gantt/blob/master/src/bar.js"
    click Arrow "https://github.com/frappe/gantt/blob/master/src/arrow.js"
    click SVGUtils "https://github.com/frappe/gantt/blob/master/src/svg_utils.js"
    click DateUtils "https://github.com/frappe/gantt/blob/master/src/date_utils.js"
    click Popup "https://github.com/frappe/gantt/blob/master/src/popup.js"
    click Defaults "https://github.com/frappe/gantt/blob/master/src/defaults.js"
    click Dark "https://github.com/frappe/gantt/blob/master/src/styles/dark.css"
    click GanttCSS "https://github.com/frappe/gantt/blob/master/src/styles/gantt.css"
    click Light "https://github.com/frappe/gantt/blob/master/src/styles/light.css"
    click Vite "https://github.com/frappe/gantt/blob/master/vite.config.js"
    click DemoJS "https://github.com/frappe/gantt/blob/master/builder/demo.js"
    click DemoCSS "https://github.com/frappe/gantt/blob/master/builder/demo.css"
    click CI "https://github.com/frappe/gantt/blob/master/.github/workflows/publish.yml"
    click Tests "https://github.com/frappe/gantt/blob/master/tests/date_utils.test.js"
    click Consumer "https://github.com/frappe/gantt/blob/master/index.html"

    classDef render fill:#e0ffe0,stroke:#0f0,stroke-width:1px
    classDef util fill:#e0f7ff,stroke:#00f,stroke-width:1px
    classDef config fill:#ffffc0,stroke:#ff0,stroke-width:1px
    classDef css fill:#f0f0f0,stroke:#888,stroke-width:1px
    classDef build fill:#fff0b3,stroke:#fc0,stroke-width:1px
    classDef demo fill:#ddd,stroke:#666,stroke-width:1px
    classDef test fill:#ccc,stroke:#555,stroke-width:1px
    classDef ci fill:#fff4e6,stroke:#f90,stroke-width:1px
    classDef dom fill:#fff,stroke:#aaa,stroke-width:1px
```
