# stallboy/cfggen architecture

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

- Interactive diagram: https://gitdiagram.com/stallboy/cfggen
- Repository: https://github.com/stallboy/cfggen

## Overview

Based on our analysis of the file tree and README, this project is a configuration “配表” system that serves three main purposes:
##### Defining object structures and schemas.
2. Allowing users to edit and browse configuration data (through Excel files or via a node-based UI editor).
3. Generating type‐safe code for multiple target languages (Java, C#, Lua) so that applications can easily access and manipulate configured data.

##### Main Components
- Core Config Generation Engine (located within the “app” directory):
– This is the backbone where the configuration schema, data parsing, processing, and code generation logic lives.
- Context/Environment Management (see app/src/main/java/configgen/ctx): Manages file system watching, directory structure, and update triggers.

- Data Parsing and Processing (located in app/src/main/java/configgen/data): Contains parsers for CSV, Excel (using both FastExcel and Apache POI), JSON, and utilities to process and align configuration data.

- Schema Management (under app/src/main/java/configgen/schema): Responsible for handling configuration schemas, constraints, validations, and interrelations (like foreign keys and polymorphic definitions) between fields.

- Value Management (in app/src/main/java/configgen/value): Manages runtime values, conversion, and error handling to produce consistent output.

- Code Generation Modules:
- Java generation (app/src/main/java/configgen/genjava and its “code” subpackage) – Generates Java code while taking hot-update safety and typing into consideration.
- C# generation (app/src/main/java/configgen/gencs) – Converts the configuration into C# code (including binary/text generation).
- JSON and TypeScript generation (app/src/main/java/configgen/genjson) – Supports generating JSON outputs and TS interfaces.
- Lua generation (app/src/main/java/configgen/genlua) – Generates memory-optimized Lua code for runtime consumption.

- Editor Server (in app/src/main/java/configgen/editorserver): Provides a set of services (e.g., CheckJsonService, EditorServer, PromptService, SchemaService, etc.) that likely serve as an API or backend for the configuration editor.

- Graphical Editor – “cfgeditor” Module:
– This front-end component (built with TypeScript/React and Tauri for desktop integration) offers a node-based UI for editing and browsing configurations.
– It contains UI components (in folders like src/flow, src/routes, etc.) and resources (HTML, CSS, package.json) that support user interaction.

- External Interfaces and Tools:
– Example Projects (“example” directory): contain batch scripts and sample configuration files to exercise code generation for different platforms (Java, C#, Lua).
– Testing & Quality: The “app/src/test” directory contains comprehensive test suites for validating the engines, schema, and value modules.
– Documentation and Build Scripts: The “docs” directory and gradle/build scripts show how to build, test, and deploy the project.

##### Relationships and Interactions
- Data Flow:
– Raw configuration input may come from Excel, CSV, or JSON files (Activity in Data Parsing modules).
– The configuration engine validates these inputs against defined schemas (Schema modules) and processes/converts values (Value modules).
– Based on the processed data, various language-specific code generators (Java, C#, Lua, JSON) produce programmatic access code.

- Editor Interaction:
– The Editor Server component acts as a backend service to offer real-time editing, searching, and schema validation support for the “cfgeditor” UI.
– The cfgeditor module communicates with this backend to retrieve configuration data and push changes.

- Integration Points:
– Build tools (Gradle, batch scripts) automate the generation of artifacts (e.g., cfggen.jar, cfgeditor.exe) needed for deployment and testing.
– Testing suites enforce that all parts of the workflow (from parsing to code generation) function as intended.

##### Architectural Patterns and Design Principles
- Modularity: The project is split into clearly separated submodules based on functionality (parsing, schema, value, code generation, UI editor).
- Layered Architecture: Input processing (raw configuration files) → Validation & transformation (schema and data parsing layers) → Code generation services → User editing interfaces.
- Extensibility: Separate modules for generating code in different languages allow for future extension with minimal changes to the core engine.
- Separation of Concerns: The backend (core generator) is isolated from the front-end (editor) ensuring that each has dedicated responsibilities.

##### Relevant Technologies and Frameworks
- Java (jdk21) and Gradle for building the core engine.
- Apache POI and FastExcel for handling Excel files.
- Tauri framework and React/TypeScript for building the cfgeditor UI.
- Testing frameworks and possibly custom parsers (see ANTLR generated files in schema/cfg).

##### Key Elements to be Included
- Clear labels for each component (e.g., “Data Parsing Module”, “Schema Validator”, “Java Code Generator”, “C# Generator”, “Lua Generator”, “Editor Server”, “cfgeditor UI”).

##### Final Recommendations
- Don’t shy away from adding intermediary layers such as the file system watchers (context management) and test suites, as these are fundamental to ensuring the reliability of the system.
- Extensibility points (e.g., support for multiple target languages) and external dependencies (such as build environments and external libraries).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Input Layer
    RC("Raw Config Files (Excel,CSV,JSON)"):::external

    %% Core Engine Subgraph
    subgraph "Core Config Generation Engine"
        CCE("Core Config Generation Engine"):::backend
        Ctx("Context/Environment Management"):::backend
        DPP("Data Parsing and Processing"):::backend
        SM("Schema Management"):::backend
        VM("Value Management"):::backend
        %% Code Generation Modules Subgraph
        subgraph "Code Generation Modules"
            JavaGen("Java Code Generator"):::backend
            CSharpGen("C# Code Generator"):::backend
            JsonTSGen("JSON/TypeScript Generator"):::backend
            LuaGen("Lua Code Generator"):::backend
        end
        ES("Editor Server"):::backend
    end

    %% Frontend Editor
    FE("Graphical Editor (cfgeditor)"):::frontend

    %% External Interfaces & Tools
    subgraph "External Interfaces & Tools"
        EP("Example Projects"):::external
        Test("Testing & Quality"):::external
        Docs("Documentation & Build Scripts"):::external
    end

    %% Data Flow Connections
    RC --> DPP
    Ctx --> DPP
    DPP --> SM
    SM --> VM
    VM --> JavaGen
    VM --> CSharpGen
    VM --> JsonTSGen
    VM --> LuaGen

    %% Editor Interaction
    ES ---|"API Connection"| FE

    %% Integration with Core Engine
    CCE --> RC
    CCE --> Ctx
    CCE --> DPP
    CCE --> SM
    CCE --> VM
    CCE --> ES

    %% External Tools Integration
    Docs --> CCE
    Test --> CCE
    EP --> CCE

    %% Click Events
    click CCE "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen"
    click Ctx "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/ctx"
    click DPP "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/data"
    click SM "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/schema"
    click VM "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/value"
    click JavaGen "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/genjava"
    click CSharpGen "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/gencs"
    click JsonTSGen "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/genjson"
    click LuaGen "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/genlua"
    click ES "https://github.com/stallboy/cfggen/tree/master/app/src/main/java/configgen/editorserver"
    click FE "https://github.com/stallboy/cfggen/tree/master/cfgeditor"
    click EP "https://github.com/stallboy/cfggen/tree/master/example"
    click Test "https://github.com/stallboy/cfggen/tree/master/app/src/test"
    click Docs "https://github.com/stallboy/cfggen/tree/master/docs"

    %% Styles
    classDef backend fill:#f4cccc,stroke:#cc0000,stroke-width:2px;
    classDef frontend fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef external fill:#c9daf8,stroke:#1155cc,stroke-width:2px;
```
