# geeeeeeker/supersonic architecture

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

- Interactive diagram: https://gitdiagram.com/geeeeeeker/supersonic
- Repository: https://github.com/geeeeeeker/supersonic

## Overview

##### Project type and purpose
- This is a full-stack, modular Java/Spring-Boot application that implements two paradigms:
- Chat BI (natural-language→SQL powered by LLMs, vector stores, plugins, conversation memory)
- Headless BI (semantic layer exposing metadata and query API)
- It includes a React/TypeScript front-end (webapp/packages/chat-sdk & supersonic-fe), several Java back-end modules (auth, authorization, chat/api, chat/server, headless/api, headless/server, common libraries), plus benchmarking, evaluation, and Docker/assembly scripts.

##### Top-level components
a. Front-end UI
- Chat BI client (chat-sdk)
- Headless BI console (supersonic-fe)
b. Back-end micro-modules (Spring Boot apps)
- Auth Service: authentication REST API
- Authorization Service: permission REST API
- Chat API: HTTP façade exposing chat endpoints
- Chat Server: core chat pipeline (schema mapper, parser, corrector, translator, plugin manager, memory)
- Headless API: semantic-layer façade
- Headless Server: semantic-layer engine (model management, YAML-driven metadata, JDBC adapters)
- Common library: shared config, Calcite SQL parser, embedding, JDBC templates
c. Persistence & caches
- Relational DB (H2/MySQL/Postgres etc.) for metadata and chat records
- Embedding store options (in-memory, Chroma, Milvus, PGVector, OpenSearch) for vector retrieval
- Caffeine cache for query caching
d. External services
- LLM providers via Dify, OpenAI, LocalAI, Ollama
- Third-party plugins (web service, web page, custom tools)
e. Operations
- Docker Compose / standalone launch scripts
- CI workflows (GitHub Actions)

##### Component interactions and data flows
- User (Browser) → Front-end UI → REST API calls to Chat API or Headless API
- Chat API → delegates to Chat Server modules:
1. Schema Mapper ← Knowledge Base (periodically built from semantic models)
2. Semantic Parser (rule-based & LLM-based)
3. Semantic Corrector (rule-based & LLM-based)
4. Semantic Translator → SQL
5. DB Adaptor → executes SQL against RDB
6. Post-processors (formatting, recommendations)
7. Chat Memory retrieval/insertion (vector store or DB)
8. Chat Plugin selection & invocation via LLM
- Headless API → Headless Server:
1. CRUD operations on YAML metadata (models, dimensions, metrics, tags)
2. Semantic model compilation → persisted to DB and Knowledge Base
- Auth & Authorization services sit in front of Chat/Headless APIs to enforce access control (dataset/column/row).
- Common library is invoked by all back-end modules for config, SQL parsing, HTTP clients, thread pools.

