# actuallab/fusion architecture

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

- Interactive diagram: https://gitdiagram.com/actuallab/fusion
- Repository: https://github.com/actuallab/fusion

## Overview

##### Main Components and Their Relationships

a) Core Components:
- Compute Services Layer
- ComputedRegistry
- ComputedState
- Invalidation System
- Dependency Tracking System

b) Client-Server Communication:
- RPC Layer (ActualLab.Rpc)
- WebSocket Communication
- Message Serialization
- Client Proxies
- Server Endpoints

c) Integration Components:
- Blazor Integration
- State Management
- UI Components
- Authentication
- Entity Framework Integration
- Database Operations
- Caching Layer
- Event Processing

##### Key Flows to Highlight

a) Compute Method Flow:
**Client Request → Compute Service → Dependency Tracking → Cache/Storage → Response**

b) Invalidation Flow:
**State Change → Invalidation System → Dependency Graph → Affected Components → UI Updates**

c) Real-time Updates:
**Data Change → Server → WebSocket → Client Cache → UI Component**

##### Implementation Details

Technical aspects:

a) Caching Layer:
- In-memory computed results
- Distributed cache coordination
- Cache invalidation paths

b) RPC System:
- WebSocket connections
- Message serialization
- Client-side caching
- Server-side processing

##### Cross-Cutting Concerns

Aspects:

- Authentication/Authorization
- Error Handling
- Performance Monitoring
- Scaling Capabilities

##### Notes

Important notes about:
- Scaling considerations
- Deployment options
- Performance characteristics
- Integration points

Remember to emphasize how Fusion's architecture enables its key features:
- Transparent caching
- Real-time updates
- Distributed dependency tracking
- Efficient RPC communication
- UI state management

This will create a comprehensive yet accessible visualization of Fusion's architecture that accurately represents its sophisticated capabilities while remaining clear and useful for technical discussions.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Components"]
        CR["ComputedRegistry"]:::core
        CS["ComputedState"]:::core
        IS["Invalidation System"]:::core
        DT["Dependency Tracking"]:::core
        
        CR --> CS
        CS --> IS
        IS --> DT
        DT --> CR
    end

    subgraph RPCLayer["RPC Layer"]
        WS["WebSocket Communication"]:::rpc
        MS["Message Serialization"]:::rpc
        CP["Client Proxies"]:::rpc
        SE["Server Endpoints"]:::rpc
        
        WS --> MS
        MS --> CP
        CP --> SE
    end

    subgraph Integration["Integration Components"]
        subgraph Blazor["Blazor Integration"]
            BC["Components"]:::integration
            BA["Authentication"]:::integration
            BSM["State Management"]:::integration
        end
        
        subgraph EF["Entity Framework Integration"]
            DB[(Database)]:::storage
            Cache[(Cache)]:::storage
            EP["Event Processing"]:::integration
            
            DB --> Cache
            Cache --> EP
        end
    end

    subgraph CrossCutting["Cross-Cutting Concerns"]
        Auth["Authentication/Authorization"]:::security
        EH["Error Handling"]:::system
        PM["Performance Monitoring"]:::system
    end

    %% Main Flows
    Core --> RPCLayer
    RPCLayer --> Integration
    Integration --> CrossCutting
    CrossCutting --> Core

    %% Click Events
    click CR "https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Fusion/ComputedRegistry.cs"
    click CS "https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Fusion/State/ComputedState.cs"
    click IS "https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Fusion/Invalidation.cs"
    click DT "https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Fusion/Internal/ComputedImpl.cs"
    click WS "https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Rpc/WebSockets/WebSocketChannel.cs"
    click MS "https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Rpc/Serialization/RpcMessageSerializer.cs"
    click CP "https://github.com/ActualLab/Fusion/blob/master/src/ActualLab.Rpc/RpcClient.cs"
    click SE "https://github.com/ActualLab/Fusion/tree/master/src/ActualLab.Fusion.Server/Endpoints/"
    click BC "https://github.com/ActualLab/Fusion/tree/master/src/ActualLab.Fusion.Blazor/Components/"
    click BA "https://github.com/ActualLab/Fusion/tree/master/src/ActualLab.Fusion.Blazor.Authentication/"
    click BSM "https://github.com/ActualLab/Fusion/tree/master/src/ActualLab.Fusion/State/"
    click EP "https://github.com/ActualLab/Fusion/tree/master/src/ActualLab.Fusion.EntityFramework/Operations/"
    click Auth "https://github.com/ActualLab/Fusion/tree/master/src/ActualLab.Fusion.Ext.Services/Authentication/"

    classDef core fill:#2374ab,stroke:#2374ab,color:#fff
    classDef rpc fill:#ff7f50,stroke:#ff7f50,color:#fff
    classDef integration fill:#4caf50,stroke:#4caf50,color:#fff
    classDef storage fill:#666,stroke:#666,color:#fff
    classDef security fill:#e91e63,stroke:#e91e63,color:#fff
    classDef system fill:#795548,stroke:#795548,color:#fff

    %% Legend
    subgraph Legend
        L1["Core Component"]:::core
        L2["RPC Component"]:::rpc
        L3["Integration Component"]:::integration
        L4[(Storage)]:::storage
        L5["Security"]:::security
        L6["System"]:::system
    end
```
