# otiai10/chomex architecture

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

- Interactive diagram: https://gitdiagram.com/otiai10/chomex
- Repository: https://github.com/otiai10/chomex

## Overview

##### Main Components Identification

a) Router Component
- Represents message routing functionality
- Connects to Chrome Extension APIs
- SerialRouter as a variant

b) Client Component
- This on one side of the Router
- Represents the Promise-based message sending interface

c) Model Component
- This on another side
- Includes OnMemoryStorage implementation
- Connected to Chrome's storage system

d) Types Component
- Should be connected to the Model component
- Represents the schema definition system

##### Relationship Representation

a) External Interfaces:
- Chrome Runtime API connection to Router
- Chrome Storage API connection to Model
- Chrome Messaging API connection to Client

b) Internal Flows:
- Client → Router (message flow)
- Router → Controllers (message handling)
- Model → Types (schema validation)
- Model → Storage (data persistence)

##### Specific Elements

**[Chrome Extension APIs]**
- ↕
**[Client] → [Router] ← [Controllers]**
- ↓         ↓
**[Message] → [Handler]**
- ↓
**[Response]**

**[Model] ← [Types]**
- ↕
**[Storage]**

##### Important Details to Highlight

a) Router Features:
- Custom route handling
- Message listener registration
- Controller mapping

b) Client Features:
- Promise-based interface
- Message sending abstraction
- Response handling

c) Model Features:
- Schema validation
- Storage interface
- ActiveRecord-like pattern

##### Implementation Notes

- Use double lines for API boundaries
- Version/npm information

Remember to emphasize the main purpose: facilitating Chrome extension message routing and storage management through a clean, Promise-based API.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Chrome["Chrome Extension APIs"]
        Runtime["Runtime API"]
        Storage["Storage API"]
        Messaging["Messaging API"]
    end

    subgraph Core["Core Components"]
        Router["Router"]:::core
        SerialRouter["Serial Router"]:::core
        Client["Client"]:::core
        Handler["Message Handler"]:::core
    end

    subgraph Data["Data Layer"]
        Model["Model"]:::data
        Types["Types"]:::data
        OnMemory["OnMemory Storage"]:::data
    end

    subgraph Testing["Testing Infrastructure"]
        TestMock["Chrome Mock"]:::test
        TestSetup["Setup Scripts"]:::test
    end

    subgraph Utility["Utility Components"]
        Logger["Logger"]:::utility
    end

    %% Relationships
    Runtime --> Router
    Storage --> Model
    Messaging --> Client

    Client --> Router
    Router --> Handler
    Router --> SerialRouter
    Handler --> Model

    Model --> Types
    Model --> OnMemory
    Model --> Storage

    Logger --> Router
    Logger --> Client
    Logger --> Model

    TestMock -.-> Runtime
    TestMock -.-> Storage
    TestMock -.-> Messaging
    TestSetup -.-> TestMock

    %% Click Events
    click Router "https://github.com/otiai10/chomex/tree/main/src/Router"
    click SerialRouter "https://github.com/otiai10/chomex/blob/main/src/Router/SerialRouter.ts"
    click Client "https://github.com/otiai10/chomex/tree/main/src/Client"
    click Model "https://github.com/otiai10/chomex/tree/main/src/Model"
    click Types "https://github.com/otiai10/chomex/tree/main/src/Model/Types"
    click OnMemory "https://github.com/otiai10/chomex/blob/main/src/Model/OnMemoryStorage.ts"
    click Logger "https://github.com/otiai10/chomex/tree/main/src/Logger"
    click TestMock "https://github.com/otiai10/chomex/blob/main/tests/mock/chrome.ts"
    click TestSetup "https://github.com/otiai10/chomex/blob/main/tests/mock/setup-script.ts"

    %% Styles
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef data fill:#4CAF50,stroke:#2E7D32,color:white
    classDef test fill:#FFC107,stroke:#FFA000,color:black
    classDef utility fill:#9C27B0,stroke:#7B1FA2,color:white

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Data Components"]:::data
        L3["Testing Components"]:::test
        L4["Utility Components"]:::utility
    end
```
