# jolacdev/template-react-component-library architecture

> Architecture diagram of the GitHub repository jolacdev/template-react-component-library, 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/jolacdev/template-react-component-library
- Repository: https://github.com/jolacdev/template-react-component-library

## Overview

##### Main Components
- Source Code & Components:
– Highlight the “src” folder as the heart of the project. Under “src” are the “components” directory (which holds individual component folders such as Button and Input) and a top-level index to export them.
- Build & Bundling System:
– Mark the TypeScript (`tsconfig.json` and `tsconfig.build.json`), Vite configuration (`vite.config.ts`), and the build scripts as the pipeline that compiles TypeScript with tsc and bundles the code using Vite. Also note the use of plugins like vite-plugin-dts for generating declaration files and vite-plugin-lib-inject-css for CSS injection.
- Documentation & Storybook:
– Include the “.storybook” directory, which configures Storybook to provide isolated component documentation and an interactive environment. Also, the __docs__ subdirectories in components (e.g., Button/__docs__) hold MDX and stories files.
- Testing Framework:
– Represent the “Vitest” configuration details (from setupTests.ts and scripts in package.json) that run tests for each component found in __test__ folders.
- Code Quality & Development Tools:
– Include configuration for ESLint (eslint.config.js and eslint.constants.mjs) and Prettier (.prettierrc.mjs) that enforce code consistency and linting. The setup for Git hooks (lefthook.yml) for runnning format and lint tasks before commits should also be noted.
- Continuous Integration/Deployment:

##### Relationships and Interactions
- “Build Process” to “Distribution Output” (e.g., dist directory mentioned in package.json) which makes the library ready for publishing.
- An interaction from “Source Code” to both “Testing” (Vitest, React Testing Library) and “Documentation (Storybook)” since tests and stories are generated based on the component code.
- Link “Code Quality” tools (ESLint, Prettier, and Git Hooks) to the “Source Code” module to indicate that all commits and code edits are automatically checked and formatted.

##### Architectural Patterns and Important Design Principles
- That there is a modular structure that supports both a full-library export and individual component exports (evidenced by the exports structure in package.json and the generation of multiple entry points in vite.config.ts).
- The separation of concerns is clearly seen: components are separated, documentation is maintained close to components, and build/test/integration scripts are isolated in dedicated folders (.github, .storybook).
- Design patterns like “component isolation” (Storybook), “fail-fast” in Git hooks (lefthook), and “automation” in CI/CD pipelines.

##### Tools, Frameworks, and Technologies
- Core Frameworks: React (with JSX/TSX) and TypeScript.
- Build Tools: Vite (with vite-plugin-dts and vite-plugin-lib-inject-css).
- Testing: Vitest and React Testing Library, with environment simulated by jsdom.
- Code Quality: ESLint and Prettier configurations along with Git hooks (Lefthook).
- CI/CD: GitHub Actions orchestrate CI (lint, test, build) and CD (release generation with semantic-release).
- Documentation: Storybook configured for dynamic component showcasing through MDX and TSX stories.

