# thuiop/magium-dev architecture

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

- Interactive diagram: https://gitdiagram.com/thuiop/magium-dev
- Repository: https://github.com/thuiop/magium-dev

## Overview

##### Main Components

a) Application Layer
- Electron Main Process (main_electron.js)
- Node.js Runtime (main_node.js)
- Main Setup Module (src/main_setup.js)

b) Core Game Engine
- Parser System (src/parser.js)
- Story Processing Engine
- Save System Manager (public/scripts/saves.js)

c) Content Management
- Story Data (.magium files)
- Localization System
- Achievement System

d) User Interface
- Template Engine (EJS)
- Static Assets
- Style System

##### Component Relationships

**[Electron Main Process] ─────┐**
- ► [Core Game Engine] ◄────── [Content Management]
**[Node.js Runtime] ──────────┘        │**
- ▼
- [User Interface]

##### Important Elements to Highlight

a) Data Flow:
- Story file loading (.magium files)
- Save state management
- Localization handling (en/fr)
- Achievement tracking

b) File Organization:
- Templates directory structure
- Public assets management
- Data directory organization

##### Specific Implementation Details

- The relationship between .magium files and the parser
- Template rendering flow
- Save state persistence
- Localization switching mechanism

##### The separation between game logic and content

Keep the following aspects in mind:
- Clear boundaries between the Electron wrapper and game engine
- File-based nature of the story content
- Achievement and stats tracking systems
- Save management system's interaction with local storage

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Application Layer
    subgraph AL["Application Layer"]
        EP["Electron Main Process"]
        NR["Node.js Runtime"]
        MS["Main Setup Module"]
    end

    %% Core Game Engine
    subgraph CE["Core Game Engine"]
        PS["Parser System"]
        SSM["Save System Manager"]
        SS["Stats System"]
        UT["Utilities"]
    end

    %% Content Management
    subgraph CM["Content Management"]
        subgraph SD["Story Data"]
            EN["English Content"]
            FR["French Content"]
        end
        subgraph AS["Achievement System"]
            AEN["English Achievements"]
            AFR["French Achievements"]
        end
        LS["Localization System"]
    end

    %% User Interface
    subgraph UI["User Interface"]
        TS["Template System"]
        MT["Main Template"]
        MNT["Menu Template"]
        SS2["Style System"]
        MS2["Main Styles"]
        NM["Night Mode"]
    end

    %% Build System
    subgraph BS["Build System"]
        BSC["Build Scripts"]
        BAS["Build All Script"]
        FC["Forge Config"]
    end

    %% Relationships
    AL --> CE
    CE --> UI
    CM --> CE
    BS --> AL

    %% Component Interactions
    PS --> SSM
    PS --> SS
    LS --> PS
    SD --> PS
    AS --> SS
    TS --> MT
    TS --> MNT
    SS2 --> MS2
    NM --> SS2

    %% Click Events
    click EP "https://github.com/thuiop/magium-dev/blob/main/main_electron.js"
    click NR "https://github.com/thuiop/magium-dev/blob/main/main_node.js"
    click MS "https://github.com/thuiop/magium-dev/blob/main/src/main_setup.js"
    click PS "https://github.com/thuiop/magium-dev/blob/main/src/parser.js"
    click SSM "https://github.com/thuiop/magium-dev/blob/main/public/scripts/saves.js"
    click SS "https://github.com/thuiop/magium-dev/blob/main/public/scripts/stats.js"
    click UT "https://github.com/thuiop/magium-dev/blob/main/public/scripts/utils.js"
    click EN "https://github.com/thuiop/magium-dev/tree/main/data/en"
    click FR "https://github.com/thuiop/magium-dev/tree/main/data/fr"
    click AEN "https://github.com/thuiop/magium-dev/blob/main/data/en/achievements[1-3].json"
    click AFR "https://github.com/thuiop/magium-dev/blob/main/data/fr/achievements[1-3].json"
    click LS "https://github.com/thuiop/magium-dev/blob/main/data/locales.json"
    click TS "https://github.com/thuiop/magium-dev/tree/main/templates"
    click MT "https://github.com/thuiop/magium-dev/blob/main/templates/main.ejs"
    click MNT "https://github.com/thuiop/magium-dev/blob/main/templates/menu.ejs"
    click SS2 "https://github.com/thuiop/magium-dev/tree/main/public/styles"
    click MS2 "https://github.com/thuiop/magium-dev/blob/main/public/styles/main.css"
    click NM "https://github.com/thuiop/magium-dev/blob/main/public/scripts/night_mode.js"
    click BSC "https://github.com/thuiop/magium-dev/tree/main/Build-Scripts"
    click BAS "https://github.com/thuiop/magium-dev/blob/main/build_all.sh"
    click FC "https://github.com/thuiop/magium-dev/blob/main/forge.config.js"

    %% Styling
    classDef application fill:#a8d1f0
    classDef engine fill:#90EE90
    classDef content fill:#FFE5B4
    classDef interface fill:#DDA0DD
    classDef build fill:#D3D3D3

    class EP,NR,MS application
    class PS,SSM,SS,UT engine
    class SD,AS,LS,EN,FR,AEN,AFR content
    class TS,MT,MNT,SS2,MS2,NM interface
    class BSC,BAS,FC build
```
