# gusxo999/flg architecture

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

- Interactive diagram: https://gitdiagram.com/gusxo999/flg
- Repository: https://github.com/gusxo999/flg

## Overview

This is a Factorio factory-layout editor and automatic layout planner. The main workflow is editing a grid, selecting a recipe and machine inputs, running auto-layout, then inspecting or exporting the resulting blueprint. The README describes the planner as recipe-tree expansion followed by module placement, with separate stages for module links, inter-module channels, and perimeter exports. Other documented capabilities include custom recipes, Factorio data handling, belt/fluid analysis, and blueprint import/export. Some planner and UI implementations were not sampled; those links are included only where the README or source index supports them.

Main entry points: [`src/UI/store/layoutStore.ts`](https://github.com/gusxo999/flg/blob/main/src/UI/store/layoutStore.ts) (Layout state), [`src/App.tsx`](https://github.com/gusxo999/flg/blob/main/src/App.tsx) (Editor shell), [`src/autoLayout/module/shape/body.ts`](https://github.com/gusxo999/flg/blob/main/src/autoLayout/module/shape/body.ts) (Module planning), [`src/autoLayout/module/emit.ts`](https://github.com/gusxo999/flg/blob/main/src/autoLayout/module/emit.ts) (Layout emission)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Editor UI"]
  node_app["Editor shell<br/>[App.tsx]"]
  node_canvas["Grid canvas<br/>[GridCanvas.tsx]"]
  node_toolbar["Toolbar<br/>[Toolbar.tsx]"]
  node_auto_modal["Auto-layout panel"]
  node_layout_store[("Layout state<br/>[layoutStore.ts]")]
  node_run_store[("Run state")]
  node_pixi["Canvas renderer<br/>[pixi-manager.ts]"]
  node_layout_model["Layout model<br/>[layout.ts]"]
end

subgraph group_data["Game Data"]
  node_game_store[("Game data state<br/>[gameDataStore.ts]")]
  node_game_parser["Game data parser<br/>[parseGameData.ts]"]
  node_custom_recipe["Custom recipes<br/>[customRecipe.ts]"]
end

subgraph group_planner["Auto Layout"]
  node_recipe_tree["Recipe tree<br/>[build.ts]"]
  node_module_plan["Module planning<br/>[body.ts]"]
  node_module_types["Module model<br/>[module.ts]"]
  node_module_links["Module links<br/>[build.ts]"]
  node_channels["Channel reservation<br/>[shape.ts]"]
  node_perimeter["Perimeter export<br/>[late.ts]"]
  node_emit["Layout emission<br/>[emit.ts]"]
  node_shared_grid["Grid geometry<br/>[grid.ts]"]
end

subgraph group_analysis["Analysis"]
  node_belt_analysis["Belt flow<br/>[beltFlow.ts]"]
  node_pipe_analysis["Pipe network<br/>[pipeNetwork.ts]"]
end

subgraph group_interop["Blueprint I/O &amp; Debug"]
  node_blueprint_codec["Blueprint codec<br/>[blueprintCodec.ts]"]
  node_blueprint_items["Blueprint items"]
  node_debug_api["Debug API<br/>[debugApi.ts]"]
  node_blueprint_format["Blueprint model<br/>[blueprint.ts]"]
end

node_user(("Factory designer"))

node_user -->|"uses editor"| node_app
node_app -->|"renders"| node_toolbar
node_app -->|"renders"| node_canvas
node_app -->|"renders"| node_auto_modal
node_canvas -.->|"edits state"| node_layout_store
node_layout_store -->|"stores grid"| node_layout_model
node_pixi -->|"subscribes"| node_layout_store
node_pixi -->|"subscribes"| node_game_store
node_toolbar -.->|"imports data"| node_game_parser
node_game_parser -.->|"loads data"| node_game_store
node_custom_recipe -->|"merges recipes"| node_game_store
node_auto_modal -.->|"starts layout"| node_run_store
node_run_store -.->|"runs planner"| node_recipe_tree
node_recipe_tree -.->|"builds modules"| node_module_plan
node_module_plan -.->|"plans links"| node_module_links
node_module_plan -->|"creates model"| node_module_types
node_module_links -.->|"reserves channels"| node_channels
node_channels -.->|"reserves exits"| node_perimeter
node_module_plan -->|"emits layout"| node_emit
node_emit -->|"uses geometry"| node_shared_grid
node_emit -.->|"writes grid"| node_layout_store
node_layout_store -.->|"analyzes flow"| node_belt_analysis
node_layout_store -.->|"analyzes network"| node_pipe_analysis
node_layout_store -.->|"exports layout"| node_blueprint_codec
node_blueprint_codec -->|"encodes"| node_blueprint_format
node_blueprint_items -->|"encodes items"| node_blueprint_format
node_user -->|"runs diagnostics"| node_debug_api

click node_app "https://github.com/gusxo999/flg/blob/main/src/App.tsx"
click node_canvas "https://github.com/gusxo999/flg/blob/main/src/UI/components/GridCanvas.tsx"
click node_toolbar "https://github.com/gusxo999/flg/blob/main/src/UI/components/Toolbar.tsx"
click node_auto_modal "https://github.com/gusxo999/flg/blob/main/src/UI/components/AutoLayoutModal.tsx"
click node_layout_store "https://github.com/gusxo999/flg/blob/main/src/UI/store/layoutStore.ts"
click node_run_store "https://github.com/gusxo999/flg/blob/main/src/UI/store/autoLayoutRunStore.ts"
click node_pixi "https://github.com/gusxo999/flg/blob/main/src/UI/pixi/pixi-manager.ts"
click node_game_store "https://github.com/gusxo999/flg/blob/main/src/UI/store/gameDataStore.ts"
click node_game_parser "https://github.com/gusxo999/flg/blob/main/src/factorio/parseGameData.ts"
click node_custom_recipe "https://github.com/gusxo999/flg/blob/main/src/factorio/customRecipe.ts"
click node_recipe_tree "https://github.com/gusxo999/flg/blob/main/src/autoLayout/tree/build.ts"
click node_module_plan "https://github.com/gusxo999/flg/blob/main/src/autoLayout/module/shape/body.ts"
click node_module_types "https://github.com/gusxo999/flg/blob/main/src/autoLayout/module/types/module.ts"
click node_module_links "https://github.com/gusxo999/flg/blob/main/src/autoLayout/link/build.ts"
click node_channels "https://github.com/gusxo999/flg/blob/main/src/autoLayout/channel/shape.ts"
click node_perimeter "https://github.com/gusxo999/flg/blob/main/src/autoLayout/perimeter/late.ts"
click node_emit "https://github.com/gusxo999/flg/blob/main/src/autoLayout/module/emit.ts"
click node_shared_grid "https://github.com/gusxo999/flg/blob/main/src/autoLayout/shared/grid.ts"
click node_belt_analysis "https://github.com/gusxo999/flg/blob/main/src/analysis/beltFlow.ts"
click node_pipe_analysis "https://github.com/gusxo999/flg/blob/main/src/analysis/pipeNetwork.ts"
click node_blueprint_codec "https://github.com/gusxo999/flg/blob/main/src/blueprint/blueprintCodec.ts"
click node_blueprint_items "https://github.com/gusxo999/flg/blob/main/src/blueprint/blueprintItemsCodec.ts"
click node_debug_api "https://github.com/gusxo999/flg/blob/main/src/debug/debugApi.ts"
click node_blueprint_format "https://github.com/gusxo999/flg/blob/main/src/types/blueprint.ts"
click node_layout_model "https://github.com/gusxo999/flg/blob/main/src/types/layout.ts"

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_canvas,node_toolbar,node_auto_modal,node_layout_store,node_run_store,node_pixi,node_layout_model toneBlue
class node_game_store,node_game_parser,node_custom_recipe toneAmber
class node_recipe_tree,node_module_plan,node_module_types,node_module_links,node_channels,node_perimeter,node_emit,node_shared_grid toneMint
class node_belt_analysis,node_pipe_analysis toneRose
class node_blueprint_codec,node_blueprint_items,node_debug_api,node_blueprint_format,node_user toneIndigo
```

## Components

### Editor UI

- [Editor shell](https://github.com/gusxo999/flg/blob/main/src/App.tsx): `src/App.tsx`
- [Grid canvas](https://github.com/gusxo999/flg/blob/main/src/UI/components/GridCanvas.tsx): `src/UI/components/GridCanvas.tsx`
- [Toolbar](https://github.com/gusxo999/flg/blob/main/src/UI/components/Toolbar.tsx): `src/UI/components/Toolbar.tsx`
- [Auto-layout panel](https://github.com/gusxo999/flg/blob/main/src/UI/components/AutoLayoutModal.tsx): `src/UI/components/AutoLayoutModal.tsx`
- [Layout state](https://github.com/gusxo999/flg/blob/main/src/UI/store/layoutStore.ts): `src/UI/store/layoutStore.ts`
- [Run state](https://github.com/gusxo999/flg/blob/main/src/UI/store/autoLayoutRunStore.ts): `src/UI/store/autoLayoutRunStore.ts`
- [Canvas renderer](https://github.com/gusxo999/flg/blob/main/src/UI/pixi/pixi-manager.ts): `src/UI/pixi/pixi-manager.ts`
- [Layout model](https://github.com/gusxo999/flg/blob/main/src/types/layout.ts): `src/types/layout.ts`

### Game Data

- [Game data state](https://github.com/gusxo999/flg/blob/main/src/UI/store/gameDataStore.ts): `src/UI/store/gameDataStore.ts`
- [Game data parser](https://github.com/gusxo999/flg/blob/main/src/factorio/parseGameData.ts): `src/factorio/parseGameData.ts`
- [Custom recipes](https://github.com/gusxo999/flg/blob/main/src/factorio/customRecipe.ts): `src/factorio/customRecipe.ts`

### Auto Layout

- [Recipe tree](https://github.com/gusxo999/flg/blob/main/src/autoLayout/tree/build.ts): `src/autoLayout/tree/build.ts`
- [Module planning](https://github.com/gusxo999/flg/blob/main/src/autoLayout/module/shape/body.ts): `src/autoLayout/module/shape/body.ts`
- [Module model](https://github.com/gusxo999/flg/blob/main/src/autoLayout/module/types/module.ts): `src/autoLayout/module/types/module.ts`
- [Module links](https://github.com/gusxo999/flg/blob/main/src/autoLayout/link/build.ts): `src/autoLayout/link/build.ts`
- [Channel reservation](https://github.com/gusxo999/flg/blob/main/src/autoLayout/channel/shape.ts): `src/autoLayout/channel/shape.ts`
- [Perimeter export](https://github.com/gusxo999/flg/blob/main/src/autoLayout/perimeter/late.ts): `src/autoLayout/perimeter/late.ts`
- [Layout emission](https://github.com/gusxo999/flg/blob/main/src/autoLayout/module/emit.ts): `src/autoLayout/module/emit.ts`
- [Grid geometry](https://github.com/gusxo999/flg/blob/main/src/autoLayout/shared/grid.ts): `src/autoLayout/shared/grid.ts`

### Analysis

- [Belt flow](https://github.com/gusxo999/flg/blob/main/src/analysis/beltFlow.ts): `src/analysis/beltFlow.ts`
- [Pipe network](https://github.com/gusxo999/flg/blob/main/src/analysis/pipeNetwork.ts): `src/analysis/pipeNetwork.ts`

### Blueprint I/O & Debug

- [Blueprint codec](https://github.com/gusxo999/flg/blob/main/src/blueprint/blueprintCodec.ts): `src/blueprint/blueprintCodec.ts`
- [Blueprint items](https://github.com/gusxo999/flg/blob/main/src/blueprint/blueprintItemsCodec.ts): `src/blueprint/blueprintItemsCodec.ts`
- [Debug API](https://github.com/gusxo999/flg/blob/main/src/debug/debugApi.ts): `src/debug/debugApi.ts`
- [Blueprint model](https://github.com/gusxo999/flg/blob/main/src/types/blueprint.ts): `src/types/blueprint.ts`

### Other components

- **Factory designer**

## Connections

- Factory designer → Editor shell: uses editor (evidence: `src/App.tsx`)
- Editor shell → Toolbar: renders (evidence: `src/App.tsx`)
- Editor shell → Grid canvas: renders (evidence: `src/App.tsx`)
- Editor shell → Auto-layout panel: renders (evidence: `src/App.tsx`)
- Grid canvas → Layout state: edits state
- Layout state → Layout model: stores grid (evidence: `src/UI/store/layoutStore.ts`)
- Canvas renderer → Layout state: subscribes (evidence: `src/UI/pixi/pixi-manager.ts`)
- Canvas renderer → Game data state: subscribes (evidence: `src/UI/pixi/pixi-manager.ts`)
- Toolbar → Game data parser: imports data
- Game data parser → Game data state: loads data
- Custom recipes → Game data state: merges recipes (evidence: `src/factorio/customRecipe.ts`)
- Auto-layout panel → Run state: starts layout
- Run state → Recipe tree: runs planner
- Recipe tree → Module planning: builds modules
- Module planning → Module links: plans links
- Module planning → Module model: creates model (evidence: `src/autoLayout/module/shape/body.ts`)
- Module links → Channel reservation: reserves channels
- Channel reservation → Perimeter export: reserves exits
- Module planning → Layout emission: emits layout (evidence: `src/autoLayout/module/emit.ts`)
- Layout emission → Grid geometry: uses geometry (evidence: `src/autoLayout/module/emit.ts`)
- Layout emission → Layout state: writes grid
- Layout state → Belt flow: analyzes flow
- Layout state → Pipe network: analyzes network
- Layout state → Blueprint codec: exports layout
- Blueprint codec → Blueprint model: encodes (evidence: `src/blueprint/blueprintCodec.ts`)
- Blueprint items → Blueprint model: encodes items (evidence: `src/blueprint/blueprintItemsCodec.ts`)
- Factory designer → Debug API: runs diagnostics (evidence: `src/debug/debugApi.ts`)
