How stallboy/cfggen works
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).