# morpheusais/node architecture

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

- Interactive diagram: https://gitdiagram.com/morpheusais/node
- Repository: https://github.com/morpheusais/node

## Overview

1. **What this repo is**
   This is a cross-platform desktop application built with Electron, packaged as the Morpheus Lite Client. The app ships as a native executable for Windows, macOS, and Linux, with the build/release pipeline managed from the repository itself.

2. **Top-level runtime split**
   The architecture is the standard Electron split: a **main/backend process** in `src/backend`, a **renderer/frontend UI** in `src/frontend`, and a **preload bridge** that exposes controlled IPC between the two. That boundary is the core architectural seam in the project.

3. **Main process responsibilities**
   `src/backend/index.ts`, `handlers.ts`, `renderer.ts`, and `preload.ts` indicate the main process creates the app window, loads the UI, and registers IPC handlers. It also mediates access to local system features and services instead of letting the frontend talk to the OS directly.

4. **Backend service layer**
   `src/backend/services` contains the app’s non-UI business logic: logging, system integration, prompt management, Ollama integration, and model metadata. This layer is where local AI behavior is orchestrated and where side effects are centralized.

5. **Local AI integration**
   The presence of `src/backend/services/ollama.ts`, `ai-models.ts`, and embedded executables under `src/executables/ollama-*` shows the app bundles or manages a local Ollama runtime rather than relying only on a remote API. The backend is responsible for starting, checking, or talking to that runtime and translating app requests into model operations.

6. **State and persistence**
   `src/backend/storage.ts` suggests local persistence for user/app configuration or runtime state. Based on the UI structure, this likely includes saved preferences, directories, connection state, and other session-related values that must survive app restarts.

7. **Frontend application structure**
   The renderer is a React-based single-page interface organized into reusable components, layout pieces, modals, views, and utility layers. The main user-facing screens are `home`, `chat`, and `settings`, which implies the app centers on an interactive AI/chat workflow plus configuration.

8. **Frontend-to-backend data flow**
   UI actions in the frontend likely trigger IPC events through the preload bridge, then the backend executes system or Ollama operations and returns results to the renderer. This keeps privileged work in the main process while the frontend remains a presentation and interaction layer.

9. **UI composition**
   The component tree is organized around app shells and interaction primitives: top bar, bottom bar, navigation, and modal dialogs. Specialized controls such as wallet and MetaMask buttons indicate the UI also supports crypto/wallet-related actions, probably as a secondary integration surface.

10. **Routing, theme, and shared client utilities**
    `router.tsx`, `theme/`, `contexts.tsx`, `hooks.tsx`, and `utils/` indicate the renderer has its own client-side routing, theming system, and shared state/helpers. `chain.ts` and `transaction.ts` suggest some frontend logic is domain-specific to blockchain or wallet operations.

11. **Packaging and build pipeline**
    The repo uses Electron Forge configuration (`forge.config.ts`) plus Webpack configs for the main and renderer bundles. GitHub Actions workflows, Husky pre-commit hooks, and setup scripts support validation, formatting, and release automation. The README’s `yarn` and `yarn make` flow reflects the packaging pipeline used to produce the distributable app.

12. **Platform and deployment boundaries**
    The `.setup` scripts and platform-specific Ollama binaries show the app has explicit cross-platform support with extra validation for local host setup, especially on macOS and Windows. The Windows instructions in the README confirm the final artifact is a standalone desktop executable rather than a hosted web deployment.

13. **How to diagram it**
    A good architecture diagram would show: user → Electron app shell → React renderer UI; renderer ↔ preload ↔ main process IPC; main process ↔ local services/storage/system; main process ↔ embedded Ollama runtime; and build/release tooling around the whole repo. The important boundary is between untrusted UI code and privileged backend/service code.

