# anthornet/sc-interactivemap architecture

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

- Interactive diagram: https://gitdiagram.com/anthornet/sc-interactivemap
- Repository: https://github.com/anthornet/sc-interactivemap

## Overview

##### Project type and purpose
- This is a client-side, full-stack-light web application (no separate server code in this repo) that provides an interactive 2D map renderer and save-game editor for the game Satisfactory.
- It loads a Satisfactory “.sav” file (remotely or locally), parses it into in-memory game state, and renders that state in a map UI with full editing capabilities via modals, tooltips, context menus, etc.

##### File structure
- src/SaveParser: Reads and writes the binary .sav file into JavaScript objects.
- src/Models: Contains JSON descriptors for every building, pattern, and vehicle type (static model data).
- src/SubSystem: Implements game-logic subsystems (WorldGrid, GameState, Conveyor networks, Vehicles, Power, etc.).
- src/BaseLayout + src/GameMap + src/SCIM.js: Core rendering engine (built on Leaflet), layout components, entry point.
- src/Modal + src/Selection + src/Spawn: User-interaction layers (dialogs, entity placement, selection, copy/paste).
- webpack.config.js: Bundles all modules, static assets, and JSON models into a single JS/CSS package for the browser.

##### README for additional insights
- Confirms the project is purely front‐end, intended to run on satisfactory-calculator.com.
- Notes remote save loading via CORS-enabled HTTPS from a dedicated Satisfactory server.
- Mentions high‐level features: rendering, full-featured save editor.

##### Main components and their interactions
a. Data Input Layer
- User uploads or points to remote .sav → src/SaveParser/Read.js
- External service: HTTPS file hosting (CORS)
b. Domain Model Layer
- Parsed data feeds into SubSystem modules (GameState, WorldGrid, PowerNetwork, ConveyorChainActor, Vehicle, etc.)
- Static metadata (src/Models) is injected to “build” game objects
c. Rendering & Presentation Layer
- GameMap (Leaflet map instance) draws terrain, grid, building overlays
- BaseLayout components (ContextMenu, Tooltip, Polygon, Math, etc.) handle lower-level SVG/Canvas abstractions
d. UI Interaction Layer
- Modal dialogs (src/Modal) for editing properties, game rules, statistics, schematics
- Selection & Spawn tools alter domain state via SubSystem APIs
- FileSaver.js & pako.esm.js export modified .sav back to the user
e. Build & Deployment
- webpack bundles all JS, CSS, JSON into a minified package
- jsconfig.json configures module resolution

