# mainsail-crew/mainsail architecture

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

- Interactive diagram: https://gitdiagram.com/mainsail-crew/mainsail
- Repository: https://github.com/mainsail-crew/mainsail

## Overview

##### Main Components

a. Frontend Layer:
- Vue.js Application (Main UI)
- WebSocket Client
- Component Structure
- Store (Vuex) Management
- Router System

b. Communication Layer:
- WebSocket Connection
- API Interfaces
- Remote Printer Support

c. Backend Integration:
- Moonraker API Connection
- Klipper Firmware Interface
- File Management System
- Printer Control Systems

##### Key Architectural Elements

**┌─ Client Layer ─────────────────────────────────────┐**
- Vue.js Frontend                                    │
- ┌─ Components ─┐ ┌─ Store ──┐ ┌─ Services ──┐     │
- Dashboard  │ │ - Printer│ │ - WebSocket │     │
- Console   │ │ - Files  │ │ - File      │     │
- Settings  │ │ - Server │ │ - Updates   │     │
- ┘ └──────────┘ └────────────┘      │
- ┬───────────────────────────┘

**┌───────────────────────▼───────────────────────────┐**
- Communication Layer                               │
- ┌─ WebSocket ─┐ ┌─ REST API ┐ ┌─ File Transfer ┐ │
- Real-time │ │ - Config  │ │ - Upload      │ │
- Events    │ │ - Status  │ │ - Download    │ │
- ┘ └───────────┘ └───────────────┘  │
- ┬───────────────────────────┘

**┌───────────────────────▼───────────────────────────┐**
- Backend Integration                               │
- ┌─ Moonraker ─┐ ┌─ Klipper ──┐ ┌─ Systems ────┐  │
- API       │ │ - Control  │ │ - File Mgmt  │  │
- Events    │ │ - Status   │ │ - Updates    │  │
- ┘ └───────────┘ └─────────────┘   │
- ┘

##### Important Relationships

- Bidirectional communication between frontend and Moonraker via WebSocket
- File management flow
- Printer control commands flow
- State management system
- Component hierarchy

##### Additional Elements

- Version control integration
- Webcam integration points
- Timelapse functionality connection

##### Implementation Details

- Use standard UML notation where appropriate
- Component names from the file structure
- Relationship between stores and components
- Plugin architecture
- Localization system integration

##### Specific Features to Highlight

- Multi-printer support architecture
- Temperature monitoring system
- File management system
- Webcam integration points
- G-code viewer architecture
- Update management system

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        VueApp["Vue.js Application"]
        Components["Component Structure"]
        Store["Store Management"]
        Router["Router System"]
        WSClient["WebSocket Client"]
        
        Dashboard["Dashboard Interface"]
        Console["Console Interface"]
        Settings["Settings Management"]
        GCodeViewer["GCode Viewer"]
        Webcam["Webcam Integration"]
        
        VueApp --> Components
        VueApp --> Store
        VueApp --> Router
        VueApp --> WSClient
        
        Components --> Dashboard
        Components --> Console
        Components --> Settings
        Components --> GCodeViewer
        Components --> Webcam
    end
    
    subgraph Communication
        WebSocket["WebSocket Connection"]
        API["REST API Interface"]
        FileTransfer["File Transfer System"]
        
        WSClient --> WebSocket
        WSClient --> API
        WSClient --> FileTransfer
    end
    
    subgraph Backend
        Moonraker["Moonraker API"]
        Klipper["Klipper Firmware"]
        FileManagement["File Management"]
        PrinterControl["Printer Control"]
        TempMonitor["Temperature Monitoring"]
        UpdateMgmt["Update Management"]
        Timelapse["Timelapse System"]
        Localization["Localization System"]
        
        WebSocket --> Moonraker
        API --> Moonraker
        FileTransfer --> FileManagement
        
        Moonraker --> Klipper
        Moonraker --> PrinterControl
        Moonraker --> TempMonitor
        Moonraker --> UpdateMgmt
        Moonraker --> Timelapse
    end
    
    %% Click events for component mapping
    click VueApp "https://github.com/mainsail-crew/mainsail/blob/develop/src/App.vue"
    click Components "https://github.com/mainsail-crew/mainsail/tree/develop/src/components/"
    click Store "https://github.com/mainsail-crew/mainsail/tree/develop/src/store/"
    click Router "https://github.com/mainsail-crew/mainsail/blob/develop/src/plugins/router.ts"
    click WSClient "https://github.com/mainsail-crew/mainsail/blob/develop/src/plugins/webSocketClient.ts"
    click FileManagement "https://github.com/mainsail-crew/mainsail/tree/develop/src/store/files/"
    click PrinterControl "https://github.com/mainsail-crew/mainsail/tree/develop/src/store/printer/"
    click TempMonitor "https://github.com/mainsail-crew/mainsail/tree/develop/src/store/printer/tempHistory/"
    click Webcam "https://github.com/mainsail-crew/mainsail/tree/develop/src/components/webcams/"
    click Console "https://github.com/mainsail-crew/mainsail/tree/develop/src/components/console/"
    click GCodeViewer "https://github.com/mainsail-crew/mainsail/tree/develop/src/components/gcodeviewer/"
    click Settings "https://github.com/mainsail-crew/mainsail/tree/develop/src/components/settings/"
    click Dashboard "https://github.com/mainsail-crew/mainsail/blob/develop/src/pages/Dashboard.vue"
    click Localization "https://github.com/mainsail-crew/mainsail/tree/develop/src/locales/"
    click UpdateMgmt "https://github.com/mainsail-crew/mainsail/tree/develop/src/store/server/updateManager/"
    click Timelapse "https://github.com/mainsail-crew/mainsail/tree/develop/src/store/server/timelapse/"
    
    %% Styling
    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef communication fill:#4CAF50,stroke:#2E7D32,color:white
    classDef backend fill:#FF9800,stroke:#EF6C00,color:white
    
    class VueApp,Components,Store,Router,WSClient,Dashboard,Console,Settings,GCodeViewer,Webcam frontend
    class WebSocket,API,FileTransfer communication
    class Moonraker,Klipper,FileManagement,PrinterControl,TempMonitor,UpdateMgmt,Timelapse,Localization backend
```
