# marigold-ui/marigold architecture

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

- Interactive diagram: https://gitdiagram.com/marigold-ui/marigold
- Repository: https://github.com/marigold-ui/marigold

## Overview

##### Project Type and Purpose
- External dependencies like react-aria (for accessibility) and Tailwind CSS (for styling) are central to the project.

##### Analyzing the File Structure
- Top-level directories like “packages”, “docs”, “themes”, “config” and “scripts” indicate the clear separation of concerns.
- Under “packages”, you see distinct packages:
- components – contains the actual UI implementations.
- system – provides lower-level theme and style management utilities and hooks.
- types – contains shared type definitions.
- theme-plugins – holds plugins to extend theme capabilities.
- The “docs” directory represents a documentation site (likely powered by Next.js or similar) to showcase the components via Storybook and live examples.
- “themes” includes multiple subthemes (theme-b2b, theme-core, theme-docs, theme-rui) that define various design tokens, style overrides, and CSS configurations.
- Configuration (such as eslint, jest, Prettier, Tailwind) and CI/CD workflows (.github directory) suggest a strongly integrated development and deployment environment.
- A monorepo management tool (pnpm workspaces indicated by “pnpm-workspace.yaml” and “turbo.json”) is used to coordinate package interdependencies and build processes.

a. Main Components:
- Monorepo Root:
- A central repository managing all the packages, configurations, and scripts.
- Packages Layer:
- Components Package: The library of React UI components (Accordion, Button, Input, etc.).
- System Package: Milestones for theming, custom hooks, and low-level design tokens.
- Types Package: Shared type definitions (for TypeScript consistency).
- Theme-Plugins Package: Plugins to extend or customize Tailwind-based themes.
- Themes:
- Several theme implementations (e.g., theme-b2b, theme-core) that provide theme-specific style tokens.
- Documentation & Developer Tooling:
- Docs Application: A Next.js (or similar) site that consumes the components to showcase examples (via Storybook & live demos).
- CI/CD and tooling: GitHub workflows and configuration files for building, linting, type checking, and testing.
- External Dependencies:
- React and react-aria (for accessible UI behaviors).
- Tailwind CSS (for styling).

b. Relationships & Interactions:
- The Components package relies on the System package for shared theming and low-level utilities.
- The MarigoldProvider (from the components package) consumes a theme (from one of the Themes packages) and passes it down via React Context.
- Docs and Storybook use the components along with the provider to render a live component library.
- The Types package is consumed by all other packages to share common TypeScript interfaces.
- Theme plugins augment and customize the Tailwind and theming logic used across components.
- CI/CD workflows (in .github/workflows) coordinate testing, linting, releases, and code quality analysis on commit/pull request.

c. Architectural Patterns:
- Modular / Monorepo Architecture: Each package is self-contained, improving maintainability and versioning.
- Component-Based Design: The UI is built using reusable React components, each living in its own directory.
- Context and Provider Pattern: The MarigoldProvider wraps applications to inject the theme and configuration.
- The use of design tokens and tailwind-based theming indicates a scalable theming approach.

d. Mention Relevant Technologies and Frameworks:
- React – For building the UI components.
- react-aria – To provide accessible behavior to components.
- Tailwind CSS – For styling and theming.
- Storybook & Docs (likely using Next.js) – For component demos and documentation.
- TypeScript – Evident from tsconfig files, ensuring type consistency.
- pnpm, Turborepo – For monorepo package management and dependency management.
- CI/CD Tools – GitHub workflows for build, test, lint, coverage, etc.

##### Essential Elements
- Every component module, even if fine-grained, should be included. For instance, list out that the Components package contains elements such as Accordion, Button, Dialog, etc.
- Do not avoid detail—demarcate clear boundaries to ensure every architectural layer is represented.
- Use text annotations where needed to clarify design patterns—especially the context-provider pattern and the modular architecture.

## Diagram (Mermaid)

```mermaid
graph TD
    MR("Marigold Monorepo"):::packages

    subgraph "Packages"
        C("Components"):::packages
        I("Icons"):::packages
        S("System"):::packages
        T("Types"):::packages
        TP("Theme-Plugins"):::packages
        MP("MarigoldProvider"):::packages
    end

    subgraph "Themes"
        TH("Themes"):::themes
    end

    subgraph "Documentation & Tooling"
        D("Documentation Site"):::docs
        CI("CI/CD & Tooling"):::docs
    end

    ED1("React & react-aria"):::external
    ED2("Tailwind CSS"):::external

    %% Connections from Monorepo Root to major modules
    MR -->|"contains"| C
    MR -->|"contains"| I
    MR -->|"contains"| S
    MR -->|"contains"| T
    MR -->|"contains"| TP
    MR -->|"contains"| TH
    MR -->|"contains"| D
    MR -->|"contains"| CI
    MR -->|"contains"| MP

    %% Inter-package dependencies & interactions
    C -->|"depends_on"| S
    C -->|"imports"| I
    C -->|"uses_types"| T
    S -->|"uses_types"| T
    TP -->|"uses_types"| T
    TP -->|"augments"| TH
    TH -->|"injects_theme"| MP
    MP -->|"wraps"| C
    D -->|"consumes"| C
    CI -->|"CI_checks"| C

    %% External Dependencies
    ED1 -->|"accessibility"| C
    ED2 -->|"styles"| TH
    ED2 -->|"styles"| C

    %% Click Events for mapped components
    click MR "https://github.com/marigold-ui/marigold/blob/main/README.md"
    click C "https://github.com/marigold-ui/marigold/tree/main/packages/components"
    click I "https://github.com/marigold-ui/marigold/tree/main/packages/icons"
    click S "https://github.com/marigold-ui/marigold/tree/main/packages/system"
    click T "https://github.com/marigold-ui/marigold/tree/main/packages/types"
    click TP "https://github.com/marigold-ui/marigold/tree/main/packages/theme-plugins"
    click TH "https://github.com/marigold-ui/marigold/tree/main/themes"
    click D "https://github.com/marigold-ui/marigold/tree/main/docs"
    click MP "https://github.com/marigold-ui/marigold/blob/main/packages/components/src/Provider/MarigoldProvider.tsx"
    click CI "https://github.com/marigold-ui/marigold/tree/main/.github/workflows"

    %% Styles
    classDef packages fill:#aee1f9,stroke:#0a74da,stroke-width:2px;
    classDef themes fill:#c8f7c5,stroke:#5abf4e,stroke-width:2px;
    classDef docs fill:#ffe5b4,stroke:#ff8c00,stroke-width:2px;
    classDef external fill:#e0e0e0,stroke:#777,stroke-width:2px;
```
