# nanbingxyz/5ire architecture

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

- Interactive diagram: https://gitdiagram.com/nanbingxyz/5ire
- Repository: https://github.com/nanbingxyz/5ire

## Overview

Based on your file tree and README, this project is an Electron‐based desktop application that functions as a sleek AI chat assistant and an MCP client. It integrates multiple AI/chat provider services (e.g., OpenAI, Anthropic, Azure, etc.), offers local knowledge base support via document vectorization, usage analytics, bookmarks, quick search, and a prompts library—all packaged within an Electron environment. The project follows a modular architecture with clear separations between the main process (back-end) and the renderer (front-end) components, as well as dedicated service/provider layers for interacting with various AI models and tools.

##### Main Components
- Electron Shell – Highlight the two primary processes:
- Main Process: Represented by “src/main”. This process handles application bootstrapping, window management, system-level integrations, IPC (Inter-Process Communication), and native functionalities like window creation, encryption, and file system access.
- Renderer Process: Represented by “src/renderer”. This includes the user interface built with React (TSX), CSS/SCSS, various pages (chat, knowledge, settings, etc.), and components for analytics, bookmarks, and prompts.
- Intellichat Module – Found in “src/intellichat” along with its “readers”, “services”, and “validators”. This layer abstracts how different AI/chat providers are interfaced:
- Providers/Readers (e.g., OpenAIReader, AnthropicReader, etc.) serve as adapters to various external chat service APIs.
- Service Layer (in “src/intellichat/services” and “src/providers”) provides the business logic to orchestrate requests and responses with these external systems.
- MCP Tools & Server Integration – Indicated in the README and the corresponding installation requirements (Python, Node.js, uv). This outlines how the application can leverage MCP servers to enable tool features (e.g., file system access, remote data fetching).
- Build, Configuration, and Auxiliary Scripts – In directories like “.erb/configs” and “.erb/scripts”, representing the build system (webpack configurations, linting, packaging for Mac notarization, etc.) and development tooling.

##### Relationships and Interactions
- Within the Main Process:
- Interactions with “src/main” components (like crypt, docloader, downloader, menu, preload, etc.) that facilitate initialization, logging, and system-level operations.
- In the Renderer Process:
- How components and pages are organized (e.g., chat pages, knowledge management pages, settings, tool marketplace page).
- “src/renderer/components”, “src/renderer/pages”, and the state management files in “src/stores” to indicate the front-end module boundaries.
- Intellichat & Providers:
- External Dependencies:
- External components such as MCP servers and external APIs (for multiple AI service providers) as external modules interfaced via defined protocols (MCP protocol, REST APIs, etc.).
- That they feed into the Intellichat/provider layer.

##### Architectural Patterns and Design Principles
- Use the separation of concerns principle: distinctly separate UI (renderer) from the system’s control logic (main process and services).
- Provider/Adapter pattern in how the Intellichat module abstracts various AI integrations, facilitating easy extension with new providers.
- That the system uses a modular architecture, where each functional module (chat, knowledge, analytics, tools) is self-contained but interconnected via clear APIs or IPC channels.

##### Relevant Technologies & Frameworks
- Electron (for Desktop application framework and IPC between main/renderer processes).
- React and TypeScript (for the UI, located under “src/renderer”).
- Webpack (as evidenced by multiple webpack configuration files for different environments—dev/prod—for main, renderer, and preload processes).
- Node.js and Python (as runtime dependencies for MCP server interactions and local tool integrations).
- State Management and utility libraries (e.g., custom hooks in “src/hooks”, stores in “src/stores”).
- Linting/Formatting tools (ESLint, Stylelint, .editorconfig).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Electron Shell"
        ME["Electron Main Process"]:::backend
        RE["Renderer Process (UI with React)"]:::frontend
        ME <-->|"IPC"| RE
    end

    subgraph "Business Logic"
        IC["Intellichat Module"]:::module
        Readers["AI Providers - Readers"]:::module
        PServ1["AI Providers - Services (Intellichat)"]:::module
        PServ2["AI Providers - Services (External)"]:::module
        IC --> Readers
        IC --> PServ1
        IC --> PServ2
        PServ1 -->|"calls"| ExtAPI["External AI APIs"]:::external
        PServ2 -->|"calls"| ExtAPI
    end

    subgraph "MCP Integration"
        MCP1["mcp.ts"]:::mcp
        MCP2["mcp.config.ts"]:::mcp
        MCP3["useMCPStore.ts"]:::mcp
        MCP4["useMCPServerMarketStore.ts"]:::mcp
        ME -->|"executes"| MCP1
        MCP1 --> MCP2
        MCP1 --> MCP3
        MCP1 --> MCP4
        MCP1 -->|"fetches"| MCPServer["MCP Servers"]:::external
    end

    subgraph "Build & Config"
        Configs["Configs"]:::config
        Scripts["Scripts"]:::config
        Configs -->|"build"| Scripts
    end

    RE -->|"requests"| IC

    click ME "https://github.com/nanbingxyz/5ire/tree/main/src/main"
    click RE "https://github.com/nanbingxyz/5ire/tree/main/src/renderer"
    click IC "https://github.com/nanbingxyz/5ire/tree/main/src/intellichat"
    click Readers "https://github.com/nanbingxyz/5ire/tree/main/src/intellichat/readers"
    click PServ1 "https://github.com/nanbingxyz/5ire/tree/main/src/intellichat/services"
    click PServ2 "https://github.com/nanbingxyz/5ire/tree/main/src/providers"
    click MCP1 "https://github.com/nanbingxyz/5ire/blob/main/src/main/mcp.ts"
    click MCP2 "https://github.com/nanbingxyz/5ire/blob/main/src/mcp.config.ts"
    click MCP3 "https://github.com/nanbingxyz/5ire/blob/main/src/stores/useMCPStore.ts"
    click MCP4 "https://github.com/nanbingxyz/5ire/blob/main/src/stores/useMCPServerMarketStore.ts"
    click Configs "https://github.com/nanbingxyz/5ire/tree/main/.erb/configs"
    click Scripts "https://github.com/nanbingxyz/5ire/tree/main/.erb/scripts"

    classDef backend fill:#ffdddd,stroke:#b30000,stroke-width:2px;
    classDef frontend fill:#ddffdd,stroke:#008000,stroke-width:2px;
    classDef module fill:#ddeeff,stroke:#003366,stroke-width:2px;
    classDef external fill:#fffacc,stroke:#996600,stroke-width:2px;
    classDef mcp fill:#e6ccff,stroke:#660099,stroke-width:2px;
    classDef config fill:#ffd700,stroke:#b8860b,stroke-width:2px;
```
