# evestera/json_typegen architecture

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

- Interactive diagram: https://gitdiagram.com/evestera/json_typegen
- Repository: https://github.com/evestera/json_typegen

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Input
    JSON["JSON Sample Input"]:::external

    %% Interfaces Subgraph
    subgraph "Interfaces"
        Macro["Rust Procedural Macro (json_typegen)"]:::interface
        CLI["Command Line Interface (json_typegen_cli)"]:::cli
        WASM["WASM Interface (json_typegen_wasm)"]:::wasm
        Web["Web Frontend (json_typegen_web)"]:::web
    end

    %% Core Engine and Demo
    Engine["Core Inference Engine (json_typegen_shared)"]:::core
    DemoApp["Demo Application (json_typegen_demo)"]:::demo

    %% Data Flow from JSON input to Interfaces
    JSON -->|"inputs"| Macro
    JSON -->|"inputs"| CLI
    JSON -->|"inputs"| WASM
    JSON -->|"inputs"| DemoApp

    %% Interfaces using Core Engine
    Macro -->|"uses"| Engine
    CLI -->|"uses"| Engine
    WASM -->|"calls"| Engine

    %% Web Frontend communicates with WASM module
    Web -->|"invokes"| WASM

    %% Demo demonstrates usage of the Core Engine
    DemoApp -->|"demonstrates"| Engine

    %% Click Events
    click Engine "https://github.com/evestera/json_typegen/tree/master/json_typegen_shared/"
    click Macro "https://github.com/evestera/json_typegen/tree/master/json_typegen/"
    click CLI "https://github.com/evestera/json_typegen/tree/master/json_typegen_cli/"
    click WASM "https://github.com/evestera/json_typegen/tree/master/json_typegen_wasm/"
    click Web "https://github.com/evestera/json_typegen/tree/master/json_typegen_web/"
    click DemoApp "https://github.com/evestera/json_typegen/tree/master/json_typegen_demo/"

    %% Styles
    classDef core fill:#e3f2fd,stroke:#1e88e5,stroke-width:2px;
    classDef interface fill:#fce4ec,stroke:#d81b60,stroke-width:2px;
    classDef cli fill:#e8f5e9,stroke:#43a047,stroke-width:2px;
    classDef wasm fill:#e0f7fa,stroke:#00acc1,stroke-width:2px;
    classDef web fill:#f3e5f5,stroke:#8e24aa,stroke-width:2px;
    classDef demo fill:#fff3e0,stroke:#fb8c00,stroke-width:2px;
    classDef external fill:#f9fbe7,stroke:#9e9d24,stroke-width:2px;
```
