# haifengl/smile architecture

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

- Interactive diagram: https://gitdiagram.com/haifengl/smile
- Repository: https://github.com/haifengl/smile

## Overview

1. **What this repo is**
   SMILE is a monorepo for a JVM-based machine learning platform, but it is not one runtime. It contains several deployable/library boundaries: core ML libraries, deep learning/LLM code, NLP, visualization, a REST inference server, a desktop IDE/shell, Spark wrappers, language bindings, and the public website/docs.

2. **Foundation layer: `base/`**
   `base` is the shared substrate. It provides the data model and utilities used across the rest of the repo: `DataFrame`, tuple/vector types, schemas and data types, formula parsing, transforms, I/O readers/writers, math utilities, linear algebra, kernels, distances, random generation, distributions, graphs, nearest-neighbor indexes, wavelets, and small support utilities. If you are drawing dependencies, this is the lowest common library most other modules build on.

3. **Algorithm layer: `core/`**
   `core` is the main classical ML engine on top of `base`. It contains supervised learning, clustering, manifold learning, feature engineering, anomaly detection, association rules, sequence learning, time series, validation, metrics, and hyperparameter optimization. Its internal flow is typically: data structures from `base` → feature preparation/validation → model training → metrics/prediction. Most of the repository’s “traditional ML” APIs live here.

4. **Deep learning and LLM stack: `deep/`**
   `deep` is a separate tensor-and-model stack centered on LibTorch/GPU support. It defines its own tensor, device, activation, layer, loss, optimizer, metric, and model abstractions instead of reusing the `base` tensor code. On top of that sit higher-level packages for LLaMA/chat generation and vision/EfficientNet workflows. Architecturally, this module bridges Java APIs to native PyTorch/Libtorch and CUDA when available.

5. **NLP subsystem: `nlp/`**
   `nlp` is a self-contained text-processing layer: tokenization, sentence/paragraph splitting, normalization, stemming, POS tagging, relevance ranking, collocations, and taxonomy/WordNet-style relationships. It is mostly preprocessing and text-analysis infrastructure rather than a model-serving layer, and it feeds text-oriented applications and examples elsewhere in the repo.

6. **Visualization subsystem: `plot/`**
   `plot` provides two distinct presentation paths. `smile.plot.swing` is an interactive desktop plotting API for charts and scientific visualization, while `smile.plot.vega` generates declarative Vega-Lite specs for browser/Jupyter rendering. This module depends heavily on the data structures in the rest of SMILE, and acts as the presentation boundary for analysis results.

7. **Inference server: `serve/`**
   `serve` is a Quarkus-based server for model inference and chat. It exposes REST resources for generic inference and OpenAI-compatible chat/completions, plus SSE streaming for incremental responses. The server side includes ONNX-backed model loading and a chat service layer, and it also ships a React/Vite web UI under `src/main/webui` for interactive inference and chat. The main external boundary here is HTTP/SSE on the outside and serialized model artifacts on the inside.

8. **Desktop IDE / shell: `studio/`**
   `studio` is the interactive authoring environment. It bundles a desktop UI, notebook support, text editor, workspace management, kernels for Java/Scala/Python/script execution, and CLI entry points such as shell/train/predict/serve. It is the main human-facing runtime for experimentation, with its own resource bundle, notebooks, and launcher scripts under `src/universal`.

9. **Language bindings and cross-language ergonomics**
   `scala/` and `kotlin/` provide idiomatic wrappers over the Java APIs so the same underlying engine can be used with Scala and Kotlin syntax/collections/builders. `clojure/` offers a smaller set of Clojure-facing wrappers. These are API-adaptation layers, not separate engines. `json/` is a separate Scala JSON library used by the ecosystem where lightweight parsing/printing is needed.

10. **Spark integration boundary: `spark/`**
   `spark` adapts SMILE models into Spark ML-compatible components such as transformers, classifiers, and regressors. Its role is to let trained SMILE algorithms participate in distributed Spark DataFrame pipelines, so the architectural boundary is between Spark’s distributed data flow and SMILE’s local model objects.

11. **Common supporting infrastructure**
   The repo is heavily test-driven and ships many resource fixtures: benchmark datasets, sample images, ONNX models, notebooks, and parser inputs. Build and packaging are split across Gradle and SBT, with module-specific conventions in `buildSrc` and CI/release workflows in `.github/workflows`. That matters architecturally because the repo is organized as a multi-module platform with multiple packaging targets, not a single application.

