# genki-tx/unitysimplecleanarchitectureplane architecture

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

- Interactive diagram: https://gitdiagram.com/genki-tx/unitysimplecleanarchitectureplane
- Repository: https://github.com/genki-tx/unitysimplecleanarchitectureplane

## Overview

##### Project Type and Purpose
- This is a Unity application exemplifying the Simple Clean Architecture design pattern.
- The project is educational, showcasing a decoupled architecture that separates business logic (Entity and Usecase) from presentation (Presenter and View), using dependency injection (Service Locator pattern) and reactive programming (using C# EventHandler).

##### File Structure
- The top-level “Assets” folder contains subdirectories for Scenes, Prefabs, and Scripts.
- The DI mechanism is featured in files such as CounterDI.cs and PresenterDI.cs, which manage the creation and wiring of component dependencies.
- The directory separation clearly indicates an architectural enforcement, where each component type resides in its dedicated folder.

##### README Insights
- The README details each component’s responsibilities and rules (for example, what each can or cannot depend on or inherit from).
- It explains the use of a Service Locator design (in CounterDI.cs and PresenterDI.cs) to resolve dependencies, ensuring low coupling among components.

a. Main Components:
- Entity: Business data structures (e.g., Count.cs).
- Gateway: Data access interface (e.g., ICountDBGateway.cs, CountDB.cs).
- Usecase: Business logic layer that performs actions (e.g., CounterUsecase.cs, ICounterUsecase.cs).
- Presenter: Interfaces between the usecase and view (e.g., CountPresenter.cs, ICountPresenter.cs, PresenterDI.cs).
- View: Unity-specific UI components (e.g., CountButtonView.cs, CountTextView.cs, TotalNumberTextView.cs).
- Additionally, include the Dependency Injection components (CounterDI.cs and PresenterDI.cs) that orchestrate the initializations.

b. Relationships and Interactions:
- From View to Presenter: Views call methods on the Presenter's interface.
- From Presenter to Usecase: Presenters invoke business logic via the Usecase interface.
- From Usecase to Gateway (if needed): Usecases access data through Gateway interfaces.
- Entities should be represented as the core business models accessed and acted upon by the Usecase.
- DI system (Service Locator) which creates instances and wires all the above components. Represent these with a centralized “DI Container” node that provides the component connections.

c. Architectural Patterns and Design Principles:
- Loose coupling enforced by having each layer depend only on its listed allowed dependencies.
- That UIView components inherit from Unity’s MonoBehaviour while the core logic (Entity, Usecase, and Gateway) do not.

d. Technologies and Libraries:
- That this project is contained within the Unity GameEngine.
- Mention that only standard C# libraries for EventHandler-based reactive programming are used.
- That no external frameworks or 3rd party DI libraries are used in this simplified example.

##### Final Advice
- Avoid over-generalization—be as specific as possible using the project’s file structure and component names.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% DI Container Subgraph
    subgraph "DI Container"
        di1["CounterDI (DI)"]:::di
        di2["PresenterDI (DI)"]:::di
    end

    %% Entity Layer
    subgraph "Entity Layer"
        e1["Count (Entity)"]:::core
    end

    %% Gateway Layer
    subgraph "Gateway Layer"
        g1["ICountDBGateway (Gateway)"]:::core
        g2["CountDB (Gateway)"]:::core
    end

    %% Usecase Layer
    subgraph "Usecase Layer"
        u1["ICounterUsecase (Usecase)"]:::core
        u2["CounterUsecase (Usecase)"]:::core
    end

    %% Presenter Layer
    subgraph "Presenter Layer"
        p1["ICountPresenter (Presenter)"]:::presentation
        p2["CountPresenter (Presenter)"]:::presentation
    end

    %% View Layer
    subgraph "View Layer"
        v1["CountButtonView (View)"]:::presentation
        v2["CountTextView (View)"]:::presentation
        v3["TotalNumberTextView (View)"]:::presentation
    end

    %% Relationships Between Layers
    %% Presentation Flow: View -> Presenter -> Usecase -> (Entity & Gateway)
    v1 -->|"calls"| p2
    v2 -->|"calls"| p2
    v3 -->|"calls"| p2

    p2 -->|"invokes"| u2

    u2 -->|"manages"| e1
    u2 -->|"accesses"| g1
    u2 -->|"accesses"| g2

    %% Dependency Injection Connections
    di1 --> e1
    di1 --> g1
    di1 --> g2
    di1 --> u1
    di1 --> u2

    di2 --> p1
    di2 --> p2
    di2 --> v1
    di2 --> v2
    di2 --> v3

    %% Optionally show interface relationships within layers
    p1 -.-> p2
    u1 -.-> u2

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px,color:#1B2631;
    classDef presentation fill:#A9DFBF,stroke:#196F3D,stroke-width:2px,color:#145A32;
    classDef di fill:#F9E79F,stroke:#B7950B,stroke-width:2px,color:#7D6608;

    %% Click Events
    click e1 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Enities/Count.cs"
    click g1 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Gateway/ICountDBGateway.cs"
    click g2 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Gateway/CountDB.cs"
    click u1 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Usecases/ICounterUsecase.cs"
    click u2 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Usecases/CounterUsecase.cs"
    click p1 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Presenters/ICountPresenter.cs"
    click p2 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Presenters/CountPresenter.cs"
    click v1 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Views/CountButtonView.cs"
    click v2 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Views/CountTextView.cs"
    click v3 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Views/TotalNumberTextView.cs"
    click di1 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/CounterDI.cs"
    click di2 "https://github.com/genki-tx/unitysimplecleanarchitectureplane/blob/master/Assets/Scripts/Presenters/PresenterDI.cs"
```