##### Architectural patterns and design principles
- Layered architecture: Input → Domain → Presentation → UI.
- Modular JavaScript: each folder corresponds to a bounded context or feature.
- JSON-driven metadata for easy extensibility (add new Models without code changes).
- Event-driven subsystems: SubSystem/Event dispatches changes to rendering/UI.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser Container
    subgraph "Browser/Client"
        direction TB

        %% Core Entry Point
        SCIM["SCIM.js (Entry Point)"]:::core

        %% Data Input Layer
        subgraph "Data Input Layer"
            direction TB
            Read["SaveParser/Read.js"]:::dataInput
            Write["SaveParser/Write.js"]:::dataInput
            FicsIt["SaveParser/FicsIt.js"]:::dataInput
        end

        %% Domain Model Layer
        subgraph "Domain Model Layer"
            direction TB
            SubSys["SubSystem Modules"]:::domain
            Models[(JSON Models)]:::storage
        end

        %% Rendering & Presentation Layer
        subgraph "Rendering Engine"
            direction TB
            GameMap["GameMap.js"]:::rendering
            BaseLayout["BaseLayout.js"]:::rendering
            subgraph "BaseLayout Components"
                direction TB
                ContextMenu["ContextMenu.js"]:::rendering
                Tooltip["Tooltip.js"]:::rendering
                PolygonBL["Polygon.js"]:::rendering
                MathBL["Math.js"]:::rendering
                History["History.js"]:::rendering
                ModalBL["Modal.js"]:::rendering
            end
        end

        %% UI Interaction Layer
        subgraph "UI Interaction Layer"
            direction TB
            UI_Modal["Modal/ (Buildings, Selection, Map, Power, Vehicle)"]:::ui
            Selection["Selection/ (Copy, Delete, MoveTo, Offset, Rotate)"]:::ui
            Spawn["Spawn/ (Circle, Fauna, Fill, Image, Megaprint, Node, Polygon, Rectangle, Road, Tower)"]:::ui
            FileSaver["Lib/FileSaver.js"]:::ui
            Pako["Lib/pako.esm.js"]:::ui
        end

        %% Intra-browser Connections
        SCIM -->|"init();"| Read
        SCIM -->|"init();"| GameMap
        Read -->|"parseSave()"| SubSys
        FicsIt --> SubSys
        SubSys -->|"buildObjects()"| Models
        SubSys -->|"dispatchEvent()"| GameMap
        Models --> GameMap
        GameMap -->|"addLayer() / render()"| BaseLayout
        BaseLayout --> ContextMenu
        BaseLayout --> Tooltip
        BaseLayout --> PolygonBL
        BaseLayout --> MathBL
        BaseLayout --> History
        BaseLayout --> ModalBL
        BaseLayout --> UI_Modal
        UI_Modal --> SubSys
        Selection --> SubSys
        Spawn --> SubSys
        UI_Modal -.->|"export()"| Write
        Write --> FileSaver
        Write --> Pako
        FileSaver -->|"saveAs()"| User
        Pako --> Write

    end

    %% External Services
    subgraph "External Services"
        direction TB
        User["User Interaction"]:::external
        Remote["HTTPS Save Server (CORS)"]:::external
        CDN["CDN (JSON Assets)"]:::external
    end

    %% External Connections
    User -->|"upload/pointTo()"| Read
    Remote --> Read
    CDN --> Models

    %% Build & Deployment
    subgraph "Build & Deployment"
        direction TB
        Webpack["webpack.config.js"]:::build
        JSConfig["jsconfig.json"]:::build
        Package["package.json"]:::build
    end
    Webpack --> SCIM
    JSConfig --> SCIM
    Package --> SCIM

    %% Click Events
    click Read "https://github.com/anthornet/sc-interactivemap/blob/dev/src/SaveParser/Read.js"
    click Write "https://github.com/anthornet/sc-interactivemap/blob/dev/src/SaveParser/Write.js"
    click FicsIt "https://github.com/anthornet/sc-interactivemap/blob/dev/src/SaveParser/FicsIt.js"
    click SubSys "https://github.com/anthornet/sc-interactivemap/tree/dev/src/SubSystem/"
    click Models "https://github.com/anthornet/sc-interactivemap/tree/dev/src/Models/"
    click GameMap "https://github.com/anthornet/sc-interactivemap/blob/dev/src/GameMap.js"
    click BaseLayout "https://github.com/anthornet/sc-interactivemap/blob/dev/src/BaseLayout.js"
    click ContextMenu "https://github.com/anthornet/sc-interactivemap/blob/dev/src/BaseLayout/ContextMenu.js"
    click Tooltip "https://github.com/anthornet/sc-interactivemap/blob/dev/src/BaseLayout/Tooltip.js"
    click PolygonBL "https://github.com/anthornet/sc-interactivemap/blob/dev/src/BaseLayout/Polygon.js"
    click MathBL "https://github.com/anthornet/sc-interactivemap/blob/dev/src/BaseLayout/Math.js"
    click History "https://github.com/anthornet/sc-interactivemap/blob/dev/src/BaseLayout/History.js"
    click ModalBL "https://github.com/anthornet/sc-interactivemap/blob/dev/src/BaseLayout/Modal.js"
    click UI_Modal "https://github.com/anthornet/sc-interactivemap/tree/dev/src/Modal/"
    click Selection "https://github.com/anthornet/sc-interactivemap/tree/dev/src/Selection/"
    click Spawn "https://github.com/anthornet/sc-interactivemap/tree/dev/src/Spawn/"
    click FileSaver "https://github.com/anthornet/sc-interactivemap/blob/dev/src/Lib/FileSaver.js"
    click Pako "https://github.com/anthornet/sc-interactivemap/blob/dev/src/Lib/pako.esm.js"
    click SCIM "https://github.com/anthornet/sc-interactivemap/blob/dev/src/SCIM.js"
    click Webpack "https://github.com/anthornet/sc-interactivemap/blob/dev/webpack.config.js"
    click JSConfig "https://github.com/anthornet/sc-interactivemap/blob/dev/jsconfig.json"
    click Package "https://github.com/anthornet/sc-interactivemap/blob/dev/package.json"

    %% Styles
    classDef dataInput fill:#D0E8FF,stroke:#3399FF,color:#000;
    classDef domain fill:#E0FFD0,stroke:#33CC33,color:#000;
    classDef rendering fill:#FFE0B2,stroke:#FF9900,color:#000;
    classDef ui fill:#E3D1FF,stroke:#9933FF,color:#000;
    classDef storage fill:#FFFFFF,stroke:#33CC33,color:#000,stroke-dasharray: 5 5;
    classDef external fill:#F0F8FF,stroke:#6699CC,color:#000,stroke-dasharray: 2 2;
    classDef build fill:#F2F2F2,stroke:#999999,color:#000;
    classDef core fill:#FFFFCC,stroke:#CCCC00,color:#000;
```
