# notethan/jsi architecture

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

- Interactive diagram: https://gitdiagram.com/notethan/jsi
- Repository: https://github.com/notethan/jsi

## Overview

##### Main Components

a) Core Components:
- Schema Management System
- Instance Management System
- Validation Engine
- Registry System
- Serialization System

b) Supporting Components:
- Meta-schema System
- Reference Resolution System
- Utility Components

**┌─────────────────────────────────────────────────────────────┐**
- Client Applications                      │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────────┐**
- JSI Public API                       │
- ┘
- ↕
**┌─────────────────────────────────────────────────────────────┐**
- Core Components                         │
- ┬───────────────┬──────────────┬─────────────┤
- Schema     │   Instance    │  Validation  │  Registry   │
- Management  │   Management  │    Engine    │   System    │
- ┴───────────────┴──────────────┴─────────────┘
- ↕
**┌─────────────────────────────────────────────────────────────┐**
- Support Components                        │
- ┬───────────────┬──────────────┬─────────────┤
- Meta-schema  │   Reference   │ Serialization│  Utility    │
- System     │  Resolution   │    System    │  Modules    │
- ┴───────────────┴──────────────┴─────────────┘

##### Component Details

Schema Management System:
- Connections to schema classes (draft04, draft06, draft07)
- Schema module generation
- To schema registry

Instance Management System:
- JSI::Base and its relationship with instances
- Mutability handling
- To validation engine

Validation Engine:
- To schema elements
- Validation result flow
- Error handling

Registry System:
- URI resolution
- Autoloading capability
- To reference resolution

##### Important Relationships

- Schema → Instance creation
- Instance → Validation flow
- Registry → Reference resolution
- Meta-schema → Schema validation
- Serialization → External systems

##### Implementation Details

- Lib/jsi/schema/ hierarchy
- Schema elements organization
- Utility module structure
- Integration points with ActiveRecord

##### External Integration Points

Connections to:
- ActiveRecord (via JSICoder)
- JSON/YAML parsers
- External schema repositories

##### Notes

- Keep the focus on the core JSON Schema instantiation process
- Schema module generation system
- Clear separation between schema and instance management
- Validation flow paths
- Demonstrate registry interaction patterns

This system design should be implemented using a professional diagramming tool that supports:
- Clear hierarchical layouts
- Detailed component labeling
- Proper grouping of related components

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Applications"]
        CA[Client App]
    end

    subgraph API["JSI Public API"]
        PublicAPI[JSI Interface]
    end

    subgraph Core["Core Components"]
        direction TB
        SchemaManagement["Schema Management"]:::core
        InstanceManagement["Instance Management"]:::core
        ValidationEngine["Validation Engine"]:::core
        RegistrySystem["Registry System"]:::core
    end

    subgraph Support["Support Components"]
        direction TB
        MetaSchema["Meta-schema System"]:::support
        RefResolution["Reference Resolution"]:::support
        Serialization["Serialization System"]:::support
        Utility["Utility Modules"]:::support
    end

    %% Core Component Details
    subgraph SchemaDetails["Schema Management Details"]
        Draft04["Draft04 Schema"]:::schema
        Draft06["Draft06 Schema"]:::schema
        Draft07["Draft07 Schema"]:::schema
        Elements["Schema Elements"]:::schema
    end

    subgraph InstanceDetails["Instance Management Details"]
        Base["JSI::Base"]:::instance
        Mutability["Mutability Handler"]:::instance
        Node["Node Management"]:::instance
    end

    subgraph ValidationDetails["Validation Details"]
        VError["Validation Error"]:::validation
        VResult["Validation Result"]:::validation
    end

    %% Connections
    CA --> PublicAPI
    PublicAPI --> SchemaManagement
    PublicAPI --> InstanceManagement
    
    SchemaManagement --> SchemaDetails
    InstanceManagement --> InstanceDetails
    ValidationEngine --> ValidationDetails
    
    SchemaManagement <--> RegistrySystem
    InstanceManagement <--> ValidationEngine
    RegistrySystem <--> RefResolution
    SchemaManagement <--> MetaSchema
    InstanceManagement <--> Serialization

    %% Click Events
    click SchemaManagement "https://github.com/notEthan/jsi/blob/main/lib/jsi/schema.rb"
    click Draft04 "https://github.com/notEthan/jsi/blob/main/lib/jsi/schema/draft04.rb"
    click Draft06 "https://github.com/notEthan/jsi/blob/main/lib/jsi/schema/draft06.rb"
    click Draft07 "https://github.com/notEthan/jsi/blob/main/lib/jsi/schema/draft07.rb"
    click Elements "https://github.com/notEthan/jsi/tree/main/lib/jsi/schema/elements/"
    click Base "https://github.com/notEthan/jsi/blob/main/lib/jsi/base.rb"
    click Mutability "https://github.com/notEthan/jsi/blob/main/lib/jsi/base/mutability.rb"
    click Node "https://github.com/notEthan/jsi/blob/main/lib/jsi/base/node.rb"
    click ValidationEngine "https://github.com/notEthan/jsi/blob/main/lib/jsi/validation.rb"
    click VError "https://github.com/notEthan/jsi/blob/main/lib/jsi/validation/error.rb"
    click VResult "https://github.com/notEthan/jsi/blob/main/lib/jsi/validation/result.rb"
    click RegistrySystem "https://github.com/notEthan/jsi/blob/main/lib/jsi/schema_registry.rb"
    click MetaSchema "https://github.com/notEthan/jsi/blob/main/lib/jsi/metaschema_node.rb"
    click RefResolution "https://github.com/notEthan/jsi/blob/main/lib/jsi/schema/ref.rb"
    click Serialization "https://github.com/notEthan/jsi/blob/main/lib/jsi/jsi_coder.rb"
    click Utility "https://github.com/notEthan/jsi/blob/main/lib/jsi/util.rb"

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333
    classDef support fill:#90EE90,stroke:#333
    classDef schema fill:#FFB6C1,stroke:#333
    classDef instance fill:#DDA0DD,stroke:#333
    classDef validation fill:#F0E68C,stroke:#333
    
    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Support Components]:::support
        L3[Schema Components]:::schema
        L4[Instance Components]:::instance
        L5[Validation Components]:::validation
    end
```
