# icehouse-ventures/laravel-chartjs architecture

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

- Interactive diagram: https://gitdiagram.com/icehouse-ventures/laravel-chartjs
- Repository: https://github.com/icehouse-ventures/laravel-chartjs

## Overview

##### Project type and purpose
- This is a Laravel-package project (“laravel-chartjs”) that wraps the Chart.js JavaScript library to provide an easy, Laravel-style API for building charts. It is not a standalone web app but a library that plugs into a Laravel application via Composer and ServiceProvider.

##### Key architectural artifacts (from file tree & README)
- Backend (PHP) code under src/
- Providers/ChartjsServiceProvider.php – registers the package, publishes config/assets/views, binds Facade alias.
- Facades/Chartjs.php – static interface for developers.
- Builder.php – fluent API to assemble chart name, type, size, labels, datasets, options.
- Support/Config.php – reads config/chartjs.php.
- View/Components/ChartjsComponent.php – Blade component that renders the chart canvas + script tag.
- resources/js/chart.js – small runtime helper for inline/livewire updates.
- resources/views/*.blade.php – default templates for chart rendering.
- Config & assets
- config/chartjs.php – settings (delivery method, Chart.js version).
- dist/chart*.js – precompiled Chart.js binaries (v2, v3, v4) for “publish” delivery.
- Frontend
- Chart.js – loaded via CDN, published binary, or via NPM/Vite.
- Blade component <x-chartjs-component> outputs HTML + data that the Chart.js engine consumes.
- Optional Livewire integration for dynamic updates.
- Tests – Feature tests using PHPUnit/Pest ensure Builder, Provider, Facade behaviors.

##### Main components & boundaries
[1] Laravel Application Container
– ServiceProvider
– Facade (Chartjs)
– Builder & Config
– Blade View Component
[2] Published Config & Assets
– config/chartjs.php
– public/js/chart.js (if “publish” method) or vendor–binary loader or CDN URL
[3] Frontend Runtime (Browser)
– <canvas> element rendered by Blade
– Chart.js library (v2, v3, v4)
– chart.js helper for Livewire or inline scripts
[4] Developer Code (in host app)
– Calls Chartjs::build() in Controller or Livewire Component
– Passes chart object to view

##### Relationships & data flows
- Developer code → Chartjs Facade → Builder (reads config) → Chart Object
- Controller returns view(… , ['chart' => $chart]) → Blade View Component
- Blade component generates:
– <canvas id="…">
– <script> ChartJShelper.init(configJSON) </script>
– <script src="…chart.js…"></script>
- Browser loads Chart.js → parses JSON config → draws chart on canvas
- Livewire path: Livewire event cycle ↔ Chart.js helper updates dataset & redraws

##### Architectural patterns & technologies
- Service Provider pattern (Laravel)
- Facade pattern for developer ergonomics
- Component-based view rendering (Blade View Components)
- Optional Livewire for reactive updates
- Config-driven asset delivery (CDN vs. published vs. binary)
- Composer for package management, Pest/PHPUnit for tests

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Application Code
    subgraph "Host Application Code" 
        direction TB
        Controller["Developer Controller/Livewire Component"]:::host
        LivewireComp["Livewire Component"]:::host
    end

    %% Backend Package
    subgraph "Laravel-ChartJS Package" 
        direction TB
        ServiceProvider["ChartjsServiceProvider"]:::backend
        Facade["Chartjs Facade"]:::backend
        Builder["Builder (Fluent API)"]:::backend
        Config["Config Reader"]:::backend
        BladeComponent["Blade View Component"]:::backend
        subgraph "Blade Templates"
            direction TB
            Template1["chart-template.blade.php"]:::backend
            Template2["chart-template-livewire.blade.php"]:::backend
        end
        subgraph "Tests"
            direction TB
            Test1["BuilderTest.php"]:::backend
            Test2["ProviderTest.php"]:::backend
            Test3["LaravelTest.php"]:::backend
        end
    end

    %% Config & Assets
    subgraph "Config & Assets" 
        direction TB
        ConfigFile["config/chartjs.php"]:::config
        subgraph "Precompiled Binaries"
            direction TB
            Dist1["dist/chart.js"]:::asset
            Dist2["dist/chart2.bundle.js"]:::asset
            Dist3["dist/chart3.js"]:::asset
        end
    end

    %% Browser Runtime
    subgraph "Browser Runtime" 
        direction TB
        Canvas["<canvas> Element"]:::frontend
        JSHelper["chart.js Helper"]:::frontend
        ChartJS["Chart.js Library"]:::external
    end

    %% External CDN
    CDN["CDN URL"]:::external

    %% Relationships
    Controller -->|"calls Chartjs::build()"| Facade
    LivewireComp -->|"calls Chartjs::build()"| Facade
    ServiceProvider -->|"binds Facade"| Facade
    Facade -->|"delegates to"| Builder
    Builder -->|"reads settings from"| Config
    Controller -->|"passes chart object to view"| BladeComponent
    BladeComponent -->|"uses template"| Template1
    BladeComponent -->|"uses template"| Template2
    ServiceProvider -->|"publishes"| ConfigFile
    ServiceProvider -->|"publishes"| Dist1
    ServiceProvider -->|"publishes"| Dist2
    ServiceProvider -->|"publishes"| Dist3
    ConfigFile -->|"provides settings"| Builder
    BladeComponent -->|"renders"| Canvas
    BladeComponent -->|"outputs init script"| JSHelper
    BladeComponent -->|"includes asset script"| Dist1
    BladeComponent -->|"or CDN"| CDN
    JSHelper -->|"initializes with JSON"| ChartJS
    ChartJS -->|"renders on"| Canvas
    LivewireComp -->|"triggers update"| JSHelper
    JSHelper -->|"Livewire AJAX call"| LivewireComp

    %% Click Events
    click ServiceProvider "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/src/Providers/ChartjsServiceProvider.php"
    click Facade "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/src/Facades/Chartjs.php"
    click Builder "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/src/Builder.php"
    click Config "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/src/Support/Config.php"
    click BladeComponent "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/src/View/Components/ChartjsComponent.php"
    click JSHelper "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/src/resources/js/chart.js"
    click Template1 "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/src/resources/views/chart-template.blade.php"
    click Template2 "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/src/resources/views/chart-template-livewire.blade.php"
    click ConfigFile "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/config/chartjs.php"
    click Dist1 "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/dist/chart.js"
    click Dist2 "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/dist/chart2.bundle.js"
    click Dist3 "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/dist/chart3.js"
    click Test1 "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/tests/Feature/BuilderTest.php"
    click Test2 "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/tests/Feature/ProviderTest.php"
    click Test3 "https://github.com/icehouse-ventures/laravel-chartjs/blob/master/tests/Feature/LaravelTest.php"

    %% Styles
    classDef backend fill:#cfe2ff,stroke:#084298,stroke-width:1px
    classDef host fill:#e2e3e5,stroke:#6c757d,stroke-width:1px
    classDef frontend fill:#d1e7dd,stroke:#0f5132,stroke-width:1px
    classDef external fill:#ffe5d9,stroke:#d63384,stroke-width:1px
    classDef asset fill:#f8d7da,stroke:#842029,stroke-width:1px
    classDef config fill:#fff3cd,stroke:#664d03,stroke-width:1px
```
