# remesh-js/remesh architecture

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

- Interactive diagram: https://gitdiagram.com/remesh-js/remesh
- Repository: https://github.com/remesh-js/remesh

## Overview

##### Main Components

a. Core Architecture Layer:
- Domain Layer (Central)
- CQRS Implementation Layer
- Event System Layer
- State Management Layer

b. Integration Components:
- Framework Adapters (React/Vue)
- External Tools Integration
- Developer Tools

**┌─────────────────────────────────────── Remesh System ───────────────────────────────────────┐**

- ┌─────────── Domain Layer ──────────┐                                                      │
- ┌─────────── Framework Adapters ──────────┐     │
- ┌─────────┐      ┌─────────┐    │      │                                         │     │
- States  │      │ Events  │    │      │  ┌─────────┐         ┌─────────┐       │     │
- ┘      └─────────┘    │      │  │ React   │         │  Vue    │       │     │
- Adapter │         │ Adapter │       │     │
- ┌─────────┐      ┌─────────┐    │◄────►│  └─────────┘         └─────────┘       │     │
- Queries │      │Commands │    │      │                                         │     │
- ┘      └─────────┘    │      └─────────────────────────────────────────┘     │

- ┘                                                      │

- ┌─────────── Support Modules ───────┐      ┌─────────── Developer Tools ───────────┐      │

- ┌─────────┐      ┌─────────┐    │      │  ┌──────────┐       ┌──────────┐      │      │
- YJS    │      │ History │    │      │  │  Logger  │       │  Redux   │      │      │
- Module  │      │ Module  │    │      │  │          │       │ DevTools │      │      │
- ┘      └─────────┘    │      │  └──────────┘       └──────────┘      │      │

- ┘      └────────────────────────────────────────┘      │

- ┘

##### Key Elements to Highlight

a. Domain Layer:
- States (immutable data store)
- Queries (read operations)
- Commands (write operations)
- Events (domain events)
- Effects (side effects handling)

b. Framework Integration:
- React Adapter (remesh-react)
- Vue Adapter (remesh-vue)
- Framework-specific hooks and utilities

c. Support Features:
- YJS Integration (collaboration)
- History Module (time-travel)
- Reactive Programming Support
- SSR Capabilities

d. Developer Tools:
- Logger
- Redux DevTools Integration
- Debugging Utilities

##### Implementation Details
- CQRS pattern implementation
- Event-driven architecture
- Reactive programming flow
- Modular structure of domains

##### Additional Notes
- Version information
- TypeScript support
- SSR capabilities
- Integration points with external systems

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph RemeshSystem["Remesh System"]
        subgraph DomainLayer["Domain Layer"]
            States["States"]
            Events["Events"]
            Queries["Queries"]
            Commands["Commands"]
            CoreDomain["Core Domain"]
            TypeDefs["Type Definitions"]
        end

        subgraph FrameworkAdapters["Framework Adapters"]
            ReactAdapter["React Adapter"]
            VueAdapter["Vue Adapter"]
        end

        subgraph SupportModules["Support Modules"]
            YJSModule["YJS Module"]
            HistoryModule["History Module"]
            AsyncModule["Async Module"]
            ListModule["List Module"]
            TreeModule["Tree Module"]
        end

        subgraph DevTools["Developer Tools"]
            Logger["Logger"]
            ReduxDevTools["Redux DevTools"]
            DebuggerHelper["Debugger Helper"]
            Inspector["Inspector"]
        end
    end

    %% Relationships
    CoreDomain --> States
    CoreDomain --> Events
    CoreDomain --> Queries
    CoreDomain --> Commands
    CoreDomain --> TypeDefs
    
    DomainLayer <--> FrameworkAdapters
    DomainLayer <--> SupportModules
    DomainLayer <--> DevTools

    %% Styling
    classDef core fill:#e1f5fe,stroke:#01579b
    classDef framework fill:#e8f5e9,stroke:#1b5e20
    classDef support fill:#fff3e0,stroke:#e65100
    classDef devtools fill:#f3e5f5,stroke:#4a148c

    class States,Events,Queries,Commands,CoreDomain,TypeDefs core
    class ReactAdapter,VueAdapter framework
    class YJSModule,HistoryModule,AsyncModule,ListModule,TreeModule support
    class Logger,ReduxDevTools,DebuggerHelper,Inspector devtools

    %% Click Events
    click CoreDomain "https://github.com/remesh-js/remesh/blob/main/packages/remesh/src/remesh.ts"
    click Queries "https://github.com/remesh-js/remesh/blob/main/packages/remesh/__tests__/query.test.ts"
    click Commands "https://github.com/remesh-js/remesh/blob/main/packages/remesh/__tests__/command.test.ts"
    click Events "https://github.com/remesh-js/remesh/blob/main/packages/remesh/__tests__/event.test.ts"
    click States "https://github.com/remesh-js/remesh/blob/main/packages/remesh/src/store.ts"
    click ReactAdapter "https://github.com/remesh-js/remesh/blob/main/packages/remesh-react/src/remesh-react.tsx"
    click VueAdapter "https://github.com/remesh-js/remesh/blob/main/packages/remesh-vue/src/remesh-vue.ts"
    click Logger "https://github.com/remesh-js/remesh/blob/main/packages/remesh-logger/src/remesh-logger.ts"
    click ReduxDevTools "https://github.com/remesh-js/remesh/blob/main/packages/remesh-redux-devtools/src/remesh-redux-devtools.ts"
    click DebuggerHelper "https://github.com/remesh-js/remesh/blob/main/packages/remesh-debugger-helper/src/remesh-debugger-helper.ts"
    click YJSModule "https://github.com/remesh-js/remesh/blob/main/packages/remesh-yjs/src/remesh-yjs.ts"
    click HistoryModule "https://github.com/remesh-js/remesh/blob/main/packages/remesh/src/modules/history.ts"
    click AsyncModule "https://github.com/remesh-js/remesh/blob/main/packages/remesh/src/modules/async.ts"
    click ListModule "https://github.com/remesh-js/remesh/blob/main/packages/remesh/src/modules/list.ts"
    click TreeModule "https://github.com/remesh-js/remesh/blob/main/packages/remesh/src/modules/tree.ts"
    click TypeDefs "https://github.com/remesh-js/remesh/blob/main/packages/remesh/src/type.ts"
    click Inspector "https://github.com/remesh-js/remesh/blob/main/packages/remesh/src/inspector.ts"
```
