# nittarab/daisy_components architecture

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

- Interactive diagram: https://gitdiagram.com/nittarab/daisy_components
- Repository: https://github.com/nittarab/daisy_components

## Overview

##### Project Type & Purpose
- This is a Ruby gem designed for UI development on Rails. Its objective is to enable component-based design by providing a library of reusable, styled view components that adhere to the DaisyUI design system.
- Key functionalities include:
- Integration with the Rails ecosystem using ViewComponent.
- Styling with DaisyUI and TailwindCSS.
- Live preview and documentation via Lookbook.
- Comprehensive testing for stability and UI reliability.

##### Main Architectural Components
a. Core Gem Structure
- Gem specification (daisy_components.gemspec) along with versioning and engine initialization in the lib directory.
b. Component Implementation
- The core components are found in “app/components/daisy_components”. This includes various types of components such as actions (button, dropdown, swap) and data display (accordion, avatar, badge, card, chat, chat bubble, divider, item, title).
- The base component class (app/components/daisy_components/base_component.rb) centralizes shared behavior for all components.
c. Assets & Styling
- Stylesheets in “app/assets/stylesheets/daisy_components” and images in “app/assets/images/daisy_components” represent the design assets.
- TailwindCSS (configured via asset pipeline and possibly in the project’s Gemfile/Build configuration) and DaisyUI’s design tokens are implied.
d. Controllers, Views, and Helpers
- Controllers (app/controllers/daisy_components) and helpers (app/helpers/daisy_components) provide the web-facing interface, integration, and rendering logic.
- The default layout for the components (app/views/layouts/daisy_components/application.html.erb) indicates how UI components are presented in a Rails view.
e. Live Preview / Documentation (Lookbook)
- The README instructs running a server and browsing to a Lookbook page. Therefore, the integration of Lookbook should be indicated as part of the documentation/live preview of components.
f. Testing Infrastructure
- The testing directories (test/components, test/controllers, test/dummy, etc.) show that component previews and integration tests are thoroughly organized.
- The “test/dummy” app simulates a Rails application environment to test and showcase component integration.

##### Relationships and Data Flow
- Components depend on the underlying Rails framework for rendering.
- View components interact with asset pipelines, integrating CSS (TailwindCSS) and images.
- The controllers and helpers make use of these components to assemble full-page layouts.
- Lookbook acts as an interactive visualization tool to preview the components. This can be represented as a side channel where developers interact with the live documentation.
- The testing suite ensures that component interactions and rendering behave as expected; this may be shown as a feedback loop from test results back to component development.

##### Architectural Patterns and Principles
- Component-Based Architecture: Emphasize the separation of UI concerns into individual, reusable components.
- MVC Pattern (typical for Rails apps): The controllers, views, and helpers working together.
- Engine Pattern: The gem is also a Rails engine (lib/daisy_components/engine.rb) that integrates seamlessly into a host Rails application.

