# friflo/friflo-ecs-unity architecture

> Architecture diagram of the GitHub repository friflo/friflo-ecs-unity, 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/friflo/friflo-ecs-unity
- Repository: https://github.com/friflo/friflo-ecs-unity

## Overview

##### Main Components
- Unity Editor Integration:
- Scripts/Editor: Contains components, drawers, popups, and UI tools that integrate with the Unity Editor.
- These elements handle things like hierarchy display, property drawing, and special customization for ECS entities.
- Runtime Functionality:
- Scripts/Runtime: Hosts the core ECS components, such as entity definitions, hubs, stores, systems, serialization, and internal logic.
- The runtime is where the ECS logic (e.g., system processing, state management) is implemented.
- Plugin System:
- Plugins: Contains XML plugin configurations for different aspects of the ECS extension (like Boost, JSON, and Annotation related plugins) that extend or configure the engine.
- Samples/Example Code:
- Samples: Provides example implementations (e.g., MoveSystem.cs) that demonstrate usage of the ECS components.
- Web and Documentation Assets:

##### Relationships and Interactions
- The runtime systems (Scripts/Runtime) manage the core ECS logic, including data storage, entity-component management, and system updates.
- Plugin files configure or extend the base ECS engine; they might be loaded dynamically or used at build time.
- The web-based components (located in www) suggest additional external interfaces—for example, a graphical explorer and API documentation using Swagger.
- Integration points include:
- Custom drawers and styles in the Editor that reflect the underlying runtime state.
- An HTTP server (found in Scripts/Runtime/Internal/HubHttpServer.cs) that might serve backend data to the web components.
- Testing frameworks under Scripts/Tests ensure that both editor and runtime systems behave as expected.

##### Architectural Patterns and Design Principles
- The project leverages separation of concerns by splitting the system into clearly distinct areas: Editor enhancements versus runtime ECS logic.
- The use of plugins implies a modular design where functionality can be extended or swapped based on configuration.
- The organization into directories like “Base,” “Components,” “Systems,” “Internal,” etc., indicates a layered approach, where base functionality is extended by concrete implementations (e.g., ECSHub, ECSStore).
- The Editor integration adheres to MVC-like or MVVM-like patterns typical in Unity editor scripting—keeping the UI (drawers, popups) separate from logic.

##### Detailed Steps for the Engineer
2. Within each section, break down further:
- In the Editor block, add subcomponents: Drawers, Popups, Styles, and System Trees.
- In the Runtime block, create sub-blocks for Base/Components, ECS Systems, Internal Utilities (like HTTP server and Serialization), and Unity Editor bridges.
- For Plugins, list out the individual XML configurations that extend functionality.
- For instance, from the Editor’s “Component Drawer” to Runtime’s “ECSEntity” component.
- From Plugins to both Editor and Runtime to reflect configuration influence.
- From Runtime’s “HTTP Server” to the Web-based documentation or explorer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Unity Editor Integration
    subgraph "Unity Editor Integration"
        A("Editor UI Components"):::editor
        B("Custom Inspectors"):::editor
        C("Custom Drawers"):::editor
    end

    %% Runtime ECS Core
    subgraph "Runtime ECS Core"
        D("ECS Entity & Store Components"):::runtime
        E("ECS Systems"):::runtime
        F("Internal Utilities (HTTP Server, Serialization)"):::runtime
    end

    %% Other Modules
    G("Plugin Configurations"):::plugin
    H("Samples / Example Code"):::samples
    I("Web Interfaces & Documentation"):::web

    %% Connections between components
    A -->|"Command/Update"| D
    B -->|"DataFlow"| D
    C -->|"DataFlow"| D
    G -->|"ConfigInfluence"| A
    G -->|"ConfigInfluence"| E
    F -->|"HTTPFeed"| I
    H -->|"UsageExample"| D
    H -->|"UsageExample"| E

    %% Click Events
    click A "https://github.com/friflo/friflo-ecs-unity/tree/main/Scripts/Editor"
    click B "https://github.com/friflo/friflo-ecs-unity/tree/main/Scripts/Editor/Components"
    click C "https://github.com/friflo/friflo-ecs-unity/tree/main/Scripts/Editor/Drawer"
    click D "https://github.com/friflo/friflo-ecs-unity/tree/main/Scripts/Runtime/Components"
    click E "https://github.com/friflo/friflo-ecs-unity/tree/main/Scripts/Runtime/Systems"
    click F "https://github.com/friflo/friflo-ecs-unity/tree/main/Scripts/Runtime/Internal"
    click G "https://github.com/friflo/friflo-ecs-unity/tree/main/Plugins"
    click H "https://github.com/friflo/friflo-ecs-unity/tree/main/Samples~/Example"
    click I "https://github.com/friflo/friflo-ecs-unity/tree/main/www~"

    %% Styles
    classDef editor fill:#ccf,stroke:#000,stroke-width:1px;
    classDef runtime fill:#cfc,stroke:#000,stroke-width:1px;
    classDef plugin fill:#fc9,stroke:#000,stroke-width:1px;
    classDef samples fill:#c9f,stroke:#000,stroke-width:1px;
    classDef web fill:#f99,stroke:#000,stroke-width:1px;
```
