# moonshine-software/moonshine architecture

> Architecture diagram of the GitHub repository moonshine-software/moonshine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moonshine-software/moonshine
- Repository: https://github.com/moonshine-software/moonshine

## Overview

##### Main Components Identification

The system should be divided into these core components:

a. Core Framework Layer
- MoonShine Core (src/Core)
- Dependency Injection System
- Router System
- Authentication System

b. UI Layer
- Asset Management (src/AssetManager)
- Component System (src/UI)
- Layout System
- Form Builders
- Table Builders

c. Resource Management Layer
- CRUD Resources
- Model Resources
- Custom Pages
- Field Management

d. Integration Layer
- Laravel Integration
- Database Interaction
- File Storage
- Authentication Integration

**[Client Browser]**
- ↕️ HTTP/HTTPS
**[Laravel Application]**
- ↕️
**[MoonShine Core]**
- ↙️    ↓    ↘️
**[UI Layer] [Resources] [Services]**
- ↓         ↓          ↓
**[Components] [Models] [Integration]**

##### Key Relationships to Highlight

a. Core Dependencies:
- How MoonShineServiceProvider bootstraps the application
- Dependency injection flow
- Routing system connections

b. Resource Management:
- Model to Resource relationships
- CRUD operations flow
- Custom page integration

c. UI Component System:
- Component hierarchy
- Asset management flow
- Form and table builder patterns

##### Integration Points

Clear integration points for:
- Laravel authentication
- Database interactions
- File storage systems
- Asset compilation and delivery

##### Data Flow Indicators

- Request/response cycle
- Data transformation flow
- Asset delivery paths
- Authentication flow

##### Implementation Details

- Modular architecture (shown by the src/ directory structure)
- Contract-based design (src/Contracts)
- Extension points
- Service provider integration

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Client Browser"]
    end

    subgraph Framework["Core Framework Layer"]
        MoonShineCore["MoonShine Core"]:::core
        DI["Dependency Injection"]:::core
        Router["Router System"]:::core
        Auth["Authentication System"]:::core
    end

    subgraph UILayer["UI Layer"]
        AssetMgr["Asset Management"]:::ui
        Components["Component System"]:::ui
        Layout["Layout System"]:::ui
        FormBuilder["Form Builder"]:::ui
        TableBuilder["Table Builder"]:::ui
    end

    subgraph ResourceLayer["Resource Management Layer"]
        CRUD["CRUD Resources"]:::resource
        ModelRes["Model Resources"]:::resource
        CustomPages["Custom Pages"]:::resource
        FieldMgmt["Field Management"]:::resource
    end

    subgraph IntegrationLayer["Integration Layer"]
        Laravel["Laravel Integration"]:::integration
        FileStorage["File Storage"]:::integration
        AuthIntegration["Authentication Integration"]:::integration
        MenuMgmt["Menu Management"]:::integration
        ColorMgmt["Color Management"]:::integration
    end

    %% Connections
    Browser --> MoonShineCore
    MoonShineCore --> DI
    MoonShineCore --> Router
    MoonShineCore --> Auth

    MoonShineCore --> UILayer
    MoonShineCore --> ResourceLayer
    MoonShineCore --> IntegrationLayer

    %% UI Layer connections
    AssetMgr --> Components
    Components --> Layout
    Components --> FormBuilder
    Components --> TableBuilder

    %% Resource Layer connections
    CRUD --> ModelRes
    ModelRes --> FieldMgmt
    CustomPages --> FieldMgmt

    %% Integration Layer connections
    Laravel --> FileStorage
    Laravel --> AuthIntegration
    Laravel --> MenuMgmt
    Laravel --> ColorMgmt

    %% Click events
    click MoonShineCore "https://github.com/moonshine-software/moonshine/tree/3.x/src/Core/"
    click DI "https://github.com/moonshine-software/moonshine/tree/3.x/src/Core/DependencyInjection/"
    click Router "https://github.com/moonshine-software/moonshine/blob/3.x/src/Core/src/AbstractRouter.php"
    click Auth "https://github.com/moonshine-software/moonshine/blob/3.x/src/Laravel/src/MoonShineAuth.php"
    click AssetMgr "https://github.com/moonshine-software/moonshine/tree/3.x/src/AssetManager/"
    click Components "https://github.com/moonshine-software/moonshine/tree/3.x/src/UI/src/Components/"
    click Layout "https://github.com/moonshine-software/moonshine/tree/3.x/src/UI/src/Components/Layout/"
    click FormBuilder "https://github.com/moonshine-software/moonshine/blob/3.x/src/UI/src/Components/FormBuilder.php"
    click TableBuilder "https://github.com/moonshine-software/moonshine/blob/3.x/src/UI/src/Components/Table/TableBuilder.php"
    click CRUD "https://github.com/moonshine-software/moonshine/blob/3.x/src/Laravel/src/Resources/CrudResource.php"
    click ModelRes "https://github.com/moonshine-software/moonshine/blob/3.x/src/Laravel/src/Resources/ModelResource.php"
    click CustomPages "https://github.com/moonshine-software/moonshine/tree/3.x/src/Laravel/src/Pages/"
    click FieldMgmt "https://github.com/moonshine-software/moonshine/tree/3.x/src/UI/src/Fields/"
    click Laravel "https://github.com/moonshine-software/moonshine/tree/3.x/src/Laravel/"
    click FileStorage "https://github.com/moonshine-software/moonshine/blob/3.x/src/Laravel/src/Storage/LaravelStorage.php"
    click AuthIntegration "https://github.com/moonshine-software/moonshine/blob/3.x/src/Laravel/src/Http/Middleware/Authenticate.php"
    click MenuMgmt "https://github.com/moonshine-software/moonshine/tree/3.x/src/MenuManager/"
    click ColorMgmt "https://github.com/moonshine-software/moonshine/tree/3.x/src/ColorManager/"

    %% Styles
    classDef core fill:#2196F3,color:white
    classDef ui fill:#4CAF50,color:white
    classDef resource fill:#FF9800,color:white
    classDef integration fill:#9C27B0,color:white
    classDef default fill:#757575,color:white

    %% Legend
    subgraph Legend
        CoreLegend["Core Component"]:::core
        UILegend["UI Component"]:::ui
        ResourceLegend["Resource Component"]:::resource
        IntegrationLegend["Integration Component"]:::integration
    end
```
