# riffcc/flagship architecture

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

- Interactive diagram: https://gitdiagram.com/riffcc/flagship
- Repository: https://github.com/riffcc/flagship

## Overview

##### And Lay Out the Main Components

a. Electron Main Process:
- Location: packages/main
- Key files: index.ts, constellation.ts, http.ts, mainWindow.ts, security-restrictions.ts, systèmeFichiers.ts
- Role: Initializes Electron, creates windows, manages security restrictions, and sets up the application environment.

b. Preload Scripts:
- Location: packages/preload
- Key files: index.ts, http.ts, so.ts, systèmeFichiers.ts
- Role: Acts as a secure bridge between the Electron main process and the renderer. It exposes limited APIs to the renderer for controlled communication.

c. Renderer (User Interface):
- Location: packages/renderer
- Key files: indexBrowser.html, indexElectron.html, index.ts, multiple Vue component files and views under src/
- Role: Provides the front-end UI using Vue. It handles user interactions, displays application pages (account, admin, home, upload, etc.), and leverages plugins (like Constellation and Inscription) and composables to manage state and features.

d. External Services and Components:
- Decentralized/Distributed data handling using OrbitDB, Constellation, and IPFS.
- Moderation Database: As described in installation instructions (copying the VITE_SITE_ID from the app startup).
- APIs / HTTP communications that are set up in several modules (see http.ts in both main and preload).

e. Build, Configuration & Testing:
- Build Tools: Vite (configured in each package), Electron Builder (electron-builder.config.cjs), and various configuration files for ESLint, Prettier, etc.
- Testing and CI: GitHub Actions workflows (in .github/workflows/) and testing directories (packages/*/tests, tests/e2e.spec.ts, vitest.config.js).

##### Interactions & Data Flow

- Communication Flow:
– The Main process, which sets up the Electron windows, handles business logic and integration with external services, then sends responses back in a similar secure fashion.

- External Data:
– Show how external services (OrbitDB, IPFS, Constellation, moderation database via HTTP) interact with the Main process to fetch or store data.
– Indicate dependencies on Node.JS and external libraries as described in the installation instructions.

##### Architectural Patterns and Design Principles

- Separation of Concerns:
– Distinct layers are clear: Main, Preload, and Renderer. This separation helps with both security and maintainability.
– Use of Vue Single-File Components (SFCs) in the Renderer for UI logic.

- Secure Bridge:
– Preload scripts are used to isolate the untrusted Renderer code from sensitive operations in the Main process.

- Modular Organization:
– The project is divided into packages (main, preload, renderer) and further into logically separated folders (components, views, plugins, composables) which facilitates scalability and potential microservice-like modularization if the platform grows further.

- Development Pipeline:

##### Final Advice

- Pay special attention to the separation between web (browser) and Electron (desktop) approaches: note that there is an indexBrowser.html for standard web execution and indexElectron.html for desktop deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Layers
    subgraph "Core Layers"
        A["Renderer (Vue-based UI)"]:::core
        B["Preload Bridge"]:::core
        C["Electron Main Process"]:::core
        A -->|"via_secure_API"| B
        B -->|"invokes"| C

        %% Renderer plugins
        A1["Constellation Plugin (Renderer)"]:::core
        A2["Inscription Plugin (Renderer)"]:::core
        A -->|"loads"| A1
        A -->|"loads"| A2

        %% Internal integration in Main process
        C1["Constellation Integration (Electron)"]:::core
        C -->|"includes"| C1
    end

    %% External Services
    subgraph "External Services"
        E1["OrbitDB"]:::external
        E2["IPFS Service"]:::external
        E3["Constellation Service"]:::external
        E4["Moderation Database/API"]:::external
        E2a["IPFS Integration"]:::external

        %% Connections from Core Process to external services
        C -->|"fetch/store"| E1
        C -->|"fetch/store"| E3
        C -->|"fetch/store"| E4
        A -->|"integrates_with"| E2
        A -->|"configures"| E2a
    end

    %% DevOps Pipeline
    subgraph "DevOps Pipeline"
        D1["Electron Builder"]:::devops
        D2["Vite Config (Main)"]:::devops
        D3["Vite Config (Preload)"]:::devops
        D4["Vite Config (Renderer)"]:::devops
        D5["GitHub Actions Workflows"]:::devops
        D6["Test: Main"]:::devops
        D7["Test: Preload"]:::devops
        D8["Test: E2E"]:::devops

        %% CI/CD triggering build and test processes
        D5 --> D1
        D5 --> D2
        D5 --> D3
        D5 --> D4
        D5 --> D6
        D5 --> D7
        D5 --> D8
    end

    %% Connections from DevOps to Core Layers
    D1 -->|"builds"| C
    D2 -->|"builds"| C
    D3 -->|"builds"| B
    D4 -->|"builds"| A

    %% Click Events for Core Components and Plugins
    click C "https://github.com/riffcc/flagship/tree/main/packages/main/src"
    click B "https://github.com/riffcc/flagship/tree/main/packages/preload/src"
    click A "https://github.com/riffcc/flagship/tree/main/packages/renderer"
    click C1 "https://github.com/riffcc/flagship/blob/main/packages/main/src/constellation.ts"
    click A1 "https://github.com/riffcc/flagship/tree/main/packages/renderer/src/plugins/constellation"
    click A2 "https://github.com/riffcc/flagship/tree/main/packages/renderer/src/plugins/inscription"
    click E2a "https://github.com/riffcc/flagship/blob/main/packages/renderer/src/constants/ipfs.ts"

    %% Click Events for DevOps Files
    click D1 "https://github.com/riffcc/flagship/blob/main/electron-builder.config.cjs"
    click D2 "https://github.com/riffcc/flagship/blob/main/packages/main/vite.config.js"
    click D3 "https://github.com/riffcc/flagship/blob/main/packages/preload/vite.config.js"
    click D4 "https://github.com/riffcc/flagship/blob/main/packages/renderer/vite.config.js"
    click D5 "https://github.com/riffcc/flagship/tree/main/.github/workflows"
    click D6 "https://github.com/riffcc/flagship/blob/main/packages/main/tests/unit.spec.ts"
    click D7 "https://github.com/riffcc/flagship/blob/main/packages/preload/tests/unit.spec.ts"
    click D8 "https://github.com/riffcc/flagship/blob/main/tests/e2e.spec.ts"

    %% Styles
    classDef core fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef external fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef devops fill:#fff3cd,stroke:#856404,stroke-width:2px;
```
