# zhxiaogg/fluorite architecture

> Architecture diagram of the GitHub repository zhxiaogg/fluorite, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zhxiaogg/fluorite
- Repository: https://github.com/zhxiaogg/fluorite

## Overview

##### Main Components

a) Schema Input Layer:
- YAML/JSON Schema Definitions
- Schema Parser/Validator

b) Code Generation Core:
- ABI (Abstract Binary Interface) Layer
- Language-specific Generators
- Type System

c) Output Layer:
- Package Writers
- Generated Code Files

##### Detailed Component Breakdown

a) Input Processing:
- To a Schema Parser component
- Fluorite Definition Parser (fluorite/definition.yaml)

b) Core Processing:
- Separate modules for:
- Type System (code_gen/abi/type_info.rs)
- Generator Interface (code_gen/generator.rs)
- Language-specific Generators:
- Rust Generator
- TypeScript Generator (marked as WIP)

c) Output Generation:
- Package Writer components for each target language
- Build Integration (build.rs support)

##### Specific Implementation Details

- Blue rectangles: Core components
- Green rectangles: Language-specific generators
- Yellow diamonds: Input/Output files
- Orange ovals: Runtime components

##### Flow Directions

**Schema Definition Files → Parser → CodeGen Engine → Language Generators → Output Files**

##### Important Subsystems

a) Type System:
- Primitive Types
- Collection Types
- User-defined Types
- Type Info Management

b) Generator System:
- Pre-processor
- Context Management
- Type Writer
- Package Writer

##### Integration Points

Highlight:
- Build System Integration
- Runtime Library Connection
- Serde Integration Points

##### Key Architectural Patterns to Emphasize

- Visitor Pattern for type handling
- Factory Pattern for generator creation
- Strategy Pattern for different language backends

##### Technical Details

- Supported input formats (YAML/JSON)
- Output language support (Rust, TypeScript)
- Build integration methods
- Runtime dependencies

Remember to show both the compile-time (codegen) and runtime (fluorite runtime) components separately, as they operate at different phases of the system's lifecycle.

This architecture should clearly demonstrate how Fluorite transforms schema definitions into type-safe code while maintaining extensibility for additional language targets.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Input
        SchemaFiles["Schema Definition Files"]
        Parser["Schema Parser/Validator"]
    end

    subgraph "Core Processing"
        CodeGenEngine["Core CodeGen Engine"]
        ABI["ABI Layer"]
        TypeSystem["Type System"]
        GenInterface["Generator Interface"]
    end

    subgraph "Language Generators"
        RustGen["Rust Generator"]
        TSGen["TypeScript Generator"]:::wip
    end

    subgraph "Generator Components"
        PreProcessor["Pre-processor"]
        Context["Context Management"]
        TypeWriter["Type Writer"]
        PackageWriter["Package Writer"]
        GenOptions["Generator Options"]
    end

    subgraph "Build & Runtime"
        BuildInt["Build Integration"]
        Runtime["Runtime Library"]
    end

    subgraph "Output"
        RustCode["Rust Code"]
        TSCode["TypeScript Code"]:::wip
    end

    %% Connections
    SchemaFiles --> Parser
    Parser --> CodeGenEngine
    CodeGenEngine --> |Uses| ABI
    CodeGenEngine --> |Uses| TypeSystem
    CodeGenEngine --> |Uses| GenInterface
    GenInterface --> RustGen
    GenInterface --> TSGen
    
    RustGen --> |Uses| PreProcessor
    RustGen --> |Uses| Context
    RustGen --> |Uses| TypeWriter
    RustGen --> |Uses| PackageWriter
    RustGen --> |Uses| GenOptions
    
    RustGen --> RustCode
    TSGen --> TSCode
    
    BuildInt --> |Integrates| RustCode
    Runtime --> |Supports| RustCode

    %% Styles
    classDef default fill:#B8D0EB,stroke:#333,stroke-width:1px
    classDef wip fill:#FFE5CC,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef input fill:#FFE5B4,stroke:#333,stroke-width:1px
    classDef output fill:#98FB98,stroke:#333,stroke-width:1px
    classDef runtime fill:#FFA07A,stroke:#333,stroke-width:1px

    class SchemaFiles input
    class RustCode,TSCode output
    class Runtime runtime
    class TSGen wip
    class TSCode wip

    %% Click events
    click SchemaFiles "https://github.com/zhxiaogg/fluorite/blob/master/examples/orders.yml"
    click Parser "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/definitions/mod.rs"
    click ABI "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/abi.rs"
    click TypeSystem "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/abi/type_info.rs"
    click GenInterface "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/generator.rs"
    click RustGen "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/rust/mod.rs"
    click TSGen "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/ts/mod.rs"
    click PackageWriter "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/rust/package_writer.rs"
    click TypeWriter "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/rust/type_writer.rs"
    click PreProcessor "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/rust/pre_processor.rs"
    click BuildInt "https://github.com/zhxiaogg/fluorite/blob/master/examples/demo/build.rs"
    click Runtime "https://github.com/zhxiaogg/fluorite/blob/master/runtime/src/lib.rs"
    click Context "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/rust/context.rs"
    click GenOptions "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/rust/options.rs"
    click CodeGenEngine "https://github.com/zhxiaogg/fluorite/blob/master/codegen/src/code_gen/mod.rs"
```