12. **Overall data flow**
   Most workflows start with data ingestion in `base`/`nlp`/`deep`/`serve`, move through feature engineering or tensor/model layers, then go into algorithm modules in `core` or `deep`, and finally emerge through validation/metrics, visualization, serialization, or serving. The primary boundaries are: native-backed math/deep learning vs pure-Java ML, local libraries vs server/desktop runtimes, and core engine vs language-specific façades.

Main entry points: [`base`](https://github.com/haifengl/smile/tree/master/base) (Base), [`core`](https://github.com/haifengl/smile/tree/master/core) (Core ML), [`studio`](https://github.com/haifengl/smile/tree/master/studio) (Studio), [`deep`](https://github.com/haifengl/smile/tree/master/deep) (Deep)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_foundation["Foundation"]
  node_base["Base<br/>core substrate"]
end

subgraph group_classical["Classical ML"]
  node_core["Core ML<br/>classical ML"]
  node_nlp["NLP<br/>text pipeline"]
end

subgraph group_deepstack["Deep Stack"]
  node_deep["Deep<br/>tensor stack"]
end

subgraph group_runtime["Runtimes"]
  node_plot["Plot<br/>viz layer"]
  node_serve["Serve"]
  node_studio["Studio<br/>desktop shell"]
end

subgraph group_bindings["Bindings"]
  node_spark["Spark"]
  node_scala["Scala"]
  node_kotlin["Kotlin"]
  node_clojure["Clojure"]
  node_json["JSON"]
end

subgraph group_platform["Platform"]
  node_website["Website<br/>docs site"]
  node_buildsrc["Build Logic<br/>build conventions"]
  node_project["Project<br/>sbt config"]
  node_bin["Scripts"]
  node_github["CI/CD<br/>workflows<br/>[.github]"]
  node_binder["Binder<br/>notebook env"]
end

node_base -->|"foundation"| node_core
node_base -->|"foundation"| node_nlp
node_base -->|"data feed"| node_plot
node_base -->|"data bridge"| node_spark
node_base -->|"wraps"| node_scala
node_base -->|"wraps"| node_kotlin
node_base -->|"wraps"| node_clojure
node_base -->|"workspace data"| node_studio
node_core -->|"parallel stack"| node_deep
node_core -->|"model export"| node_serve
node_core -->|"model bridge"| node_spark
node_nlp -->|"feeds"| node_core
node_deep -->|"chat/infer"| node_serve
node_deep -->|"docs"| node_website
node_plot -->|"showcase"| node_website
node_studio -->|"launch"| node_serve
node_studio -->|"experiments"| node_core
node_website -->|"explains"| node_base
node_buildsrc -->|"build system"| node_project
node_github -->|"automation"| node_bin
node_binder -->|"notebooks"| node_studio

click node_base "https://github.com/haifengl/smile/tree/master/base"
click node_core "https://github.com/haifengl/smile/tree/master/core"
click node_nlp "https://github.com/haifengl/smile/tree/master/nlp"
click node_plot "https://github.com/haifengl/smile/tree/master/plot"
click node_deep "https://github.com/haifengl/smile/tree/master/deep"
click node_serve "https://github.com/haifengl/smile/tree/master/serve"
click node_studio "https://github.com/haifengl/smile/tree/master/studio"
click node_spark "https://github.com/haifengl/smile/tree/master/spark"
click node_scala "https://github.com/haifengl/smile/tree/master/scala"
click node_kotlin "https://github.com/haifengl/smile/tree/master/kotlin"
click node_clojure "https://github.com/haifengl/smile/tree/master/clojure"
click node_json "https://github.com/haifengl/smile/tree/master/json"
click node_website "https://github.com/haifengl/smile/tree/master/website"
click node_buildsrc "https://github.com/haifengl/smile/tree/master/buildSrc"
click node_project "https://github.com/haifengl/smile/tree/master/project"
click node_bin "https://github.com/haifengl/smile/tree/master/bin"
click node_github "https://github.com/haifengl/smile/blob/master/.github"
click node_binder "https://github.com/haifengl/smile/tree/master/binder"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_base toneBlue
class node_core,node_nlp toneAmber
class node_deep toneMint
class node_plot,node_serve,node_studio toneRose
class node_spark,node_scala,node_kotlin,node_clojure,node_json toneIndigo
class node_website,node_buildsrc,node_project,node_bin,node_github,node_binder toneTeal
```

## Components

### Foundation

Shared data model, math, linear algebra, I/O, and utility substrate.

- [Base](https://github.com/haifengl/smile/tree/master/base): core substrate · Shared data frames, types, math, I/O, linear algebra, graphs, and utilities. · `base`

### Classical ML

Traditional machine learning, feature processing, validation, and model families.

- [Core ML](https://github.com/haifengl/smile/tree/master/core): classical ML · Classical learning algorithms, feature work, validation, metrics, and model APIs. · `core`
- [NLP](https://github.com/haifengl/smile/tree/master/nlp): text pipeline · Tokenization, normalization, tagging, relevance, stemming, and taxonomy support. · `nlp`

### Deep Stack

Native-backed tensor, LLM, and vision components.

- [Deep](https://github.com/haifengl/smile/tree/master/deep): tensor stack · LibTorch-based tensor, layers, optimization, LLM, and vision workflows. · `deep`

### Runtimes

User-facing inference and desktop environments.

- [Plot](https://github.com/haifengl/smile/tree/master/plot): viz layer · Swing charts and Vega-Lite generation for analysis presentation. · `plot`
- [Serve](https://github.com/haifengl/smile/tree/master/serve): inference server · Quarkus REST/SSE inference and chat service with web UI. · `serve`
- [Studio](https://github.com/haifengl/smile/tree/master/studio): desktop shell · Interactive IDE, notebook, kernels, workspace, and CLI runtime. · `studio`

### Bindings

Language façades and integration adapters.

- [Spark](https://github.com/haifengl/smile/tree/master/spark): spark adapter · Spark ML wrappers that bridge distributed pipelines to SMILE models. · `spark`
- [Scala](https://github.com/haifengl/smile/tree/master/scala): scala façade · Idiomatic Scala wrappers and extension APIs over the Java libraries. · `scala`
- [Kotlin](https://github.com/haifengl/smile/tree/master/kotlin): kotlin façade · Kotlin-friendly wrappers for the SMILE API surface. · `kotlin`
- [Clojure](https://github.com/haifengl/smile/tree/master/clojure): clojure façade · Clojure bindings for selected SMILE functionality. · `clojure`
- [JSON](https://github.com/haifengl/smile/tree/master/json): scala json · Standalone Scala JSON parser/printer/serializer library. · `json`

### Platform

Website, build, and release infrastructure around the library modules.

- [Website](https://github.com/haifengl/smile/tree/master/website): docs site · Public documentation and marketing site for the platform. · `website`
- [Build Logic](https://github.com/haifengl/smile/tree/master/buildSrc): build conventions · Shared Gradle/SBT build conventions and packaging logic. · `buildSrc`
- [Project](https://github.com/haifengl/smile/tree/master/project): sbt config · SBT project-level settings, overrides, and plugins. · `project`
- [Scripts](https://github.com/haifengl/smile/tree/master/bin): release scripts · Packaging, setup, publishing, and convenience shell scripts. · `bin`
- [CI/CD](https://github.com/haifengl/smile/blob/master/.github): workflows · Automation for CI, publishing, release, and security checks. · `.github`
- [Binder](https://github.com/haifengl/smile/tree/master/binder): notebook env · Reproducible notebook environment definition for hosted use. · `binder`

## Connections

- Base → Core ML: foundation · Classical ML builds on shared data, math, and I/O primitives.
- Base → NLP: foundation · Text processing uses shared utilities and data structures.
- Base → Plot: data feed · Visualization consumes shared datasets and tabular structures.
- Base → Spark: data bridge · Spark adapters rely on common data-frame and type abstractions.
- Base → Scala: wraps · Scala APIs expose the base library with idiomatic syntax.
- Base → Kotlin: wraps · Kotlin APIs adapt the base and core libraries.
- Base → Clojure: wraps · Clojure bindings sit on top of the shared Java engine.
- Base → Studio: workspace data · Studio uses shared notebook, kernel, and model utilities.
- Core ML → Deep: parallel stack · Deep learning is a separate model stack alongside classical ML.
- Core ML → Serve: model export · Inference server loads and serves trained model artifacts.
- Core ML → Spark: model bridge · Spark wrappers adapt core models into distributed pipelines.
- NLP → Core ML: feeds · Text features and preprocessing feed classical ML workflows.
- Deep → Serve: chat/infer · Serve can expose deep models for inference and chat.
- Deep → Website: docs · Website documents deep learning and LLM workflows.
- Plot → Website: showcase · Website highlights visualization capabilities and examples.
- Studio → Serve: launch · Studio includes entry points to start serving workflows.
- Studio → Core ML: experiments · Studio notebooks and CLI drive training and prediction tasks.
- Website → Base: explains · Docs cover foundational data, math, and I/O concepts.
- Build Logic → Project: build system · Shared build logic works with the SBT project settings.
- CI/CD → Scripts: automation · CI and release workflows exercise repository scripts.
- Binder → Studio: notebooks · Binder provides a hosted environment for Studio-style notebooks.