- For each module, break down the sub-components (e.g., within “Source” show individual components with folders like Button and Input).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Source Code & Components
    subgraph "Source Code"
        src["src"]:::source
        srcIndex["src/index.ts"]:::source
        srcComponents["src/components"]:::source
        compIndex["src/components/index.ts"]:::source
        btn["Button Component"]:::component
        btnDocs["Button Docs"]:::doc
        btnTests["Button Tests"]:::test
        inp["Input Component"]:::component
        inpDocs["Input Docs"]:::doc
        inpTests["Input Tests"]:::test
    end

    %% Build & Bundling System
    subgraph "Build & Bundling"
        tsconfig["tsconfig.json"]:::build
        tsconfigBuild["tsconfig.build.json"]:::build
        viteConfig["vite.config.ts"]:::build
    end

    %% Documentation & Storybook
    subgraph "Documentation & Storybook"
        storybook["Storybook (.storybook)"]:::doc
        storyMain["main.ts"]:::doc
        storyPreview["preview.ts"]:::doc
    end

    %% Testing Framework
    subgraph "Testing Framework"
        setupTests["setupTests.ts"]:::test
    end

    %% Code Quality & Development Tools
    subgraph "Code Quality & DevTools"
        eslint["eslint.config.js"]:::quality
        eslintConst["eslint.constants.mjs"]:::quality
        prettier[".prettierrc.mjs"]:::quality
        lefthook["lefthook.yml"]:::quality
    end

    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        workflows["GitHub Workflows (.github/workflows)"]:::ci
        semantic["Semantic Release (release.config.mjs)"]:::ci
    end

    %% Distribution Output
    Distribution["Distribution (dist)"]:::distribution

    %% Connections
    %% From Source Code to Build Process
    src -- "Compile/Bundle" --> tsconfig
    tsconfigBuild --- viteConfig
    viteConfig -- "Output Library" --> Distribution

    %% Source Code connections to Testing & Documentation
    src -- "RunTests" --> setupTests
    src -- "GenerateDocs" --> storybook

    %% Link individual component details
    srcComponents --> compIndex
    srcComponents --> btn
    btn -- "Docs" --> btnDocs
    btn -- "Tests" --> btnTests
    srcComponents --> inp
    inp -- "Docs" --> inpDocs
    inp -- "Tests" --> inpTests

    %% Source Code connection to Code Quality Tools
    src -- "Lint/Format" --> eslint

    %% CI/CD Pipeline triggering Build, Testing, and Quality
    workflows -- "TriggerBuild" --> tsconfig
    workflows -- "TriggerTests" --> setupTests
    workflows -- "RunLint" --> eslint
    workflows -- "InitiateRelease" --> semantic
    semantic -- "Publish" --> Distribution

    %% Additional connections within Documentation & Storybook
    storybook --> storyMain
    storybook --> storyPreview

    %% Styles
    classDef source fill:#cce5ff,stroke:#333,stroke-width:1px;
    classDef component fill:#99ccff,stroke:#333,stroke-width:1px;
    classDef build fill:#d4edda,stroke:#333,stroke-width:1px;
    classDef doc fill:#fff3cd,stroke:#333,stroke-width:1px;
    classDef test fill:#f8d7da,stroke:#333,stroke-width:1px;
    classDef quality fill:#fde2e2,stroke:#333,stroke-width:1px;
    classDef ci fill:#e2e3e5,stroke:#333,stroke-width:1px;
    classDef distribution fill:#d1c4e9,stroke:#333,stroke-width:1px;

    %% Click Events
    click src "https://github.com/jolacdev/template-react-component-library/tree/master/src/"
    click srcIndex "https://github.com/jolacdev/template-react-component-library/blob/master/src/index.ts"
    click srcComponents "https://github.com/jolacdev/template-react-component-library/tree/master/src/components/"
    click compIndex "https://github.com/jolacdev/template-react-component-library/blob/master/src/components/index.ts"
    click tsconfig "https://github.com/jolacdev/template-react-component-library/blob/master/tsconfig.json"
    click tsconfigBuild "https://github.com/jolacdev/template-react-component-library/blob/master/tsconfig.build.json"
    click viteConfig "https://github.com/jolacdev/template-react-component-library/blob/master/vite.config.ts"
    click storybook "https://github.com/jolacdev/template-react-component-library/tree/master/.storybook/"
    click storyMain "https://github.com/jolacdev/template-react-component-library/blob/master/.storybook/main.ts"
    click storyPreview "https://github.com/jolacdev/template-react-component-library/blob/master/.storybook/preview.ts"
    click btnDocs "https://github.com/jolacdev/template-react-component-library/tree/master/src/components/Button/__docs__/"
    click inpDocs "https://github.com/jolacdev/template-react-component-library/tree/master/src/components/Input/__docs__/"
    click setupTests "https://github.com/jolacdev/template-react-component-library/blob/master/setupTests.ts"
    click btnTests "https://github.com/jolacdev/template-react-component-library/tree/master/src/components/Button/__test__/"
    click inpTests "https://github.com/jolacdev/template-react-component-library/tree/master/src/components/Input/__test__/"
    click eslint "https://github.com/jolacdev/template-react-component-library/blob/master/eslint.config.js"
    click eslintConst "https://github.com/jolacdev/template-react-component-library/blob/master/eslint.constants.mjs"
    click prettier "https://github.com/jolacdev/template-react-component-library/blob/master/.prettierrc.mjs"
    click lefthook "https://github.com/jolacdev/template-react-component-library/blob/master/lefthook.yml"
    click workflows "https://github.com/jolacdev/template-react-component-library/tree/master/.github/workflows/"
    click semantic "https://github.com/jolacdev/template-react-component-library/blob/master/release.config.mjs"
```
