# jaseci-labs/jaseci architecture

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

- Interactive diagram: https://gitdiagram.com/jaseci-labs/jaseci
- Repository: https://github.com/jaseci-labs/jaseci

## Overview

##### Project Type and Purpose
- This is a polyglot, full-stack language & tooling ecosystem, not a single web app.
- Components include:
– A superset language & compiler (jaclang)
– Cloud-native server tooling (jac-cloud)
– An IDE extension (VS Code)
– An LLM integration library (mtllm)

##### File Structure
- Top-level modules:
– `jac/` → language definition, compiler passes, runtime, langserve (LSP)
– `jac-cloud/` → REST & WebSocket server, plugin system, SSO, data sources
– `jac/support/vscode_ext/` → VS Code extension, LSP client, visual debugger
– `jac-mtllm/` → LLM abstraction layer, provider adapters, tools
- Notice subfolders: compiler/passes, langserve, runtimelib, routers, plugin implementations, llms providers.

##### Extract Architecture Insights from README
- “jaclang” is the CPython‐like reference implementation (compiler → runtime).
- “jac-cloud” auto-wraps a Jac app into a production API server.
- “mtllm” plugs language models into Jac programs.
- The VS Code extension connects to jaclang’s LSP (langserve).

##### Main Components & Their Relationships
a. Developer Tools Layer
– VS Code Extension (UI)
- LSP Client ↔ Langserve (JSON-RPC)
- CLI Wrapper (`jac` commands)
b. Language Processing Layer
– Langserve Server
- Provides language-service APIs (syntax, diagnostics, code completion)
– jaclang Compiler
- Parser (Lark), AST & IR passes, bytecode generator
- Sym-tab builder, type inference, code formatter
– Runtime Library
- Constructs, memory, importer, machine executor
c. Cloud Runtime Layer
– jac-cloud Server
- HTTP API (FastAPI routers for healthz, SSO, user, webhook)
- WebSocket plugin support, scheduler, memory contexts
- Data sources: local DB, Redis, external SSO providers
– Plugin System
- CLI plugin, scheduler plugin, websocket plugin
d. LLM Integration Layer
– mtllm Core
- Abstract LLM interface, tool registry (math, wiki, Serper)
- Provider adapters (OpenAI, Anthropic, Hugging Face, etc.)
e. External Services
– Redis, SSO providers (Google, Apple), Database
– HTTP clients for LLM providers

##### Architectural Patterns & Design Principles
- Layered architecture: UI/CLI → language service → compiler → runtime → infrastructure
- Plugin architecture in both jac-cloud and mtllm for extensibility
- Microservices style for langserve (LSP) and jac-cloud (API server)
- Pass-based compiler pipeline
- Clear separation of concerns: parsing, analysis, codegen, execution

