# joserick/laravel-livewire-discover architecture

> Architecture diagram of the GitHub repository joserick/laravel-livewire-discover, 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/joserick/laravel-livewire-discover
- Repository: https://github.com/joserick/laravel-livewire-discover

## Overview

The file structure is organized with clear separation of concerns:
- The config directory holds the configuration file (livewire-discover configuration) which defines the mapping of prefixes to class namespaces.
- The src directory is the heart of the package and contains all core classes. Within it:
- The Commands folder includes Artisan commands for listing and creating components (for example, ListCommand, MakeCommand, and MakeLivewireDiscoverCommand).
- The other files (like ComponentRegistry.php, ComponentResolver.php, LaravelLivewireDiscover.php, LaravelLivewireDiscoverData.php, LaravelLivewireDiscoverManager.php, and LaravelLivewireDiscoverServiceProvider.php) represent the components needed to register, resolve, and manage Livewire components.
- The tests directory holds both unit and feature tests to ensure the package works correctly.

##### Main Components
- Configuration Module: Represented by the config file (config/livewire-discover.php) that holds the namespace configurations.
- Service Provider: The LaravelLivewireDiscoverServiceProvider (in src) which integrates the package with the Laravel boot process.
- Livewire Discover Manager and Helpers: Classes like LaravelLivewireDiscover, LaravelLivewireDiscoverManager, ComponentRegistry, and ComponentResolver, which manage the discovery logic.
- Artisan Command Handlers: The set of commands in src/Commands (such as ListCommand, MakeCommand, etc.) that expose the capabilities to the end-user via the command line.
- Stubbing Resources: The resources directory holds stubs for generating service provider files or component templates, which are used by the make commands.
- Test Suite: Feature and Unit tests (in tests) ensure the stability and correctness of the functionality.

##### Relationships and Interactions
- At application boot, the Service Provider is registered. It uses the configuration (from config/livewire-discover.php) to register one or more namespaces for Livewire components.
- The Service Provider is responsible for calling functions like Livewire::discover or Livewire::componentNamespace, passing in the configured namespaces.
- When an Artisan command (for listing or making components) is executed by the developer, the corresponding command class (for example, ListCommand or MakeCommand) is called. These, in turn, interact with the Manager and Registry classes to manage the component creation or listing.
- The ComponentResolver likely handles the mapping of short names (like my-components.devices) to fully qualified class names based on the discovered namespaces.
- The process may also load stubs and other resources when auto-creating Livewire components.

##### Architectural Patterns and Design Principles
- The package follows the Service Provider pattern of Laravel to bootstrap its features into the Laravel ecosystem.
- It splits responsibilities among several classes (single responsibility principle): configuration reading, component registration, command handling, and component resolution.
- Use of Artisan commands denotes a command–query separation strategy for user interactions.
- Clean separation between configuration, core logic, and test cases helps maintain a maintainable and scalable design.

##### Detail the Technology Stack
- PHP is the primary language.
- Laravel Framework integrates the package via its Service Provider and Artisan command system.
- Livewire (a dynamic front-end framework for Laravel) is the target system to which the package adds functionality.
- Composer is used as the package manager and also for autoloading.
- PHPUnit/Pest (as seen in tests) ensures the quality of implementation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Laravel Application"]:::external

    subgraph "Configuration Module"
        B["Configuration (livewire-discover.php)"]:::config
    end

    subgraph "Core Integration"
        C["Service Provider (LaravelLivewireDiscoverServiceProvider)"]:::service
    end

    subgraph "Livewire Discovery Manager & Helpers"
        D1["Discovery Core (LaravelLivewireDiscover)"]:::core
        D2["Manager (LaravelLivewireDiscoverManager)"]:::core
        D3["Component Registry (ComponentRegistry)"]:::core
        D4["Component Resolver (ComponentResolver)"]:::core
        D5["Data Handler (LaravelLivewireDiscoverData)"]:::core
    end

    subgraph "Artisan Command Handlers"
        E1["ListCommand"]:::command
        E2["MakeCommand"]:::command
        E3["MakeLivewireDiscoverCommand"]:::command
        E4["ToolCommand"]:::command
    end

    subgraph "Stubbing Resources"
        F["Stubs (resources/stubs)"]:::resource
    end

    subgraph "Test Suite"
        G["Test Suite (tests)"]:::test
    end

    A -->|"registers"| C
    C -->|"reads_config"| B
    C -->|"registers_components"| D2
    E1 -->|"triggers"| D2
    E2 -->|"triggers"| D2
    E3 -->|"triggers"| D2
    E4 -->|"triggers"| D2
    D2 -->|"loads_stubs"| F
    G -->|"tests_provider"| C
    G -->|"tests_commands"| E1
    G -->|"tests_commands"| E2
    G -->|"tests_commands"| E3
    G -->|"tests_commands"| E4

    click B "https://github.com/joserick/laravel-livewire-discover/blob/main/config/livewire-discover.php"
    click C "https://github.com/joserick/laravel-livewire-discover/blob/main/src/LaravelLivewireDiscoverServiceProvider.php"
    click D1 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/LaravelLivewireDiscover.php"
    click D2 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/LaravelLivewireDiscoverManager.php"
    click D3 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/ComponentRegistry.php"
    click D4 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/ComponentResolver.php"
    click D5 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/LaravelLivewireDiscoverData.php"
    click E1 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/Commands/ListCommand.php"
    click E2 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/Commands/MakeCommand.php"
    click E3 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/Commands/MakeLivewireDiscoverCommand.php"
    click E4 "https://github.com/joserick/laravel-livewire-discover/blob/main/src/Commands/ToolCommand.php"
    click F "https://github.com/joserick/laravel-livewire-discover/tree/main/resources/stubs"
    click G "https://github.com/joserick/laravel-livewire-discover/tree/main/tests"

    classDef config fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef service fill:#aed6f1,stroke:#2471a3,stroke-width:2px;
    classDef core fill:#abebc6,stroke:#239b56,stroke-width:2px;
    classDef command fill:#f5b7b1,stroke:#b03a2e,stroke-width:2px;
    classDef resource fill:#d7bde2,stroke:#8e44ad,stroke-width:2px;
    classDef test fill:#f9c5d1,stroke:#c0392b,stroke-width:2px;
    classDef external fill:#d5f5e3,stroke:#27ae60,stroke-width:2px;
```
