# kainsk/sdk architecture

> Architecture diagram of the GitHub repository kainsk/sdk, 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/kainsk/sdk
- Repository: https://github.com/kainsk/sdk

## Overview

##### Main Components

a) Core Components:
- Graph Database Layer
- State Function Runtime
- NATS Integration Layer
- Plugin System
- Cache System
- Monitoring/Metrics System

b) External Dependencies:
- NATS JetStream
- NATS Key-Value Store
- JavaScript V8 Engine

**┌─ Application Layer ─────────────────────┐**
- (User Applications)                     │
- Runtime Layer ──────────────────────────┤
- State Functions                       │
- Plugin System (JS)                    │
- Cache Management                      │
- Graph Database Layer ──────────────────┤
- CRUD Operations                       │
- JPGQL Query Engine                    │
- Transaction Management                │
- Storage & Message Layer ───────────────┤
- NATS JetStream                        │
- NATS KV Store                         │
- ┘

##### Key Elements to Highlight

a) Graph Database Features:
- CRUD operations (embedded/graph/crud)
- JPGQL query engine (embedded/graph/jpgql)
- Transaction management (embedded/graph/tx)
- Debug capabilities (embedded/graph/debug)

b) Runtime Features:
- State function management (statefun/runtime.go)
- Cache system (statefun/cache)
- Plugin architecture (statefun/plugins)

c) Integration Points:
- NATS integration (embedded/nats)
- JavaScript plugin support (statefun/plugins/js)
- Monitoring/metrics (statefun/system)

##### Notes for Implementation

- Use clear boundaries between different layers
- Scaling points and distributed nature
- Version/configuration management
- Demonstrate error handling flow
- Monitoring/observability paths

- Distributed nature of the graph database
- Plugin extensibility
- State function runtime
- Integration with NATS ecosystem
- Monitoring capabilities

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph "Application Layer"
        APP[User Applications]
    end

    subgraph "Runtime Layer"
        SF["State Function Runtime"]:::runtime
        PS["Plugin System"]:::plugin
        CM["Cache Management"]:::cache
        LOG["Logger"]:::system
    end

    subgraph "Graph Database Layer"
        GDB["Graph Database Core"]:::database
        CRUD["CRUD Operations"]:::database
        JPGQL["JPGQL Query Engine"]:::database
        TXM["Transaction Management"]:::database
        DEBUG["Debug Capabilities"]:::database
    end

    subgraph "Storage & Message Layer"
        NATS["NATS Integration"]:::messaging
        KV["NATS KV Store"]:::storage
        JS["NATS JetStream"]:::storage
    end

    subgraph "Monitoring Layer"
        PROM["Prometheus Metrics"]:::monitoring
        GRAF["Grafana Dashboards"]:::monitoring
    end

    %% Relationships
    APP --> SF
    APP --> PS
    SF --> GDB
    SF --> CM
    SF --> LOG
    PS --> SF
    GDB --> CRUD
    GDB --> JPGQL
    GDB --> TXM
    GDB --> DEBUG
    GDB --> NATS
    NATS --> KV
    NATS --> JS
    SF -.-> PROM
    PROM -.-> GRAF

    %% Click Events
    click SF "https://github.com/kainsk/sdk/blob/main/statefun/runtime.go"
    click PS "https://github.com/kainsk/sdk/blob/main/statefun/plugins/plugins.go"
    click CM "https://github.com/kainsk/sdk/blob/main/statefun/cache/cache.go"
    click LOG "https://github.com/kainsk/sdk/blob/main/statefun/logger/logger.go"
    click GDB "https://github.com/kainsk/sdk/tree/main/embedded/graph/"
    click CRUD "https://github.com/kainsk/sdk/tree/main/embedded/graph/crud/"
    click JPGQL "https://github.com/kainsk/sdk/tree/main/embedded/graph/jpgql/"
    click TXM "https://github.com/kainsk/sdk/tree/main/embedded/graph/tx/"
    click DEBUG "https://github.com/kainsk/sdk/tree/main/embedded/graph/debug/"
    click NATS "https://github.com/kainsk/sdk/tree/main/embedded/nats/"
    click KV "https://github.com/kainsk/sdk/blob/main/embedded/nats/kv/kv.go"
    click PROM "https://github.com/kainsk/sdk/blob/main/statefun/system/prometrics.go"
    click GRAF "https://github.com/kainsk/sdk/tree/main/tests/basic/configs/grafana/dashboards/"

    %% Styles
    classDef runtime fill:#3498db
    classDef plugin fill:#f1c40f
    classDef cache fill:#2ecc71
    classDef database fill:#34495e
    classDef messaging fill:#9b59b6
    classDef storage fill:#95a5a6
    classDef monitoring fill:#e74c3c
    classDef system fill:#7f8c8d

    %% Legend
    subgraph Legend
        L1["Runtime Component"]:::runtime
        L2["Plugin Component"]:::plugin
        L3["Cache Component"]:::cache
        L4["Database Component"]:::database
        L5["Messaging Component"]:::messaging
        L6["Storage Component"]:::storage
        L7["Monitoring Component"]:::monitoring
        L8["System Component"]:::system
    end
```
