# badatt/tidy-ui architecture

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

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

## Overview

##### Project Type and Purpose
- This is a monorepo–style React component library (“Tidy UI”) managed by Lerna. It provides a modular set of styled-components (UI primitives) organized into package groups (presentation, layout, form, navigation, feedback, commons, types, etc.). Consumers install individual packages (e.g., “@tidy-ui/button”) and wrap their app in a global `TidyUiProvider` for theming.

##### File-Structure Analysis
- Root
- Configuration files (babel.config.js, rollup.config.js, tsconfig*.json, ESLint, Prettier, Husky, GitHub workflows)
- `internals/` – code generators for new components and docs templates
- `packages/` – ~70 subfolders, each a standalone component or utility (each with its own `src/`, `tests/`, `stories/`, `package.json`, `tsconfig.build.json`)
- `storybook/` – Storybook config + custom theming
- Patterns
- Monorepo with Lerna (lerna.json)
- Rollup-based build for each package
- Storybook for live component preview
- Jest + snapshots for unit tests
- CI/CD via GitHub Actions (PR checks, publish, Storybook deployment)

a. Main Components
- Developer Workstation (IDE + Git)
- GitHub Repository (monorepo root)
- Lerna/CLI – orchestrates bootstrap, build, publish
- Internal Generators (`internals/`) – scaffolding
- Package Modules (`packages/*`) – 70+ component packages
- Build & Test Tools – Rollup, Babel, Jest
- Storybook Server – hosts UI catalog
- Registry (npm) – package publication
- Consumer App – imports tidy-ui packages
b. Relationships & Data Flow
1. Developer pushes code → GitHub repo
2. GitHub Actions triggers PR checks (lint, test, build)
3. Lerna bootstraps dependencies, Rollup builds each package
4. Storybook workflow builds and deploys a static site
5. On release, publish workflow pushes package versions to npm
6. Consumer App installs from npm, pulls in peer-deps (@tidy-ui/commons for Provider)
c. Architectural Patterns
- Monorepo (single source, many packages)
- “Publish per package” pattern
- Code generation for consistency via `internals/generators`
- Separation of concerns: each package is independent, relying on shared `commons` and `types`
d. Key Technologies
- React + styled-components
- TypeScript (tsconfig.base.json / tsconfig.build.json)
- Rollup (bundling)
- Lerna (monorepo management)
- Jest (unit testing)
- Storybook (component explorer)
- GitHub Actions (CI/CD)

##### Essential Architectural Elements
- Monorepo root with Lerna orchestrator
- Internal code generators for package scaffolding
- Individual component packages (with own build/test config)
- Build pipeline and CI/CD via GitHub Actions
- Storybook documentation site
- npm registry for distribution
- Consumer integration via `TidyUiProvider` and package imports

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Workspace
    Dev((Developer Workstation)):::dev
    Dev -->|"git push"| Repo["GitHub Repository (monorepo root)"]:::repo
    click Repo "https://github.com/badatt/tidy-ui/blob/main/lerna.json"

    %% Monorepo Root Components
    subgraph "Monorepo Root"
        Config1["babel.config.js"]:::tool
        Config2["rollup.config.js"]:::tool
        Config3["jest.config.js"]:::tool
        Config4["tsconfig.base.json"]:::tool
        Config5["tsconfig.json"]:::tool
        CIYML[".github/workflows/"]:::ci
        StorybookConfig[".storybook/"]:::ci
        Internals["internals/generators/"]:::tool
        PackagesDir["packages/"]:::code
        click Config1 "https://github.com/badatt/tidy-ui/blob/main/babel.config.js"
        click Config2 "https://github.com/badatt/tidy-ui/blob/main/rollup.config.js"
        click Config3 "https://github.com/badatt/tidy-ui/blob/main/jest.config.js"
        click Config4 "https://github.com/badatt/tidy-ui/blob/main/tsconfig.base.json"
        click Config5 "https://github.com/badatt/tidy-ui/blob/main/tsconfig.json"
        click CIYML "https://github.com/badatt/tidy-ui/tree/main/.github/workflows/"
        click StorybookConfig "https://github.com/badatt/tidy-ui/tree/main/.storybook/"
        click Internals "https://github.com/badatt/tidy-ui/tree/main/internals/generators/"
        click PackagesDir "https://github.com/badatt/tidy-ui/tree/main/packages/"
    end

    %% CI/CD Service
    Repo --> CI["GitHub Actions"]:::ci

    %% Build & Test Pipeline
    CI -->|"PR Checks: lint,test,build"| Lerna["Lerna/CLI"]:::tool
    subgraph "Build & Test Pipeline"
        Lerna -->|"bootstrap"| PackagesDir
        Lerna -->|"run build"| Build["Rollup"]:::tool
        Lerna -->|"run tests"| Test["Jest"]:::tool
        click Build "https://github.com/badatt/tidy-ui/blob/main/rollup.config.js"
        click Test "https://github.com/badatt/tidy-ui/blob/main/jest.config.js"
    end
    Build -->|"publish packages"| NPM["npm Registry"]:::external
    Test --> Repo

    %% Docs Deployment
    CI -->|"deploy docs"| SBHost["Storybook Host"]:::ci
    click StorybookConfig "https://github.com/badatt/tidy-ui/tree/main/.storybook/"

    %% Packages Structure
    subgraph "Packages"
        Commons["@tidy-ui/commons"]:::code
        Theme["commons theme"]:::code
        Types["@tidy-ui/types"]:::code
        Button["@tidy-ui/button"]:::code
        StoryBtn["Button.stories.tsx"]:::code
        TestBtn["Button.spec.tsx"]:::code
        click Commons "https://github.com/badatt/tidy-ui/blob/main/packages/commons/src/provider/TidyUiProvider.tsx"
        click Theme "https://github.com/badatt/tidy-ui/tree/main/packages/commons/src/theme/"
        click Types "https://github.com/badatt/tidy-ui/tree/main/packages/types/"
        click Button "https://github.com/badatt/tidy-ui/blob/main/packages/button/src/Button.tsx"
        click Button "https://github.com/badatt/tidy-ui/blob/main/packages/button/package.json"
        click StoryBtn "https://github.com/badatt/tidy-ui/blob/main/packages/button/stories/Button.stories.tsx"
        click TestBtn "https://github.com/badatt/tidy-ui/blob/main/packages/button/tests/Button.spec.tsx"
    end
    PackagesDir --> Commons
    PackagesDir --> Theme
    PackagesDir --> Types
    PackagesDir --> Button
    PackagesDir --> StoryBtn
    PackagesDir --> TestBtn

    %% Consumer Integration
    ConsumerApp((Consumer App)):::dev
    ConsumerApp -->|"npm install"| NPM
    ConsumerApp -->|"wrap with TidyUiProvider"| Commons

    %% Styles
    classDef dev fill:#f9f,stroke:#333,stroke-width:1px
    classDef repo fill:#bbf,stroke:#333,stroke-width:1px
    classDef tool fill:#bfb,stroke:#333,stroke-width:1px
    classDef ci fill:#f96,stroke:#333,stroke-width:1px
    classDef code fill:#8fd,stroke:#333,stroke-width:1px
    classDef external fill:#ccc,stroke:#333,stroke-width:1px
```