Main entry points: [`src/backend/services`](https://github.com/morpheusais/node/tree/main/src/backend/services) (Services), [`src/frontend`](https://github.com/morpheusais/node/tree/main/src/frontend) (Frontend app), [`src/frontend/components/layout`](https://github.com/morpheusais/node/tree/main/src/frontend/components/layout) (App shell), [`forge.config.ts`](https://github.com/morpheusais/node/blob/main/forge.config.ts) (Build tooling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_electron_shell["Electron shell<br/>desktop host"]
  node_ollama_binaries["Ollama binaries<br/>bundled executables"]
end

subgraph group_backend["Backend"]
  node_main_process["Main process<br/>electron main<br/>[index.ts]"]
  node_ipc_handlers["IPC handlers<br/>electron IPC<br/>[handlers.ts]"]
  node_preload_bridge["Preload bridge<br/>secure bridge<br/>[preload.ts]"]
  node_window_host["Window host<br/>renderer host<br/>[renderer.ts]"]
  node_backend_services["Services<br/>service layer"]
  node_ollama_service["Ollama service<br/>local AI runtime<br/>[ollama.ts]"]
  node_storage_layer[("Storage<br/>local persistence<br/>[storage.ts]")]
  node_model_catalog["Model catalog<br/>model metadata<br/>[ai-models.ts]"]
  node_system_service["System service<br/>host integration<br/>[system.ts]"]
  node_logger_service["Logger<br/>telemetry/logging<br/>[logger.ts]"]
end

subgraph group_frontend["Frontend"]
  node_frontend_app["Frontend app<br/>react renderer"]
  node_app_shell["App shell<br/>layout"]
  node_views["Views<br/>screens"]
  node_modals["Modals<br/>overlay ui"]
  node_wallet_ui["Wallet UI<br/>crypto integration"]
  node_client_shared["Shared client<br/>client utilities<br/>[router.tsx]"]
end

subgraph group_build["Build"]
  node_build_tooling["Build tooling<br/>packaging pipeline<br/>[forge.config.ts]"]
end

node_electron_shell -->|"starts"| node_main_process
node_main_process -->|"creates"| node_window_host
node_window_host -->|"loads"| node_frontend_app
node_frontend_app -->|"composes"| node_app_shell
node_app_shell -->|"navigates"| node_views
node_app_shell -->|"opens"| node_modals
node_app_shell -->|"hosts"| node_wallet_ui
node_frontend_app -->|"uses"| node_client_shared
node_frontend_app -->|"calls"| node_preload_bridge
node_preload_bridge -->|"forwards"| node_ipc_handlers
node_ipc_handlers -->|"delegates"| node_backend_services
node_backend_services -->|"orchestrates"| node_ollama_service
node_backend_services -->|"persists"| node_storage_layer
node_backend_services -->|"accesses"| node_system_service
node_backend_services -->|"logs"| node_logger_service
node_ollama_service -->|"executes"| node_ollama_binaries
node_ollama_service -->|"selects"| node_model_catalog
node_build_tooling -->|"bundles"| node_main_process
node_build_tooling -->|"bundles"| node_frontend_app
node_build_tooling -->|"ships"| node_ollama_binaries

click node_main_process "https://github.com/morpheusais/node/blob/main/src/backend/index.ts"
click node_ipc_handlers "https://github.com/morpheusais/node/blob/main/src/backend/handlers.ts"
click node_preload_bridge "https://github.com/morpheusais/node/blob/main/src/backend/preload.ts"
click node_window_host "https://github.com/morpheusais/node/blob/main/src/backend/renderer.ts"
click node_backend_services "https://github.com/morpheusais/node/tree/main/src/backend/services"
click node_ollama_service "https://github.com/morpheusais/node/blob/main/src/backend/services/ollama.ts"
click node_storage_layer "https://github.com/morpheusais/node/blob/main/src/backend/storage.ts"
click node_model_catalog "https://github.com/morpheusais/node/blob/main/src/backend/ai-models.ts"
click node_system_service "https://github.com/morpheusais/node/blob/main/src/backend/services/system.ts"
click node_logger_service "https://github.com/morpheusais/node/blob/main/src/backend/services/logger.ts"
click node_frontend_app "https://github.com/morpheusais/node/tree/main/src/frontend"
click node_app_shell "https://github.com/morpheusais/node/tree/main/src/frontend/components/layout"
click node_views "https://github.com/morpheusais/node/tree/main/src/frontend/views"
click node_modals "https://github.com/morpheusais/node/tree/main/src/frontend/components/modals"
click node_wallet_ui "https://github.com/morpheusais/node/tree/main/src/frontend/components/buttons"
click node_client_shared "https://github.com/morpheusais/node/blob/main/src/frontend/router.tsx"
click node_ollama_binaries "https://github.com/morpheusais/node/tree/main/src/executables"
click node_build_tooling "https://github.com/morpheusais/node/blob/main/forge.config.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_electron_shell,node_ollama_binaries toneBlue
class node_main_process,node_ipc_handlers,node_preload_bridge,node_window_host,node_backend_services,node_ollama_service,node_storage_layer,node_model_catalog,node_system_service,node_logger_service toneAmber
class node_frontend_app,node_app_shell,node_views,node_modals,node_wallet_ui,node_client_shared toneMint
class node_build_tooling toneRose
```

## Components

### Runtime

Electron app runtime boundaries and execution flow

- **Electron shell**: desktop host · Native app container that launches the main process and renderer
- [Ollama binaries](https://github.com/morpheusais/node/tree/main/src/executables): bundled executables · Platform-specific shipped runtime binaries for local AI support · `src/executables`

### Backend

Privileged main-process code and local services

- [Main process](https://github.com/morpheusais/node/blob/main/src/backend/index.ts): electron main · Creates the window, wires IPC, and mediates privileged operations · `src/backend/index.ts`
- [IPC handlers](https://github.com/morpheusais/node/blob/main/src/backend/handlers.ts): electron IPC · Request/response layer between renderer and backend services · `src/backend/handlers.ts`
- [Preload bridge](https://github.com/morpheusais/node/blob/main/src/backend/preload.ts): secure bridge · Controlled exposure of backend APIs to the renderer · `src/backend/preload.ts`
- [Window host](https://github.com/morpheusais/node/blob/main/src/backend/renderer.ts): renderer host · Loads the packaged frontend into the Electron window · `src/backend/renderer.ts`
- [Services](https://github.com/morpheusais/node/tree/main/src/backend/services): service layer · Centralized backend logic for logging, prompts, system access, and model orchestration · `src/backend/services`
- [Ollama service](https://github.com/morpheusais/node/blob/main/src/backend/services/ollama.ts): local AI runtime · Starts, checks, and talks to the bundled Ollama runtime · `src/backend/services/ollama.ts`
- [Storage](https://github.com/morpheusais/node/blob/main/src/backend/storage.ts): local persistence · App state and configuration persisted across launches · `src/backend/storage.ts`
- [Model catalog](https://github.com/morpheusais/node/blob/main/src/backend/ai-models.ts): model metadata · Backend model definitions and AI model selection data · `src/backend/ai-models.ts`
- [System service](https://github.com/morpheusais/node/blob/main/src/backend/services/system.ts): host integration · Access to local OS features and environment checks · `src/backend/services/system.ts`
- [Logger](https://github.com/morpheusais/node/blob/main/src/backend/services/logger.ts): telemetry/logging · Structured logging for backend activity and diagnostics · `src/backend/services/logger.ts`

### Frontend

Renderer UI and client-side application structure

- [Frontend app](https://github.com/morpheusais/node/tree/main/src/frontend): react renderer · Single-page client UI with routing, state, and shared presentation logic · `src/frontend`
- [App shell](https://github.com/morpheusais/node/tree/main/src/frontend/components/layout): layout · Top-level UI frame with navigation and persistent chrome · `src/frontend/components/layout`
- [Views](https://github.com/morpheusais/node/tree/main/src/frontend/views): screens · Primary user screens for home, chat, and settings · `src/frontend/views`
- [Modals](https://github.com/morpheusais/node/tree/main/src/frontend/components/modals): overlay ui · Dialog surfaces for directory selection, QR, and wallet flows · `src/frontend/components/modals`
- [Wallet UI](https://github.com/morpheusais/node/tree/main/src/frontend/components/buttons): crypto integration · Wallet and MetaMask entry points in the interface · `src/frontend/components/buttons`
- [Shared client](https://github.com/morpheusais/node/blob/main/src/frontend/router.tsx): client utilities · Routing, theme, contexts, hooks, helpers, and domain utilities · `src/frontend/router.tsx`

### Build

Packaging, validation, and release automation

- [Build tooling](https://github.com/morpheusais/node/blob/main/forge.config.ts): packaging pipeline · Electron Forge, Webpack, workflows, and setup scripts for validation and release · `forge.config.ts`

## Connections

- Electron shell → Main process: starts · The desktop container launches the Electron main process
- Main process → Window host: creates · Main process creates and configures the app window
- Window host → Frontend app: loads · The browser window loads the renderer bundle
- Frontend app → App shell: composes · Frontend is organized around a persistent application shell
- App shell → Views: navigates · Shell routes users between home, chat, and settings screens
- App shell → Modals: opens · Shell-triggered overlays handle dialogs and transient flows
- App shell → Wallet UI: hosts · Shell includes wallet and MetaMask-related actions
- Frontend app → Shared client: uses · Renderer relies on shared routing, theme, state, and helpers
- Frontend app → Preload bridge: calls · UI talks to privileged APIs through the preload boundary
- Preload bridge → IPC handlers: forwards · Preload forwards approved renderer requests into IPC
- IPC handlers → Services: delegates · Handlers route work into backend service modules
- Services → Ollama service: orchestrates · Service layer manages local model/runtime interactions
- Services → Storage: persists · Backend stores config and session state locally
- Services → System service: accesses · Backend reaches host features through a dedicated system layer
- Services → Logger: logs · Services emit runtime and diagnostic logs
- Ollama service → Ollama binaries: executes · Backend uses bundled platform-specific Ollama binaries
- Ollama service → Model catalog: selects · Runtime uses model metadata to choose and describe models
- Build tooling → Main process: bundles · Tooling packages the main process for desktop distribution
- Build tooling → Frontend app: bundles · Tooling builds the renderer bundle
- Build tooling → Ollama binaries: ships · Release pipeline includes embedded executables