##### Architectural patterns & design principles
- Modular micro-services (many Java modules packaged as separate Spring Boot apps)
- SPI/Factory pattern for embedding stores, DB adaptors, LLM providers, authentication strategies, semantic parsers/correctors
- Layered design (REST controller → Service → Repository/Mapper → DB)
- Plugin architecture for chat extensions
- Caching layer (Caffeine) and asynchronous tasks (listeners, scheduled tasks)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        style UI_BG fill:#E8F0FE,stroke:#ccc
        ChatUI["Chat BI Client<br/>(React/TS)"]:::ui
        HeadlessUI["Headless BI Console<br/>(React/TS)"]:::ui
    end

    %% API Gateway Layer
    subgraph "API Gateway Layer"
        style API_BG fill:#E7F6E7,stroke:#ccc
        AuthService["Auth Service<br/>(Spring Boot)"]:::backend
        AuthorizationService["Authorization Service<br/>(Spring Boot)"]:::backend
    end

    %% Chat BI Layer
    subgraph "Chat BI Layer"
        style CHAT_BG fill:#E7F6E7,stroke:#ccc
        ChatAPI["Chat API<br/>(Spring Boot)"]:::backend
        subgraph "Chat Server Pipeline"
            style PIPE_BG fill:#F0FFF0,stroke:#ccc
            SchemaMapper["Schema Mapper"]:::shared
            SemanticParser["Semantic Parser"]:::shared
            SemanticCorrector["Semantic Corrector"]:::shared
            SemanticTranslator["Semantic Translator"]:::shared
            DBAdapter["DB Adapter"]:::backend
            PostProcessors["Post-processors"]:::shared
            ChatMemory["Chat Memory"]:::shared
            PluginManager["Plugin Manager"]:::shared
        end
    end

    %% Headless BI Layer
    subgraph "Headless BI Layer"
        style HEADLESS_BG fill:#E7F6E7,stroke:#ccc
        HeadlessAPI["Headless API<br/>(Spring Boot)"]:::backend
        subgraph "Headless Server Engine"
            style HL_SERVER_BG fill:#F0FFF0,stroke:#ccc
            YAMLManager["YAML Metadata Manager"]:::shared
            ModelCompiler["Semantic Model Compiler"]:::shared
            CRUDService["CRUD Service"]:::shared
            Listeners["Listeners & Tasks"]:::shared
        end
    end

    %% Common Library
    CommonLib["Common Library<br/>(config, Calcite, JDBC)"]:::shared

    %% Persistence Layer
    subgraph "Persistence Layer"
        style PERSIST_BG fill:#FFF4E5,stroke:#ccc
        RDB["Relational DB<br/>(H2/MySQL/Postgres)"]:::persistence
        EmbeddingStore["Embedding Store<br/>(In-memory/Chroma/Milvus/PGVector/OpenSearch)"]:::persistence
        Cache["Caffeine Cache"]:::persistence
    end

    %% External Services
    subgraph "External Services"
        style EXT_BG fill:#F5E6FF,stroke:#ccc
        LLMs["LLM Providers<br/>(Dify/OpenAI/LocalAI/Ollama)"]:::external
        Plugins["Third-party Plugins"]:::external
    end

    %% Operations
    subgraph "Operations"
        style OPS_BG fill:#F0F0F0,stroke:#ccc
        DockerCompose["Docker Compose<br/>& Images"]:::ops
        AssemblyScripts["Assembly Scripts"]:::ops
    end

    %% Flow arrows
    ChatUI -->|"HTTP JSON"| AuthService
    HeadlessUI -->|"HTTP JSON"| AuthService
    AuthService -->|"JWT / OAuth"| AuthorizationService
    AuthorizationService -->|"OAuth Token"| ChatAPI
    AuthorizationService -->|"OAuth Token"| HeadlessAPI

    ChatAPI -->|"HTTP JSON"| SchemaMapper
    SchemaMapper --> SemanticParser
    SemanticParser --> SemanticCorrector
    SemanticCorrector --> SemanticTranslator
    SemanticTranslator --> DBAdapter
    DBAdapter --> RDB
    SemanticTranslator --> Cache
    SemanticTranslator --> EmbeddingStore
    SemanticTranslator --> ChartMemory
    SchemaMapper --> ModelCompiler
    ModelCompiler --> RDB
    PostProcessors --> ChatAPI
    PluginManager --> LLMs
    PluginManager --> Plugins
    ChatMemory --> EmbeddingStore
    ChatMemory --> RDB

    HeadlessAPI -->|"HTTP JSON"| CRUDService
    CRUDService --> YAMLManager
    YAMLManager --> ModelCompiler
    ModelCompiler --> RDB
    Listeners --> ModelCompiler

    %% Common library invocation
    ChatAPI --> CommonLib
    ChatServerPipeline --> CommonLib
    HeadlessAPI --> CommonLib
    HeadlessServerEngine --> CommonLib

    %% Operations links
    DockerCompose -.-> ChatAPI
    DockerCompose -.-> HeadlessAPI
    AssemblyScripts -.-> DockerCompose

    %% Click Events
    click ChatUI "https://github.com/geeeeeeker/supersonic/tree/master/webapp/packages/chat-sdk"
    click HeadlessUI "https://github.com/geeeeeeker/supersonic/tree/master/webapp/packages/supersonic-fe"
    click AuthService "https://github.com/geeeeeeker/supersonic/tree/master/auth/api"
    click AuthenticationModule "https://github.com/geeeeeeker/supersonic/tree/master/auth/authentication"
    click AuthorizationModule "https://github.com/geeeeeeker/supersonic/tree/master/auth/authorization"
    click ChatAPI "https://github.com/geeeeeeker/supersonic/tree/master/chat/api"
    click ChatServer "https://github.com/geeeeeeker/supersonic/tree/master/chat/server"
    click HeadlessAPI "https://github.com/geeeeeeker/supersonic/tree/master/headless/api"
    click HeadlessServer "https://github.com/geeeeeeker/supersonic/tree/master/headless/server"
    click CommonLib "https://github.com/geeeeeeker/supersonic/tree/master/common"
    click DockerCompose "https://github.com/geeeeeeker/supersonic/blob/master/docker/docker-compose.yml"
    click AssemblyScripts "https://github.com/geeeeeeker/supersonic/blob/master/assembly/bin/supersonic-*.sh"
    click LLMs "https://github.com/geeeeeeker/supersonic/tree/master/common/src/main/java/dev/langchain4j"

    %% Styles
    classDef ui fill:#D0E1FF,stroke:#4A90E2,color:#000
    classDef backend fill:#DFF2E1,stroke:#2E8B57,color:#000
    classDef shared fill:#FFF9C4,stroke:#F9A825,color:#000
    classDef persistence fill:#FFE6CC,stroke:#FF8C00,color:#000
    classDef external fill:#E5DAF5,stroke:#8A2BE2,color:#000
    classDef ops fill:#E8E8E8,stroke:#A9A9A9,color:#000
```
