How evestera/json_typegen works
Project Type & Purpose
• This project is a multi-interface code generation tool used to generate type definitions from JSON samples. Its purpose is to support Rust (via a procedural macro), provide a command line interface (CLI) for environments where macro use is less feasible, and offer a web-based interface powered by WebAssembly.
Main Components from the File Structure
• Core Libraries:
• json_typegen: Implements the Rust procedural macro functionality.
• Command Line Interface:
• json_typegen_cli: Builds upon the shared core to provide a CLI for generating types outside of compile-time macros.
• Web Interfaces:
• json_typegen_wasm: Wraps the code generation logic for WebAssembly, allowing the generator to be used in browser environments.
• json_typegen_web: Contains the frontend (built with Svelte) that communicates with the WebAssembly component, providing a user-friendly web interface.
• Demos & Examples:
• json_typegen_demo: Contains a demonstration application to show integration and usage of the type generation tools.
• Support and Configuration:
• CONFIGURATION.md, Cargo.toml files, and CI/CD workflow setups (.github/workflows) indicate integration with a robust Rust tooling and deployment environment.
a. Main Components:
• A “Core Inference Engine” representing json_typegen_shared.
• The “Rust Procedural Macro” component using the core logic (json_typegen).
• A “CLI Tool” component (json_typegen_cli) interfacing with the core.
• The “WASM Interface” (json_typegen_wasm) that adapts the core library for browser use.
• The “Web Frontend” (json_typegen_web) that interacts with the WASM interface.
• Optionally, a “Demo Application” (json_typegen_demo) showing sample use cases.
b. Relationships & Interactions:
• For the web side, illustrate how the web frontend communicates with the WASM module, which in turn calls into the shared core.
• That the CLI and procedural macro components are alternative entry points that both depend on the shared engine.
c. Architectural Patterns/Design Principles:
• Separation of concerns: a core library (json_typegen_shared) is reused by multiple wrappers/adapters, which is a common design in toolchain development.
• Use of conditional compilation in the procedural macro to handle local vs. remote JSON sample loading.
• Modularity: each interface (CLI, WASM, procedural macro) is encapsulated as its own Rust crate, ensuring loose coupling.
d. Technologies, Frameworks, and Libraries:
• Rust: The base language with Cargo package management.
• WebAssembly: Used by json_typegen_wasm for cross-compiling the core logic.
• Svelte (and related web tooling): Underlies json_typegen_web for the user interface.
• CI/CD pipelines: Represented by GitHub Actions files for continuous integration and deployment.
• Additional tooling: The project uses .editorconfig, .gitignore, and configuration markdown files to maintain code quality and build consistency.