# menloresearch/jan architecture

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

- Interactive diagram: https://gitdiagram.com/menloresearch/jan
- Repository: https://github.com/menloresearch/jan

## Overview

##### Key Components
- Core Engine – Represented by the “core” directory. This component encapsulates the main logic, including browser and node modules, extension management, API processors, events, configuration handling, and type definitions.
- Desktop Application – The “electron” directory clearly defines the desktop client implementation. It handles native window management, tray interactions, OS-specific handlers, preload scripts, and testing components.
- Web Frontend – Found in the “web” directory. This component is built with React (containers, screens, hooks, services) and communicates with the API server. It manages the user interface, layout, routing, and state management (possibly using Jotai as indicated by providers).
- Server/API – The “server” directory is used to set up a local API server (an OpenAI-equivalent) which likely acts as an interface for local client apps (desktop, web, or even external tools) to interface with the AI engine.
- Extensions – The “extensions” folder holds multiple extension packages (e.g., assistant-extension, conversational-extension, engine-management-extension, etc.). These modules provide additional features and can be integrated at runtime. They indicate a plug-in architecture that allows developers to customize or extend core functionalities.
- UI Library – The “joi” directory appears to be a reusable UI component library (buttons, modals, inputs, etc.) that the web front-end and possibly other parts of the app use.

##### Relationships and Interactions
- The Desktop (Electron) and Web frontends communicate with the backend. The API which lives under “server” or parts of “core” handles requests – for example, managing model downloads, starting the local API server, and handling OpenAI-equivalent API requests.
- The “core” component acts as the central orchestrator for managing AI-related tasks, such as handling messages, managing models/extensions, and interfacing with hardware.

##### Architectural Patterns and Design Principles
- Modular/Plugin Architecture: Emphasize how “extensions” integrate with the core (and possibly the UI) using clearly defined interfaces.
- Separation of Concerns: Note the distinct separation between UI (Electron and Web), core logic (core), API server (server), and the underlying AI engine.
- Multi-Platform Support: Illustrate how different front-end clients (desktop vs. web) are maintained and how they interface with common backend services.
- CI/CD & DevOps: Although not critical for runtime operation, mention that automated builds, tests, and deployments (via GitHub workflows, Docker files, etc.) support the system’s development lifecycle.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Frontend Clients"
        D["Desktop Client (Electron)"]:::frontend
        W["Web Client (React Frontend)"]:::frontend
    end

    subgraph "Backend Services"
        A["Local API Server"]:::backend
        C["Core Logic"]:::backend
    end

    E["Extensions"]:::extension
    U["UI Library (Joi)"]:::ui
    X["Cortex (Local AI Engine)"]:::external

    subgraph "DevOps & Documentation"
        DOC["Documentation"]:::devops
        CI["CI/CD & DevOps"]:::devops
    end

    D -->|"REST/API"| A
    W -->|"REST/API"| A
    A -->|"Processes"| C
    C -->|"LoadsPlugins"| E
    C -->|"Integrates"| X
    U -->|"SupportsUI"| W
    DOC -.-> C
    CI -.-> C

    click C "https://github.com/menloresearch/jan/tree/dev/core"
    click D "https://github.com/menloresearch/jan/tree/dev/electron"
    click W "https://github.com/menloresearch/jan/tree/dev/web"
    click A "https://github.com/menloresearch/jan/tree/dev/server"
    click E "https://github.com/menloresearch/jan/tree/dev/extensions"
    click U "https://github.com/menloresearch/jan/tree/dev/joi"
    click DOC "https://github.com/menloresearch/jan/tree/dev/docs"
    click CI "https://github.com/menloresearch/jan/blob/dev/.github"

    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef extension fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef ui fill:#ffe5b4,stroke:#d2691e,stroke-width:2px;
    classDef devops fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
