# oashalal/lg-native architecture

> Architecture diagram of the GitHub repository oashalal/lg-native, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oashalal/lg-native
- Repository: https://github.com/oashalal/lg-native

## Overview

lg-native is a Linux Electron client for the live Legion game site, with local interface patches while the site remains authoritative for API and authentication. The main workflow loads a channel in an account-specific browser session, mediates site requests and versioned asset caching, then applies compatible patches and exposes their LGX runtime to the page. Separate branches cover multi-account lifecycle, native window features, and patch network permissions. The source index and excerpts establish the main wiring; less-sampled native and preload details are represented at directory level, with undocumented links omitted.

Main entry points: [`src/main/app.ts`](https://github.com/oashalal/lg-native/blob/master/src/main/app.ts) (Electron app), [`src/main/patching/engine.ts`](https://github.com/oashalal/lg-native/blob/master/src/main/patching/engine.ts) (Patch engine), [`src/runtime/lgx.ts`](https://github.com/oashalal/lg-native/blob/master/src/runtime/lgx.ts) (LGX page API), [`src/main/ipc/page-bridge.ts`](https://github.com/oashalal/lg-native/blob/master/src/main/ipc/page-bridge.ts) (Page bridge)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_shell["Electron shell"]
  node_app["Electron app<br/>[app.ts]"]
  node_ipc["IPC channels<br/>[channels.ts]"]
  node_bridge["Page bridge<br/>[page-bridge.ts]"]
  node_preload["Preload bridges"]
end

subgraph group_network["Site networking"]
  node_origin["Origin handling<br/>[origin.ts]"]
  node_policy["Patch network policy<br/>[network-policy.ts]"]
  node_cache[("Asset cache<br/>[cache.ts]")]
end

subgraph group_patching["Patch platform"]
  node_manifest["Patch manifest schema<br/>[manifest.ts]"]
  node_engine["Patch engine<br/>[engine.ts]"]
  node_compat["Compatibility checks<br/>[compat.ts]"]
  node_settings["Patch settings<br/>[settings.ts]"]
  node_reports[("Patch reports<br/>[report-log.ts]")]
  node_patches["Local patches"]
end

subgraph group_runtime["Page runtime"]
  node_lgx["LGX page API<br/>[lgx.ts]"]
  node_ui["Patch UI helpers<br/>[ui.ts]"]
  node_channel["World channel<br/>[channel.ts]"]
  node_runtime_net["Runtime fetch<br/>[net.ts]"]
end

subgraph group_native["Accounts and native"]
  node_accounts[("Account registry<br/>[index.ts]")]
  node_native["Native features"]
end

node_player(("Player"))
node_site["Legion site"]

node_player -->|"opens client"| node_app
node_app -->|"loads channel"| node_site
node_app -->|"reads and writes"| node_cache
node_app -->|"restores origin"| node_origin
node_app -->|"applies patches"| node_engine
node_app -->|"checks versions"| node_compat
node_app -->|"loads overrides"| node_settings
node_app -->|"records outcomes"| node_reports
node_app -->|"manages profiles"| node_accounts
node_engine -->|"uses schema"| node_manifest
node_engine -->|"checks compatibility"| node_compat
node_engine -.->|"executes patch code"| node_patches
node_engine -->|"injects runtime"| node_lgx
node_lgx -->|"creates helpers"| node_ui
node_app -->|"registers handlers"| node_ipc
node_app -->|"uses bridge gates"| node_bridge
node_app -.->|"configures preload"| node_preload
node_preload -.->|"exposes page API"| node_bridge
node_lgx -.->|"requests reports"| node_bridge
node_runtime_net -.->|"validates fetches"| node_policy
node_player -.->|"selects profile"| node_accounts
node_app -.->|"creates native UI"| node_native
node_app -->|"intercepts requests"| node_site

click node_app "https://github.com/oashalal/lg-native/blob/master/src/main/app.ts"
click node_ipc "https://github.com/oashalal/lg-native/blob/master/src/main/ipc/channels.ts"
click node_bridge "https://github.com/oashalal/lg-native/blob/master/src/main/ipc/page-bridge.ts"
click node_preload "https://github.com/oashalal/lg-native/tree/master/src/preload"
click node_origin "https://github.com/oashalal/lg-native/blob/master/src/main/net/origin.ts"
click node_policy "https://github.com/oashalal/lg-native/blob/master/src/main/net/network-policy.ts"
click node_cache "https://github.com/oashalal/lg-native/blob/master/src/main/net/cache.ts"
click node_manifest "https://github.com/oashalal/lg-native/blob/master/src/shared/manifest.ts"
click node_engine "https://github.com/oashalal/lg-native/blob/master/src/main/patching/engine.ts"
click node_compat "https://github.com/oashalal/lg-native/blob/master/src/main/patching/compat.ts"
click node_settings "https://github.com/oashalal/lg-native/blob/master/src/main/patching/settings.ts"
click node_reports "https://github.com/oashalal/lg-native/blob/master/src/main/patching/report-log.ts"
click node_patches "https://github.com/oashalal/lg-native/tree/master/patches"
click node_lgx "https://github.com/oashalal/lg-native/blob/master/src/runtime/lgx.ts"
click node_ui "https://github.com/oashalal/lg-native/blob/master/src/runtime/ui.ts"
click node_channel "https://github.com/oashalal/lg-native/blob/master/src/runtime/channel.ts"
click node_runtime_net "https://github.com/oashalal/lg-native/blob/master/src/runtime/net.ts"
click node_accounts "https://github.com/oashalal/lg-native/blob/master/src/main/accounts/index.ts"
click node_native "https://github.com/oashalal/lg-native/tree/master/src/main/native"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_ipc,node_bridge,node_preload toneBlue
class node_origin,node_policy,node_cache toneAmber
class node_manifest,node_engine,node_compat,node_settings,node_reports,node_patches toneMint
class node_lgx,node_ui,node_channel,node_runtime_net toneRose
class node_accounts,node_native,node_player,node_site toneIndigo
```

## Components

### Electron shell

- [Electron app](https://github.com/oashalal/lg-native/blob/master/src/main/app.ts): `src/main/app.ts`
- [IPC channels](https://github.com/oashalal/lg-native/blob/master/src/main/ipc/channels.ts): `src/main/ipc/channels.ts`
- [Page bridge](https://github.com/oashalal/lg-native/blob/master/src/main/ipc/page-bridge.ts): `src/main/ipc/page-bridge.ts`
- [Preload bridges](https://github.com/oashalal/lg-native/tree/master/src/preload): `src/preload`

### Site networking

- [Origin handling](https://github.com/oashalal/lg-native/blob/master/src/main/net/origin.ts): `src/main/net/origin.ts`
- [Patch network policy](https://github.com/oashalal/lg-native/blob/master/src/main/net/network-policy.ts): `src/main/net/network-policy.ts`
- [Asset cache](https://github.com/oashalal/lg-native/blob/master/src/main/net/cache.ts): `src/main/net/cache.ts`

### Patch platform

- [Patch manifest schema](https://github.com/oashalal/lg-native/blob/master/src/shared/manifest.ts): `src/shared/manifest.ts`
- [Patch engine](https://github.com/oashalal/lg-native/blob/master/src/main/patching/engine.ts): `src/main/patching/engine.ts`
- [Compatibility checks](https://github.com/oashalal/lg-native/blob/master/src/main/patching/compat.ts): `src/main/patching/compat.ts`
- [Patch settings](https://github.com/oashalal/lg-native/blob/master/src/main/patching/settings.ts): `src/main/patching/settings.ts`
- [Patch reports](https://github.com/oashalal/lg-native/blob/master/src/main/patching/report-log.ts): `src/main/patching/report-log.ts`
- [Local patches](https://github.com/oashalal/lg-native/tree/master/patches): `patches`

### Page runtime

- [LGX page API](https://github.com/oashalal/lg-native/blob/master/src/runtime/lgx.ts): `src/runtime/lgx.ts`
- [Patch UI helpers](https://github.com/oashalal/lg-native/blob/master/src/runtime/ui.ts): `src/runtime/ui.ts`
- [World channel](https://github.com/oashalal/lg-native/blob/master/src/runtime/channel.ts): `src/runtime/channel.ts`
- [Runtime fetch](https://github.com/oashalal/lg-native/blob/master/src/runtime/net.ts): `src/runtime/net.ts`

### Accounts and native

- [Account registry](https://github.com/oashalal/lg-native/blob/master/src/main/accounts/index.ts): `src/main/accounts/index.ts`
- [Native features](https://github.com/oashalal/lg-native/tree/master/src/main/native): `src/main/native`

### Other components

- **Player**
- **Legion site**

## Connections

- Player → Electron app: opens client (evidence: `README.md`)
- Electron app → Legion site: loads channel (evidence: `README.md`)
- Electron app → Asset cache: reads and writes (evidence: `src/main/app.ts`)
- Electron app → Origin handling: restores origin (evidence: `src/main/app.ts`)
- Electron app → Patch engine: applies patches (evidence: `src/main/app.ts`)
- Electron app → Compatibility checks: checks versions (evidence: `src/main/app.ts`)
- Electron app → Patch settings: loads overrides (evidence: `src/main/app.ts`)
- Electron app → Patch reports: records outcomes (evidence: `src/main/app.ts`)
- Electron app → Account registry: manages profiles (evidence: `src/main/app.ts`)
- Patch engine → Patch manifest schema: uses schema (evidence: `src/main/patching/engine.ts`)
- Patch engine → Compatibility checks: checks compatibility (evidence: `src/main/patching/engine.ts`)
- Patch engine → Local patches: executes patch code
- Patch engine → LGX page API: injects runtime (evidence: `src/main/patching/engine.ts`)
- LGX page API → Patch UI helpers: creates helpers (evidence: `src/runtime/lgx.ts`)
- Electron app → IPC channels: registers handlers (evidence: `src/main/app.ts`)
- Electron app → Page bridge: uses bridge gates (evidence: `src/main/app.ts`)
- Electron app → Preload bridges: configures preload
- Preload bridges → Page bridge: exposes page API
- LGX page API → Page bridge: requests reports
- Runtime fetch → Patch network policy: validates fetches
- Player → Account registry: selects profile
- Electron app → Native features: creates native UI
- Electron app → Legion site: intercepts requests (evidence: `src/main/app.ts`)
