# supch/prunplanner-zh architecture

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

- Interactive diagram: https://gitdiagram.com/supch/prunplanner-zh
- Repository: https://github.com/supch/prunplanner-zh

## Overview

#### Purpose and runtime
PRUNplanner 中文版 is a localized Vue single-page planner for the Prosperous Universe game. It provides plan creation, production/economy analysis, market/exchange tools, FIO operations, account-backed data, and shareable plans. The browser app is bootstrapped at `src/main.ts`, composed by `src/App.vue` and `src/AppProvider.vue`, and served through Vite or a Docker static deployment (`Dockerfile`, `docker-compose.yaml`). Production is deployed to Cloudflare Pages; `netlify.toml` and `public/_redirects` support SPA deep-link routing.

#### Application shell, navigation, and localization
Routing maps feature views to the SPA at `src/router/index.ts`; primary screens live in `src/views/`, notably `src/views/PlanView.vue`, `src/views/EmpireView.vue`, and `src/views/tools/ProductionChainView.vue`. Shared navigation, progress states, and version notifications are in `src/layout/components/NavigationBar.vue`, `src/layout/components/ComputingProgress.vue`, and `src/layout/components/VersionUpdateNotification.vue`. Internationalization is backed by `src/locales/index.ts`, `src/locales/en.json`, and `src/locales/zh.json`; translated Markdown help is held under `src/assets/help/`.

#### Remote API and validation boundary
Feature-specific API clients isolate calls to the configured PRUNplanner backend: `src/features/api/gameData.api.ts`, `src/features/api/planData.api.ts`, `src/features/api/empireData.api.ts`, plus account, optimization, CX, and sharing clients. Transport/configuration is centralized in `src/lib/apiService.ts` and `src/lib/config.ts`, using `VITE_API_BASE_URL`; schemas in `src/features/api/schemas/` validate API payloads at the client boundary. Share links use the independently configurable `VITE_SHARE_BASE_URL`.

#### Data loading, caching, and persistence
Route/feature wrappers orchestrate game and planning-data acquisition before rendering: `src/features/wrapper/useGameDataLoader.ts`, `src/features/wrapper/usePlanningDataLoader.ts`, and their loader components. Query caching is a distinct repository/store layer in `src/lib/query_cache/queryRepository.ts`, `src/lib/query_cache/queryStore.ts`, and `src/lib/query_cache/useQuery.ts`. Browser-local structured data is abstracted behind IndexedDB in `src/database/composables/useDB.ts`, `src/database/composables/useIndexedDBStore.ts`, and `src/database/schema.ts`; domain services expose building, material, planet, and exchange datasets.

#### Planning engine and state
Planning is the core computation pipeline. Plan persistence/loading is represented by `src/features/planning_data/usePlan.ts`; application state is held in `src/stores/planningStore.ts`. `src/features/planning/usePlanCalculation.ts` coordinates precomputation and handlers, feeding specialized deterministic calculations for buildings, extraction, bonuses, habitation optimization, and workforce under `src/features/planning/calculations/`. Results drive the plan workspace (`src/features/planning/components/PlanArea.vue`, `PlanProduction.vue`, `PlanMaterialIO.vue`) and downstream tools such as construction/supply carts, COGM, POPR, and repair analysis.

#### Domain analysis and graph stages
Empire and plan outputs feed economic analysis: `src/features/empire/components/EmpireAnalysis.vue` and `src/features/empire/components/EmpireMaterialIO.vue` aggregate plan-level behavior. ROI, resource ROI, market exploration, planet search, and CX pricing are separated feature modules, e.g. `src/features/roi_overview/useROIOverview.ts`, `src/features/market_exploration/useMarketExploration.ts`, and `src/features/cx/useCXData.ts`. Production-chain visualization transforms production relationships into nodes and edges in `src/features/production_chain/productionGraph.ts`, `productionNode.ts`, and `productionEdge.ts`; `src/features/production_chain/useGraph.ts` applies graph state/layout, rendered through `GraphVueFlow.vue` with Dagre configuration.

