# openfactorioservermanager/factorio-server-manager architecture

> Architecture diagram of the GitHub repository openfactorioservermanager/factorio-server-manager, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openfactorioservermanager/factorio-server-manager
- Repository: https://github.com/openfactorioservermanager/factorio-server-manager

## Overview

##### Main Components

A. Frontend Layer:
- React-based UI (located in /ui directory)
- Key views: Console, Controls, Mods, Saves, User Management
- WebSocket client for real-time updates
- REST API client

B. Backend Layer:
- Go-based server (located in /src directory)
- WebSocket hub for real-time communication
- API handlers for different functionalities
- Authentication system

C. Core Functionality Layer:
- Factorio server management
- Save file management
- Mod management
- Configuration management

D. External Integrations:
- Factorio game server
- Factorio mod portal
- File system for saves and mods

**[Frontend Layer]**

- (WebSocket + REST API)
- v
**[Backend Layer] <-----> [External Services]**
- Factorio Game Server
- Factorio Mod Portal
- v
**[File System]**
- Saves
- Mods
- Configs

##### Key Relationships to Highlight

A. Client-Server Communication:
- REST API calls between UI and backend
- WebSocket connections for real-time updates
- Authentication flow

B. Server-Game Integration:
- RCON communication with Factorio server
- Server control mechanisms
- Log management

C. Data Flow:
- Mod management workflow
- Save file handling
- Configuration management

##### Important Architectural Patterns

- MVC-like pattern in the backend
- Component-based architecture in the React frontend
- WebSocket pub/sub system for real-time updates
- Resource-based API structure

##### Technical Details

A. Frontend:
- React components hierarchy
- API client structure
- WebSocket client implementation

B. Backend:
- Go API routes and handlers
- WebSocket hub implementation
- Authentication middleware
- Factorio server management logic

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef backend fill:#2ecc71,stroke:#27ae60,color:white
    classDef external fill:#f1c40f,stroke:#f39c12,color:black
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef auth fill:#e74c3c,stroke:#c0392b,color:white

    %% Frontend Layer
    subgraph Frontend
        UI["React UI"]:::frontend
        Views["Frontend Views"]:::frontend
        APIClient["API Client"]:::frontend
        WSClient["WebSocket Client"]:::frontend
        
        UI --> Views
        UI --> APIClient
        UI --> WSClient
    end
    click UI "https://github.com/OpenFactorioServerManager/factorio-server-manager/tree/develop/ui/App"
    click Views "https://github.com/OpenFactorioServerManager/factorio-server-manager/tree/develop/ui/App/views"
    click APIClient "https://github.com/OpenFactorioServerManager/factorio-server-manager/tree/develop/ui/api"
    click WSClient "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/ui/api/socket.js"

    %% Backend Layer
    subgraph Backend
        APIHandlers["API Handlers"]:::backend
        WSHub["WebSocket Hub"]:::backend
        Auth["Authentication System"]:::auth
        ModMgmt["Mod Management"]:::backend
        SaveMgmt["Save Management"]:::backend
        ServerMgmt["Server Management"]:::backend
        ConfigMgmt["Configuration Management"]:::backend
        ModPortal["Mod Portal Handler"]:::backend
        
        APIHandlers --> Auth
        APIHandlers --> ModMgmt
        APIHandlers --> SaveMgmt
        APIHandlers --> ServerMgmt
        APIHandlers --> ConfigMgmt
        WSHub --> ServerMgmt
    end
    click APIHandlers "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/api/handlers.go"
    click WSHub "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/api/websocket/wshub.go"
    click Auth "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/api/auth.go"
    click ModMgmt "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/factorio/mods.go"
    click SaveMgmt "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/factorio/saves.go"
    click ServerMgmt "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/factorio/server.go"
    click ConfigMgmt "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/factorio/config.go"
    click ModPortal "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/src/api/mod_portal_handler.go"

    %% Frontend Components
    subgraph FrontendViews
        Console["Console View"]:::frontend
        Controls["Controls View"]:::frontend
        ModsView["Mods View"]:::frontend
        SavesView["Saves View"]:::frontend
        Settings["Settings View"]:::frontend
        UserMgmt["User Management"]:::frontend
    end
    click Console "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/ui/App/views/Console.jsx"
    click Controls "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/ui/App/views/Controls.jsx"
    click ModsView "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/ui/App/views/Mods/Mods.jsx"
    click SavesView "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/ui/App/views/Saves/Saves.jsx"
    click Settings "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/ui/App/views/ServerSettings.jsx"
    click UserMgmt "https://github.com/OpenFactorioServerManager/factorio-server-manager/blob/develop/ui/App/views/UserManagement/UserManagment.jsx"

    %% External Systems
    subgraph External
        GameServer["Factorio Game Server"]:::external
        ModPortalExt["Factorio Mod Portal"]:::external
    end

    %% Storage
    subgraph Storage
        FileSystem["File System"]:::storage
        SaveFiles["Save Files"]:::storage
        ModFiles["Mod Files"]:::storage
        Configs["Configuration Files"]:::storage
    end

    %% Connections
    APIClient --> APIHandlers
    WSClient --> WSHub
    ModMgmt --> ModPortalExt
    ServerMgmt --> GameServer
    SaveMgmt --> SaveFiles
    ModMgmt --> ModFiles
    ConfigMgmt --> Configs
    Views --> FrontendViews

    %% Docker
    Docker["Docker Container"]:::external
    Docker --> Backend
    click Docker "https://github.com/OpenFactorioServerManager/factorio-server-manager/tree/develop/docker/Dockerfile"

    %% Legend
    subgraph Legend
        Frontend_L["Frontend"]:::frontend
        Backend_L["Backend"]:::backend
        External_L["External Systems"]:::external
        Storage_L["Storage"]:::storage
        Auth_L["Authentication"]:::auth
    end
```
