# tjake/jlama architecture

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

- Interactive diagram: https://gitdiagram.com/tjake/jlama
- Repository: https://github.com/tjake/jlama

## Overview

##### Main Components
- Core Inference Engine (jlama-core): This is the heart of model support and processing. It handles model loading, operations on tensors, safe tensor operations, prompt processing, and the generation API.
- Native Performance Module (jlama-native): Acts as a performance accelerator wrapping the core functionality—this module offloads heavy numerical operations (SIMD based) to native C code.
- Client & CLI Interface (jlama-cli): Provides a command-line interface for invoking interactions (chat, restapi, complete, quantize, etc.), presenting a user-friendly API to drive the inference methods.
- Distributed Networking Module (jlama-net): Contains components to coordinate distributed inference. It includes a Cluster Coordinator, Worker, gRPC services, as well as OpenAI-compatible REST adaptations.
- Testing & Deployment Infrastructure: This covers the jlamba-tests module for unit and performance testing, Docker/Kubernetes deployment files (docker-compose.yaml, Kubernetes helm charts), and CI/CD workflows (GitHub workflows in .github/).

##### Relationships & Interactions
- The CLI (jlama-cli) acts as the entry point, invoking operations from the Core module. For example, when you run a command, it internally loads models (via jlama-core) and then calls its generate functions.
- The Core Inference Engine loads models and calls the native methods when needed. It uses utility classes from jlama-core (for model prompt support, quantization, etc.) and may hand off heavy numerical operations to the native layer.
- The Native Performance Module (jlama-native) is integrated by linking via Maven (with OS-specific classifiers) and is used by jlama-core for optimized tensor operations.
- For distributed inference, the jlama-net module uses gRPC services (Coordinator, Worker, TopologyService) to connect multiple instances. Data flows from the CLI or Core command to distributed backends via these networking components.
- The deployment part is represented through the Dockerfile and Kubernetes configuration files, which package the entire service as containerized microservices.

##### Architectural Patterns & Design Principles
- Modular design: Components are neatly separated by functionality (CLI, Core, Native, Networking, Testing).
- Layered architecture: The presentation layer (CLI or REST API) sits atop a well-defined service (Core) which in turn leverages native performance layers.
- Distributed systems: Clear separation for coordinator/worker semantics in jlama-net supports distributed model inference.
- Dependency injection and command pattern: The CLI submodule includes several “Command” classes to handle specific user commands (chat, complete, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        CLI["Jlama CLI (jlama-cli)"]:::frontend
    end

    %% Application Layer
    subgraph "Application Layer"
        CORE["Jlama Core Inference Engine (jlama-core)"]:::core
        NATIVE["Jlama Native (Performance Layer) (jlama-native)"]:::native
    end

    %% Distributed Inference
    subgraph "Distributed Inference"
        NET["Jlama Distributed Network (jlama-net)"]:::network
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        TESTING["Testing Artifacts (jlama-tests)"]:::infra
        DOCKER["Deployment Files (Dockerfile & docker-compose.yaml)"]:::infra
        KUBE["Kubernetes Configurations (kubernetes/)"]:::infra
    end

    %% Main interactions
    CLI -->|"invokes"| CORE
    CORE -->|"delegatesHeavyWork"| NATIVE
    CLI -->|"triggersDistributed"| NET
    CORE -->|"callsRemote"| NET

    %% Infrastructure feeding into system modules (dotted arrows)
    TESTING -.-> CLI
    TESTING -.-> CORE
    TESTING -.-> NATIVE
    TESTING -.-> NET

    DOCKER -.-> CLI
    DOCKER -.-> CORE
    DOCKER -.-> NATIVE
    DOCKER -.-> NET

    KUBE -.-> CLI
    KUBE -.-> CORE
    KUBE -.-> NATIVE
    KUBE -.-> NET

    %% Click Events
    click CLI "https://github.com/tjake/jlama/tree/main/jlama-cli/"
    click CORE "https://github.com/tjake/jlama/tree/main/jlama-core/"
    click NATIVE "https://github.com/tjake/jlama/tree/main/jlama-native/"
    click NET "https://github.com/tjake/jlama/tree/main/jlama-net/"
    click TESTING "https://github.com/tjake/jlama/tree/main/jlama-tests/"
    click DOCKER "https://github.com/tjake/jlama/tree/main/Dockerfile"
    click KUBE "https://github.com/tjake/jlama/tree/main/kubernetes/"

    %% Styling Classes
    classDef frontend fill:#f7d6e0,stroke:#000,stroke-width:2px;
    classDef core fill:#d0e4fe,stroke:#000,stroke-width:2px;
    classDef native fill:#d0fdd6,stroke:#000,stroke-width:2px;
    classDef network fill:#ffe6a7,stroke:#000,stroke-width:2px;
    classDef infra fill:#fdd4ab,stroke:#000,stroke-width:2px;
```