#### Identity, user operations, and external game actions
User/session state is separated in `src/stores/userStore.ts`, with login/registration/reset UI under `src/features/account/components/` and account API access in `src/features/api/userData.api.ts`. Preferences and endpoint/API-key management are modularized in `src/features/preferences/usePreferences.ts` and `src/features/endpoints/useEndpoints.ts`. FIO and XIT actions form explicit external-operation boundaries through `src/features/fio/useFIORepair.ts`, `src/features/xit/useXITAction.ts`, and their action components. Analytics is isolated behind `src/lib/analytics/useAnalytics.ts` and `src/lib/analytics/usePostHog.ts`.

Main entry points: [`src/AppProvider.vue`](https://github.com/supch/prunplanner-zh/blob/main/src/AppProvider.vue) (App Provider & Shell), [`src/features/wrapper/usePlanningDataLoader.ts`](https://github.com/supch/prunplanner-zh/blob/main/src/features/wrapper/usePlanningDataLoader.ts) (Game & Planning Loaders), [`src/views/PlanView.vue`](https://github.com/supch/prunplanner-zh/blob/main/src/views/PlanView.vue) (Planner & Empire Views), [`src/stores/planningStore.ts`](https://github.com/supch/prunplanner-zh/blob/main/src/stores/planningStore.ts) (Plan State & Persistence)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["SPA Shell"]
  node_bootstrap{{"Vue Bootstrap<br/>runtime entry<br/>[main.ts]"}}
  node_shell["App Provider &amp; Shell<br/>application shell<br/>[AppProvider.vue]"]
  node_router["Feature Router<br/>routing<br/>[index.ts]"]
  node_views["Planner &amp; Empire Views<br/>feature views<br/>[PlanView.vue]"]
  node_navigation["Navigation &amp; Status<br/>layout components<br/>[NavigationBar.vue]"]
  node_i18n["Chinese / English i18n<br/>localization<br/>[index.ts]"]
end

subgraph group_data["Data Boundary"]
  node_api{{"API Transport<br/>HTTP client<br/>[apiService.ts]"}}
  node_api_clients["Domain API Clients<br/>API adapters<br/>[gameData.api.ts]"]
  node_schemas["Payload Schemas<br/>validation"]
  node_loaders["Game &amp; Planning Loaders<br/>data orchestration"]
  node_query_cache[("Query Cache<br/>repository store<br/>[queryRepository.ts]")]
  node_indexeddb[("IndexedDB Domain Data<br/>browser persistence<br/>[useDB.ts]")]
end

subgraph group_planning["Planning Engine"]
  node_plan_state[("Plan State &amp; Persistence<br/>state store<br/>[planningStore.ts]")]
  node_calculation{{"Plan Calculation Pipeline<br/>calculation coordinator"}}
  node_calculations["Production Calculations<br/>deterministic calculations"]
  node_plan_workspace["Plan Workspace<br/>planner UI<br/>[PlanArea.vue]"]
end

subgraph group_analysis["Analysis Tools"]
  node_empire_analysis["Empire Analysis<br/>economic aggregation<br/>[EmpireAnalysis.vue]"]
  node_market_tools["ROI &amp; Market Tools<br/>analysis features"]
  node_production_graph{{"Production Chain Graph<br/>graph transformation<br/>[productionGraph.ts]"}}
  node_graph_view["Vue Flow Graph View<br/>graph renderer<br/>[useGraph.ts]"]
end

subgraph group_account["User Operations"]
  node_user_session["User Session<br/>identity state<br/>[userStore.ts]"]
  node_account_api["Account API<br/>identity adapter<br/>[userData.api.ts]"]
  node_preferences["Preferences &amp; Endpoints<br/>user configuration<br/>[usePreferences.ts]"]
  node_game_actions{{"FIO &amp; XIT Actions<br/>external game operations<br/>[useFIORepair.ts]"}}
  node_analytics["Analytics<br/>telemetry adapter<br/>[useAnalytics.ts]"]
end

node_bootstrap -->|"mounts"| node_shell
node_shell -->|"hosts"| node_router
node_shell -->|"renders"| node_navigation
node_shell -->|"initializes"| node_i18n
node_router -->|"selects"| node_views
node_views -->|"loads data"| node_loaders
node_loaders -->|"requests"| node_api_clients
node_loaders -->|"reads and writes"| node_query_cache
node_api_clients -->|"validates with"| node_schemas
node_api_clients -->|"uses"| node_api
node_indexeddb -->|"provides local datasets"| node_loaders
node_views -->|"renders"| node_plan_workspace
node_loaders -->|"hydrates"| node_plan_state
node_plan_workspace -->|"edits"| node_plan_state
node_plan_state -->|"feeds"| node_calculation
node_calculation -->|"runs"| node_calculations
node_calculations -->|"produces results"| node_plan_workspace
node_plan_state -->|"aggregates plans"| node_empire_analysis
node_empire_analysis -->|"informs"| node_market_tools
node_calculations -->|"supplies relationships"| node_production_graph
node_production_graph -->|"builds graph"| node_graph_view
node_views -->|"renders tool"| node_graph_view
node_account_api -->|"uses"| node_api
node_account_api -->|"updates"| node_user_session
node_user_session -->|"scopes"| node_preferences
node_user_session -->|"authorizes"| node_game_actions
node_game_actions -->|"executes through"| node_api
node_shell -.->|"tracks through"| node_analytics

click node_bootstrap "https://github.com/supch/prunplanner-zh/blob/main/src/main.ts"
click node_shell "https://github.com/supch/prunplanner-zh/blob/main/src/AppProvider.vue"
click node_router "https://github.com/supch/prunplanner-zh/blob/main/src/router/index.ts"
click node_views "https://github.com/supch/prunplanner-zh/blob/main/src/views/PlanView.vue"
click node_navigation "https://github.com/supch/prunplanner-zh/blob/main/src/layout/components/NavigationBar.vue"
click node_i18n "https://github.com/supch/prunplanner-zh/blob/main/src/locales/index.ts"
click node_api "https://github.com/supch/prunplanner-zh/blob/main/src/lib/apiService.ts"
click node_api_clients "https://github.com/supch/prunplanner-zh/blob/main/src/features/api/gameData.api.ts"
click node_schemas "https://github.com/supch/prunplanner-zh/blob/main/src/features/api/schemas/gameData.schemas.ts"
click node_loaders "https://github.com/supch/prunplanner-zh/blob/main/src/features/wrapper/usePlanningDataLoader.ts"
click node_query_cache "https://github.com/supch/prunplanner-zh/blob/main/src/lib/query_cache/queryRepository.ts"
click node_indexeddb "https://github.com/supch/prunplanner-zh/blob/main/src/database/composables/useDB.ts"
click node_plan_state "https://github.com/supch/prunplanner-zh/blob/main/src/stores/planningStore.ts"
click node_calculation "https://github.com/supch/prunplanner-zh/blob/main/src/features/planning/usePlanCalculation.ts"
click node_calculations "https://github.com/supch/prunplanner-zh/blob/main/src/features/planning/calculations/buildingCalculations.ts"
click node_plan_workspace "https://github.com/supch/prunplanner-zh/blob/main/src/features/planning/components/PlanArea.vue"
click node_empire_analysis "https://github.com/supch/prunplanner-zh/blob/main/src/features/empire/components/EmpireAnalysis.vue"
click node_market_tools "https://github.com/supch/prunplanner-zh/blob/main/src/features/market_exploration/useMarketExploration.ts"
click node_production_graph "https://github.com/supch/prunplanner-zh/blob/main/src/features/production_chain/productionGraph.ts"
click node_graph_view "https://github.com/supch/prunplanner-zh/blob/main/src/features/production_chain/useGraph.ts"
click node_user_session "https://github.com/supch/prunplanner-zh/blob/main/src/stores/userStore.ts"
click node_account_api "https://github.com/supch/prunplanner-zh/blob/main/src/features/api/userData.api.ts"
click node_preferences "https://github.com/supch/prunplanner-zh/blob/main/src/features/preferences/usePreferences.ts"
click node_game_actions "https://github.com/supch/prunplanner-zh/blob/main/src/features/fio/useFIORepair.ts"
click node_analytics "https://github.com/supch/prunplanner-zh/blob/main/src/lib/analytics/useAnalytics.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_bootstrap,node_shell,node_router,node_views,node_navigation,node_i18n toneBlue
class node_api,node_api_clients,node_schemas,node_loaders,node_query_cache,node_indexeddb toneAmber
class node_plan_state,node_calculation,node_calculations,node_plan_workspace toneMint
class node_empire_analysis,node_market_tools,node_production_graph,node_graph_view toneRose
class node_user_session,node_account_api,node_preferences,node_game_actions,node_analytics toneIndigo
```

## Components

### SPA Shell

- [Vue Bootstrap](https://github.com/supch/prunplanner-zh/blob/main/src/main.ts): runtime entry · `src/main.ts`
- [App Provider & Shell](https://github.com/supch/prunplanner-zh/blob/main/src/AppProvider.vue): application shell · `src/AppProvider.vue`
- [Feature Router](https://github.com/supch/prunplanner-zh/blob/main/src/router/index.ts): routing · `src/router/index.ts`
- [Planner & Empire Views](https://github.com/supch/prunplanner-zh/blob/main/src/views/PlanView.vue): feature views · `src/views/PlanView.vue`
- [Navigation & Status](https://github.com/supch/prunplanner-zh/blob/main/src/layout/components/NavigationBar.vue): layout components · `src/layout/components/NavigationBar.vue`
- [Chinese / English i18n](https://github.com/supch/prunplanner-zh/blob/main/src/locales/index.ts): localization · `src/locales/index.ts`

### Data Boundary

- [API Transport](https://github.com/supch/prunplanner-zh/blob/main/src/lib/apiService.ts): HTTP client · Uses the configured PRUNplanner backend URL. · `src/lib/apiService.ts`
- [Domain API Clients](https://github.com/supch/prunplanner-zh/blob/main/src/features/api/gameData.api.ts): API adapters · `src/features/api/gameData.api.ts`
- [Payload Schemas](https://github.com/supch/prunplanner-zh/blob/main/src/features/api/schemas/gameData.schemas.ts): validation · Validates backend payloads at the client boundary. · `src/features/api/schemas/gameData.schemas.ts`
- [Game & Planning Loaders](https://github.com/supch/prunplanner-zh/blob/main/src/features/wrapper/usePlanningDataLoader.ts): data orchestration · `src/features/wrapper/usePlanningDataLoader.ts`
- [Query Cache](https://github.com/supch/prunplanner-zh/blob/main/src/lib/query_cache/queryRepository.ts): repository store · `src/lib/query_cache/queryRepository.ts`
- [IndexedDB Domain Data](https://github.com/supch/prunplanner-zh/blob/main/src/database/composables/useDB.ts): browser persistence · `src/database/composables/useDB.ts`

### Planning Engine

- [Plan State & Persistence](https://github.com/supch/prunplanner-zh/blob/main/src/stores/planningStore.ts): state store · `src/stores/planningStore.ts`
- [Plan Calculation Pipeline](https://github.com/supch/prunplanner-zh/blob/main/src/features/planning/usePlanCalculation.ts): calculation coordinator · Coordinates precomputation and specialized plan handlers. · `src/features/planning/usePlanCalculation.ts`
- [Production Calculations](https://github.com/supch/prunplanner-zh/blob/main/src/features/planning/calculations/buildingCalculations.ts): deterministic calculations · Building, extraction, bonus, habitation, and workforce calculations. · `src/features/planning/calculations/buildingCalculations.ts`
- [Plan Workspace](https://github.com/supch/prunplanner-zh/blob/main/src/features/planning/components/PlanArea.vue): planner UI · `src/features/planning/components/PlanArea.vue`

### Analysis Tools

- [Empire Analysis](https://github.com/supch/prunplanner-zh/blob/main/src/features/empire/components/EmpireAnalysis.vue): economic aggregation · Aggregates plan-level material and economic behavior. · `src/features/empire/components/EmpireAnalysis.vue`
- [ROI & Market Tools](https://github.com/supch/prunplanner-zh/blob/main/src/features/market_exploration/useMarketExploration.ts): analysis features · `src/features/market_exploration/useMarketExploration.ts`
- [Production Chain Graph](https://github.com/supch/prunplanner-zh/blob/main/src/features/production_chain/productionGraph.ts): graph transformation · Builds production nodes and edges for visualization. · `src/features/production_chain/productionGraph.ts`
- [Vue Flow Graph View](https://github.com/supch/prunplanner-zh/blob/main/src/features/production_chain/useGraph.ts): graph renderer · Applies graph state and Dagre layout. · `src/features/production_chain/useGraph.ts`

### User Operations

- [User Session](https://github.com/supch/prunplanner-zh/blob/main/src/stores/userStore.ts): identity state · `src/stores/userStore.ts`
- [Account API](https://github.com/supch/prunplanner-zh/blob/main/src/features/api/userData.api.ts): identity adapter · `src/features/api/userData.api.ts`
- [Preferences & Endpoints](https://github.com/supch/prunplanner-zh/blob/main/src/features/preferences/usePreferences.ts): user configuration · `src/features/preferences/usePreferences.ts`
- [FIO & XIT Actions](https://github.com/supch/prunplanner-zh/blob/main/src/features/fio/useFIORepair.ts): external game operations · Explicit boundary for game actions. · `src/features/fio/useFIORepair.ts`
- [Analytics](https://github.com/supch/prunplanner-zh/blob/main/src/lib/analytics/useAnalytics.ts): telemetry adapter · `src/lib/analytics/useAnalytics.ts`

## Connections

- Vue Bootstrap → App Provider & Shell: mounts
- App Provider & Shell → Feature Router: hosts
- App Provider & Shell → Navigation & Status: renders
- App Provider & Shell → Chinese / English i18n: initializes
- Feature Router → Planner & Empire Views: selects
- Planner & Empire Views → Game & Planning Loaders: loads data
- Game & Planning Loaders → Domain API Clients: requests
- Game & Planning Loaders → Query Cache: reads and writes
- Domain API Clients → Payload Schemas: validates with
- Domain API Clients → API Transport: uses
- IndexedDB Domain Data → Game & Planning Loaders: provides local datasets
- Planner & Empire Views → Plan Workspace: renders
- Game & Planning Loaders → Plan State & Persistence: hydrates
- Plan Workspace → Plan State & Persistence: edits
- Plan State & Persistence → Plan Calculation Pipeline: feeds
- Plan Calculation Pipeline → Production Calculations: runs
- Production Calculations → Plan Workspace: produces results
- Plan State & Persistence → Empire Analysis: aggregates plans
- Empire Analysis → ROI & Market Tools: informs
- Production Calculations → Production Chain Graph: supplies relationships
- Production Chain Graph → Vue Flow Graph View: builds graph
- Planner & Empire Views → Vue Flow Graph View: renders tool
- Account API → API Transport: uses
- Account API → User Session: updates
- User Session → Preferences & Endpoints: scopes
- User Session → FIO & XIT Actions: authorizes
- FIO & XIT Actions → API Transport: executes through
- App Provider & Shell → Analytics: tracks through