##### Elements
- Component labels: exact folder/namespace names (e.g., `jaclang/compiler`, `jac_cloud/jaseci/routers`)
- Notes on protocols (LSP JSON-RPC, HTTP REST, WebSocket, gRPC)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% VS Code Extension Layer
    subgraph "VS Code Extension" 
        direction TB
        VSC_UI["VS Code UI"]:::frontend
        LSP_Client["LSP Client"]:::frontend
        VS_Ext_Commands["Commands & Activation"]:::frontend
        VS_Debugger["Visual Debugger Webview"]:::frontend
    end

    %% Jaclang Language Core Layer
    subgraph "jaclang (Language Core)"
        direction TB
        CLI_Wrapper["CLI Wrapper"]:::langcore
        Langserve["Langserve (LSP Server)"]:::langcore
        LS_Engine["Langserve Engine & Session Manager"]:::langcore
        Compiler["jaclang Compiler"]:::langcore
        Parser["Parser (Lark)"]:::langcore
        Passes["Compiler Passes (AST & IR)"]:::langcore
        RuntimeLib["Runtime Library"]:::langcore
    end

    %% jac-cloud Cloud Runtime Layer
    subgraph "jac-cloud (Cloud Runtime)"
        direction TB
        JC_Entrypoints["Server Entrypoints"]:::cloud
        JC_Server["REST API Server (FastAPI routers)"]:::cloud
        DataSources["Data Sources"]:::cloud
        PluginCore["Plugin System Core"]:::cloud
        PluginImpl["Plugin Implementations"]:::cloud
        SSO["Security & SSO Providers"]:::cloud
    end

    %% mtllm LLM Integration Layer
    subgraph "mtllm (LLM Integration)"
        direction TB
        MT_Core["Core Abstraction & Plugin Loader"]:::llm
        MT_Interface["Abstract LLM Interface & Core"]:::llm
        MT_Adapters["Provider Adapters"]:::llm
        MT_Tools["Tool Registry & Tools"]:::llm
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Redis[(Redis)]:::db
        LocalDB[(LocalDB)]:::db
        SSO_Providers["SSO Providers"]:::external
        LLM_Providers["LLM Providers"]:::external
    end

    %% Connections
    VSC_UI --> LSP_Client
    VS_Ext_Commands --> LSP_Client
    VS_Debugger --> LSP_Client
    LSP_Client -->|"JSON-RPC"| Langserve

    CLI_Wrapper -->|"CLI"| Compiler
    Langserve --> LS_Engine
    LS_Engine --> Compiler
    Compiler --> Parser
    Parser --> Passes
    Passes --> Compiler
    Compiler --> RuntimeLib

    RuntimeLib -->|"import"| JC_Server
    JC_Entrypoints --> JC_Server
    JC_Server -->|"HTTP/REST"| DataSources
    JC_Server -->|"HTTP/REST"| Redis
    JC_Server -->|"HTTP/REST"| LocalDB
    JC_Server --> PluginCore
    PluginCore --> PluginImpl
    PluginImpl --> JC_Server
    JC_Server --> SSO
    SSO --> SSO_Providers

    RuntimeLib -->|"function call"| MT_Core
    MT_Core --> MT_Interface
    MT_Interface --> MT_Adapters
    MT_Tools --> MT_Adapters
    MT_Adapters -->|"HTTP"| LLM_Providers

    %% Click Events
    click CLI_Wrapper "https://github.com/jaseci-labs/jaseci/blob/main/jac/jaclang/cli/cli.py"
    click Langserve "https://github.com/jaseci-labs/jaseci/blob/main/jac/jaclang/langserve/server.py"
    click LS_Engine "https://github.com/jaseci-labs/jaseci/blob/main/jac/jaclang/langserve/engine.py"
    click LS_Engine "https://github.com/jaseci-labs/jaseci/blob/main/jac/jaclang/langserve/sem_manager.py"
    click Compiler "https://github.com/jaseci-labs/jaseci/tree/main/jac/jaclang/compiler"
    click Parser "https://github.com/jaseci-labs/jaseci/blob/main/jac/jaclang/compiler/larkparse/jac_parser.py"
    click Passes "https://github.com/jaseci-labs/jaseci/tree/main/jac/jaclang/compiler/passes"
    click RuntimeLib "https://github.com/jaseci-labs/jaseci/tree/main/jac/jaclang/runtimelib"
    click JC_Server "https://github.com/jaseci-labs/jaseci/tree/main/jac-cloud/jac_cloud/jaseci/routers"
    click DataSources "https://github.com/jaseci-labs/jaseci/tree/main/jac-cloud/jac_cloud/jaseci/datasources"
    click PluginCore "https://github.com/jaseci-labs/jaseci/tree/main/jac-cloud/jac_cloud/plugin"
    click PluginImpl "https://github.com/jaseci-labs/jaseci/tree/main/jac-cloud/jac_cloud/plugin/implementation"
    click SSO "https://github.com/jaseci-labs/jaseci/tree/main/jac-cloud/jac_cloud/jaseci/sso"
    click JC_Entrypoints "https://github.com/jaseci-labs/jaseci/blob/main/jac-cloud/jac_cloud/runner.py"
    click JC_Entrypoints "https://github.com/jaseci-labs/jaseci/blob/main/jac-cloud/jac_cloud/standalone.py"
    click VSC_UI "https://github.com/jaseci-labs/jaseci/tree/main/jac/support/vscode_ext/jac"
    click LSP_Client "https://github.com/jaseci-labs/jaseci/blob/main/jac/support/vscode_ext/jac/src/lsp/client.ts"
    click VS_Ext_Commands "https://github.com/jaseci-labs/jaseci/blob/main/jac/support/vscode_ext/jac/src/extension.ts"
    click VS_Ext_Commands "https://github.com/jaseci-labs/jaseci/tree/main/jac/support/vscode_ext/jac/src/commands"
    click VS_Debugger "https://github.com/jaseci-labs/jaseci/tree/main/jac/support/vscode_ext/jac/src/visual_debugger"
    click VS_Debugger "https://github.com/jaseci-labs/jaseci/blob/main/jac/support/vscode_ext/jac/src/webview/visualDebugger.ts"
    click MT_Core "https://github.com/jaseci-labs/jaseci/blob/main/jac-mtllm/mtllm/plugin.py"
    click MT_Interface "https://github.com/jaseci-labs/jaseci/blob/main/jac-mtllm/mtllm/aott.py"
    click MT_Interface "https://github.com/jaseci-labs/jaseci/blob/main/jac-mtllm/mtllm/types.py"
    click MT_Adapters "https://github.com/jaseci-labs/jaseci/tree/main/jac-mtllm/mtllm/llms"
    click MT_Tools "https://github.com/jaseci-labs/jaseci/tree/main/jac-mtllm/mtllm/tools"

    %% Styles
    classDef frontend fill:#C3DDF9,stroke:#0B6FA4,color:#0B6FA4;
    classDef langcore fill:#D5E8D4,stroke:#82B366,color:#82B366;
    classDef cloud fill:#FFE6CC,stroke:#FFA500,color:#CD8500;
    classDef llm fill:#E1D5E7,stroke:#9673A6,color:#9673A6;
    classDef db fill:#F5F5F5,stroke:#CCCCCC,color:#333333,shape:cylinder;
    classDef external fill:#F0F0F0,stroke:#999999,color:#666666;
```
