How morpheusais/node works
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: services Services · frontend Frontend app · layout App shell · forge.config.ts Build tooling
Components 19
Runtime
Electron app runtime boundaries and execution flow
- Electron shell · Native app container that launches the main process and renderer
- Ollama binaries · Platform-specific shipped runtime binaries for local AI support
src/executables
Backend
Privileged main-process code and local services
- Main process · Creates the window, wires IPC, and mediates privileged operations
src/backend/index.ts - IPC handlers · Request/response layer between renderer and backend services
src/backend/handlers.ts - Preload bridge · Controlled exposure of backend APIs to the renderer
src/backend/preload.ts - Window host · Loads the packaged frontend into the Electron window
src/backend/renderer.ts - Services · Centralized backend logic for logging, prompts, system access, and model orchestration
src/backend/services - Ollama service · Starts, checks, and talks to the bundled Ollama runtime
src/backend/services/ollama.ts - Storage · App state and configuration persisted across launches
src/backend/storage.ts - Model catalog · Backend model definitions and AI model selection data
src/backend/ai-models.ts - System service · Access to local OS features and environment checks
src/backend/services/system.ts - Logger · Structured logging for backend activity and diagnostics
src/backend/services/logger.ts
Frontend
Renderer UI and client-side application structure
- Frontend app · Single-page client UI with routing, state, and shared presentation logic
src/frontend - App shell · Top-level UI frame with navigation and persistent chrome
src/frontend/components/layout - Views · Primary user screens for home, chat, and settings
src/frontend/views - Modals · Dialog surfaces for directory selection, QR, and wallet flows
src/frontend/components/modals - Wallet UI · Wallet and MetaMask entry points in the interface
src/frontend/components/buttons - Shared client · Routing, theme, contexts, hooks, helpers, and domain utilities
src/frontend/router.tsx
Build
Packaging, validation, and release automation
- Build tooling · Electron Forge, Webpack, workflows, and setup scripts for validation and release
forge.config.ts
Connections 20
- 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