# hypermodeinc/modus architecture

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

- Interactive diagram: https://gitdiagram.com/hypermodeinc/modus
- Repository: https://github.com/hypermodeinc/modus

## Overview

##### Main Components

a. Core Runtime Layer:
- WebAssembly Execution Environment (based on Wazero)
- Function Invocation Manager
- Memory Management System
- Host Functions Interface

b. SDK Layer:
- AssemblyScript SDK
- Go SDK
- Language-specific Type Handlers
- Common API Interfaces

c. CLI Layer:
- Project Management Tools
- Development Server
- Build System
- Runtime Management

d. Integration Layer:
- GraphQL API Gateway
- Database Connectors (PostgreSQL, Neo4j, DGraph)
- AI Model Integrations
- Authentication System

##### Component Relationships

**[CLI Layer] → [Runtime Layer]**
- ↑
- [Integration Layer] ← [SDK Layer]

##### Detailed Component Breakdown

a. Runtime Core (from /runtime directory):
- Surrounding modules:
- Collections Management (/runtime/collections)
- Function Management (/runtime/functions)
- Host Functions (/runtime/hostfunctions)
- Language Support (/runtime/langsupport)

b. SDK Components (from /sdk directory):
- Create two parallel tracks for AssemblyScript and Go SDKs
- Shared components:
- Authentication
- Database Access
- HTTP Client
- Model Integration
- Vector Operations

c. CLI Architecture (from /cli directory):
- Command hierarchy:
- Build Commands
- Development Tools
- Runtime Management
- SDK Management

d. Integration Systems:
- Database Connectors
- AI Model Integration
- Authentication Services
- GraphQL API Layer

##### Data Flow Indicators

- Function invocation flow
- Data access patterns
- SDK communication paths
- CLI interaction paths

##### Architectural Patterns to Highlight

- Serverless Execution Model
- Plugin Architecture
- Language-Agnostic Design
- Security Sandboxing
- API-First Approach

##### The security boundaries and sandboxing

This system design should provide a clear understanding of how Modus works as a serverless framework while highlighting its key features and architectural decisions.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Core["Core Runtime Layer"]
        WasmEnv[("WebAssembly Environment")]:::core
        FuncInv["Function Invocation Manager"]:::core
        HostFunc["Host Functions Interface"]:::core
        LangSupp["Language Support System"]:::core
        MemMgmt["Memory Management"]:::core
        CollMgmt["Collections Management"]:::core
        PlugSys["Plugin System"]:::core
        StorSys["Storage System"]:::core
        ConfigMgmt["Configuration Management"]:::core
        MetricsSys["Metrics System"]:::core
    end

    subgraph SDK["SDK Layer"]
        AScript["AssemblyScript SDK"]:::sdk
        GoSDK["Go SDK"]:::sdk
        TypeHand["Language Type Handlers"]:::sdk
        APIInt["Common API Interfaces"]:::sdk
    end

    subgraph CLI["CLI Layer"]
        ProjMgmt["Project Management"]:::cli
        DevServ["Development Server"]:::cli
        BuildSys["Build System"]:::cli
        RuntimeMgmt["Runtime Management"]:::cli
    end

    subgraph Integration["Integration Layer"]
        GraphQL["GraphQL API Gateway"]:::integration
        DBConn{"Database Connectors"}:::integration
        AIModels["AI Model Integration"]:::integration
        AuthSys["Authentication System"]:::integration
    end

    %% Relationships
    CLI --> Core
    Integration --> Core
    SDK --> Integration
    
    %% Core Layer Internal Relations
    WasmEnv --> FuncInv
    WasmEnv --> HostFunc
    WasmEnv --> LangSupp
    WasmEnv --> MemMgmt
    WasmEnv --> CollMgmt
    WasmEnv --> PlugSys
    WasmEnv --> StorSys
    WasmEnv --> ConfigMgmt
    WasmEnv --> MetricsSys

    %% Integration Layer Internal Relations
    DBConn --> GraphQL
    AIModels --> GraphQL
    AuthSys --> GraphQL

    %% SDK Layer Internal Relations
    APIInt --> AScript
    APIInt --> GoSDK
    TypeHand --> AScript
    TypeHand --> GoSDK

    %% CLI Layer Internal Relations
    ProjMgmt --> DevServ
    ProjMgmt --> BuildSys
    ProjMgmt --> RuntimeMgmt

    %% Click Events
    click WasmEnv "https://github.com/hypermodeinc/modus/tree/main/runtime/wasmhost"
    click FuncInv "https://github.com/hypermodeinc/modus/tree/main/runtime/functions"
    click HostFunc "https://github.com/hypermodeinc/modus/tree/main/runtime/hostfunctions"
    click LangSupp "https://github.com/hypermodeinc/modus/tree/main/runtime/langsupport"
    click AScript "https://github.com/hypermodeinc/modus/tree/main/sdk/assemblyscript"
    click GoSDK "https://github.com/hypermodeinc/modus/tree/main/sdk/go"
    click TypeHand "https://github.com/hypermodeinc/modus/tree/main/runtime/languages"
    click APIInt "https://github.com/hypermodeinc/modus/tree/main/runtime/hostfunctions"
    click ProjMgmt "https://github.com/hypermodeinc/modus/tree/main/cli/src/commands"
    click DevServ "https://github.com/hypermodeinc/modus/tree/main/cli/src/commands/dev"
    click BuildSys "https://github.com/hypermodeinc/modus/tree/main/cli/src/commands/build"
    click RuntimeMgmt "https://github.com/hypermodeinc/modus/tree/main/cli/src/commands/runtime"
    click GraphQL "https://github.com/hypermodeinc/modus/tree/main/runtime/graphql"
    click AuthSys "https://github.com/hypermodeinc/modus/tree/main/runtime/middleware"
    click AIModels "https://github.com/hypermodeinc/modus/tree/main/runtime/models"
    click CollMgmt "https://github.com/hypermodeinc/modus/tree/main/runtime/collections"
    click PlugSys "https://github.com/hypermodeinc/modus/tree/main/runtime/pluginmanager"
    click StorSys "https://github.com/hypermodeinc/modus/tree/main/runtime/storage"
    click ConfigMgmt "https://github.com/hypermodeinc/modus/tree/main/runtime/config"
    click MetricsSys "https://github.com/hypermodeinc/modus/tree/main/runtime/metrics"

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef sdk fill:#2ecc71,stroke:#27ae60,color:white
    classDef cli fill:#e67e22,stroke:#d35400,color:white
    classDef integration fill:#9b59b6,stroke:#8e44ad,color:white

    %% Legend
    subgraph Legend
        CoreL[Core Components]:::core
        SDKL[SDK Components]:::sdk
        CLIL[CLI Components]:::cli
        IntL[Integration Components]:::integration
    end
```