##### Elements
- Gem Core (lib folder contents and gemspec)
- UI Components (view components, divided by “actions” and “data display”)
- Assets (stylesheets and images)
- Rails Integration (controllers, views, helpers, and layouts)
- Documentation/Preview (Lookbook integration)
- Testing (unit tests, integration tests, dummy app)
- The Gem Core provides a foundation to initialize components.
- UI Components receive styling and assets to render UI.
- Controllers and helpers assemble the overall layout using components.
- Testing runs through the dummy app to validate component functionality.
- Lookbook fetches components to provide a live preview.
- Another for UI components.
- A third for assets (CSS, images).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Gem Core Layer
    subgraph "Gem Core"
        GC1["Gem Specification"]:::core
        GC2["Engine Initialization"]:::core
        GC3["Versioning"]:::core
    end

    %% Base Component
    BC["Base Component"]:::component

    %% UI Components Layer
    subgraph "UI Components"
        subgraph "Actions"
            A1["Button Component"]:::component
            A2["Dropdown Component"]:::component
            A3["Swap Component"]:::component
        end
        subgraph "Data Display"
            DD1["Accordion Component"]:::component
            DD2["Avatar Component"]:::component
            DD3["Badge Component"]:::component
            DD4["Card Component"]:::component
            DD5["Chat Component"]:::component
            DD6["Chat Bubble Component"]:::component
            DD7["Divider Component"]:::component
            DD8["Item Component"]:::component
            DD9["Title Component"]:::component
        end
    end

    %% Assets & Styling Layer
    subgraph "Assets & Styling"
        AS1["Stylesheets"]:::asset
        AS2["Images"]:::asset
    end

    %% Rails Integration Layer
    subgraph "Rails Integration"
        R1["Controller: application_controller.rb"]:::rails
        RH1["Helper: application_helper.rb"]:::rails
        RH2["Helper: icons_helper.rb"]:::rails
        R3["Layout: application.html.erb"]:::rails
    end

    %% Documentation / Live Preview
    DP["Lookbook Previews"]:::docs

    %% Testing Infrastructure
    subgraph "Testing"
        T1["Component Tests"]:::testing
        T2["Dummy App"]:::testing
    end

    %% Connections: Gem Core to Base Component
    GC1 --> GC2
    GC2 --> GC3
    GC3 --> BC

    %% Base Component to UI Components
    BC --> A1
    BC --> A2
    BC --> A3
    BC --> DD1
    BC --> DD2
    BC --> DD3
    BC --> DD4
    BC --> DD5
    BC --> DD6
    BC --> DD7
    BC --> DD8
    BC --> DD9

    %% Assets provide styling to UI Components
    AS1 --> A1
    AS1 --> A2
    AS1 --> A3
    AS1 --> DD1
    AS1 --> DD2
    AS1 --> DD3
    AS1 --> DD4
    AS1 --> DD5
    AS1 --> DD6
    AS1 --> DD7
    AS1 --> DD8
    AS1 --> DD9

    %% Rails Integration uses Base Component for rendering
    R1 --> BC
    RH1 --> BC
    RH2 --> BC
    R3 --> BC

    %% Documentation fetches components for live preview
    DP --> BC

    %% Testing validates components and live preview
    T1 --> BC
    T2 --> DP

    %% Click Events for Gem Core & Engine
    click GC1 "https://github.com/nittarab/daisy_components/blob/main/daisy_components.gemspec"
    click GC2 "https://github.com/nittarab/daisy_components/blob/main/lib/daisy_components/engine.rb"
    click GC3 "https://github.com/nittarab/daisy_components/blob/main/lib/daisy_components/version.rb"

    %% Click Event for Base Component
    click BC "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/base_component.rb"

    %% Click Events for UI Components - Actions
    click A1 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/actions/button_component.rb"
    click A2 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/actions/dropdown_component.rb"
    click A3 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/actions/swap_component.rb"

    %% Click Events for UI Components - Data Display
    click DD1 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/accordion_component.rb"
    click DD2 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/avatar_component.rb"
    click DD3 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/badge_component.rb"
    click DD4 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/card_component.rb"
    click DD5 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/chat_component.rb"
    click DD6 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/chat_bubble_component.rb"
    click DD7 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/divider_component.rb"
    click DD8 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/item_component.rb"
    click DD9 "https://github.com/nittarab/daisy_components/blob/main/app/components/daisy_components/data_display/title_component.rb"

    %% Click Events for Assets & Styling
    click AS1 "https://github.com/nittarab/daisy_components/blob/main/app/assets/stylesheets/daisy_components/application.css"
    click AS2 "https://github.com/nittarab/daisy_components/tree/main/app/assets/images/daisy_components"

    %% Click Events for Rails Integration
    click R1 "https://github.com/nittarab/daisy_components/blob/main/app/controllers/daisy_components/application_controller.rb"
    click RH1 "https://github.com/nittarab/daisy_components/blob/main/app/helpers/daisy_components/application_helper.rb"
    click RH2 "https://github.com/nittarab/daisy_components/blob/main/app/helpers/daisy_components/icons_helper.rb"
    click R3 "https://github.com/nittarab/daisy_components/blob/main/app/views/layouts/daisy_components/application.html.erb"

    %% Click Event for Documentation / Lookbook
    click DP "https://github.com/nittarab/daisy_components/tree/main/test/components/previews/daisy_components"

    %% Click Events for Testing
    click T1 "https://github.com/nittarab/daisy_components/tree/main/test/components/daisy_components"
    click T2 "https://github.com/nittarab/daisy_components/tree/main/test/dummy"

    %% Style Definitions
    classDef core fill:#ffe6e6,stroke:#cc0000,stroke-width:2px;
    classDef component fill:#e6f7ff,stroke:#005580,stroke-width:2px;
    classDef asset fill:#e6ffe6,stroke:#008000,stroke-width:2px;
    classDef rails fill:#fff5e6,stroke:#cc6600,stroke-width:2px;
    classDef docs fill:#f2e6ff,stroke:#8000ff,stroke-width:2px;
    classDef testing fill:#ffffe6,stroke:#808000,stroke-width:2px;
```
