# avarok-cybersecurity/atlas architecture

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

- Interactive diagram: https://gitdiagram.com/avarok-cybersecurity/atlas
- Repository: https://github.com/avarok-cybersecurity/atlas

## Overview

#### Purpose and entry points
Atlas is a Rust LLM inference monorepo: it serves local, hardware-tuned model inference through OpenAI-, Anthropic-, and Responses-compatible HTTP APIs. The primary executable is `spark-server`, entered at `crates/spark-server/src/main.rs`; CLI serve configuration is defined under `crates/spark-server/src/cli/serve_args.rs`. A separate translation-oriented CLI exists at `crates/spark-nllb/src/bin/nllb-translate.rs`.

#### Server API and request normalization
`spark-server` owns HTTP lifecycle, authentication, rate limiting, request/session state, streaming, and protocol translation. OpenAI and Anthropic wire formats are lowered into a shared internal request/response representation, isolating inference from external API compatibility.
- `crates/spark-server/src/api/mod.rs`
- `crates/spark-server/src/openai/to_ir.rs`
- `crates/spark-server/src/anthropic/to_ir.rs`
- `crates/spark-server/src/ir/request.rs`

#### Startup, model resolution, and construction
The server’s staged startup builds app state, resolves a model, initializes tokenizer/runtime/KV cache/topology, loads weights, and constructs the executable model. Model-family configuration parsing and factory dispatch are separate from per-family weight loaders, allowing new model support without changing serving or scheduling.
- `crates/spark-server/src/main_modules/serve_phases/mod.rs`
- `crates/spark-server/src/model_resolver.rs`
- `crates/spark-model/src/factory.rs`
- `crates/spark-model/src/weight_loader/mod.rs`
- `crates/atlas-core/src/config/parsers/mod.rs`

#### Scheduling and generation control
The scheduler is the central control plane after admission: it manages sequence lifecycle, batched prefill and decode, token emission, sampling/logprobs, speculative/MTP verification, rollback, and per-request grammar/logit constraints. Requests flow API → tokenizer/preparation → scheduler → model forward steps → streamed or blocking API responses.
- `crates/spark-server/src/scheduler/mod.rs`
- `crates/spark-server/src/scheduler/phase_start_prefills.rs`
- `crates/spark-server/src/scheduler/decode_step.rs`
- `crates/spark-server/src/scheduler/spec_step.rs`

#### Model execution and architectural variants
`spark-model` implements the generic model engine and composes transformer layers from attention, SSM/GDN or Mamba paths, dense FFNs, routed/shared MoE, vision encoders, and MTP heads. It separates prefill from decode and keeps model-specific loading/mapping at the weight boundary. Tensor-parallel sharding and expert-parallel dispatch are model-level concerns.
- `crates/spark-model/src/engine.rs`
- `crates/spark-model/src/layer/transformer_layer.rs`
- `crates/spark-model/src/layers/qwen3_attention/mod.rs`
- `crates/spark-model/src/layers/moe/mod.rs`
- `crates/spark-model/src/tp_shard.rs`

#### Runtime, kernels, and hardware boundary
The runtime provides GPU buffers, launches, paged KV cache, sampling, and backend-specific CUDA or Metal implementations. Build-time kernel discovery/compilation bridges Rust dispatch to hardware/model/quant-specific CUDA or Metal sources. Current kernel inventory covers GB10, Strix/Strix HIP, and Metal targets; CUDA integrations include cuBLASLt, CUTLASS, and FlashInfer.
- `crates/spark-runtime/src/gpu.rs`
- `crates/spark-runtime/src/cuda_backend.rs`
- `crates/spark-runtime/src/metal_backend.rs`
- `crates/atlas-kernels/build.rs`
- `kernels/gb10/common/KERNEL.toml`

#### Stateful memory, distributed execution, and constrained output
KV state is paged and prefix-cached in runtime; storage extends this to NVMe/io_uring, mmap, and RDMA-backed paging/swap for long contexts. NCCL communication supports multi-GPU collectives/expert parallelism, while `xgrammar` compiles schemas/grammars into token masks consumed by server grammar and scheduler logit-processing paths.
- `crates/spark-runtime/src/kv_cache/paged_impl.rs`
- `crates/spark-runtime/src/prefix_cache.rs`
- `crates/spark-storage/src/kv_paging/backend.rs`
- `crates/spark-storage/src/high_speed_swap.rs`
- `crates/spark-comm/src/nccl_backend.rs`
- `crates/xgrammar/src/api/compiler.rs`

Main entry points: [`crates/spark-server/src/scheduler/mod.rs`](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/scheduler/mod.rs) (Scheduler), [`crates/spark-model/src/engine.rs`](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/engine.rs) (Model engine), [`crates/spark-server/src/api/mod.rs`](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/api/mod.rs) (HTTP API), [`crates/spark-server/src/main.rs`](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/main.rs) (spark-server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_server["Serving"]
  node_server_main["spark-server<br/>Rust executable<br/>[main.rs]"]
  node_serve_args["Serve CLI<br/>CLI configuration<br/>[serve_args.rs]"]
  node_startup["Serve phases<br/>startup pipeline<br/>[mod.rs]"]
  node_api["HTTP API<br/>API lifecycle<br/>[mod.rs]"]
  node_openai_ir["OpenAI lowering<br/>protocol adapter<br/>[to_ir.rs]"]
  node_anthropic_ir["Anthropic lowering<br/>protocol adapter<br/>[to_ir.rs]"]
  node_request_ir["Request IR<br/>internal contract<br/>[request.rs]"]
  node_scheduler{{"Scheduler<br/>generation control<br/>[mod.rs]"}}
  node_prefill["Prefill phase<br/>scheduler stage"]
  node_decode["Decode and spec<br/>scheduler stage<br/>[decode_step.rs]"]
end

subgraph group_model["Model execution"]
  node_model_resolver["Model resolver<br/>model selection<br/>[model_resolver.rs]"]
  node_model_config["Model config parsers<br/>family configuration<br/>[mod.rs]"]
  node_model_factory["Model factory<br/>model construction<br/>[factory.rs]"]
  node_weight_loader["Weight loaders<br/>weight boundary<br/>[mod.rs]"]
  node_model_engine{{"Model engine<br/>forward execution<br/>[engine.rs]"}}
  node_transformer["Transformer layers<br/>layer composition"]
  node_moe["MoE layers<br/>expert routing<br/>[mod.rs]"]
end

subgraph group_platform["Runtime platform"]
  node_runtime["GPU runtime<br/>execution runtime<br/>[gpu.rs]"]
  node_kv_cache[("Paged KV cache<br/>stateful memory<br/>[paged_impl.rs]")]
  node_storage[("KV storage paging<br/>memory tiering<br/>[backend.rs]")]
  node_nccl["NCCL backend<br/>distributed collectives<br/>[nccl_backend.rs]"]
  node_grammar["Grammar compiler<br/>constraint compiler<br/>[compiler.rs]"]
  node_kernels["Kernel build<br/>hardware kernel bridge<br/>[build.rs]"]
end

node_serve_args -->|"configures"| node_server_main
node_server_main -->|"starts"| node_startup
node_server_main -->|"serves"| node_api
node_startup -->|"resolves model"| node_model_resolver
node_model_resolver -->|"parses family config"| node_model_config
node_model_resolver -->|"selects"| node_model_factory
node_model_factory -->|"loads weights"| node_weight_loader
node_model_factory -->|"constructs"| node_model_engine
node_openai_ir -->|"normalizes"| node_request_ir
node_anthropic_ir -->|"normalizes"| node_request_ir
node_api -->|"OpenAI requests"| node_openai_ir
node_api -->|"Anthropic requests"| node_anthropic_ir
node_request_ir -->|"admitted requests"| node_scheduler
node_scheduler -->|"batches prompts"| node_prefill
node_scheduler -->|"generates tokens"| node_decode
node_prefill -->|"prefill forward"| node_model_engine
node_decode -->|"decode forward"| node_model_engine
node_model_engine -->|"executes layers"| node_transformer
node_transformer -->|"routes experts"| node_moe
node_model_engine -->|"launches tensors"| node_runtime
node_scheduler -->|"manages sequence state"| node_kv_cache
node_kv_cache -->|"pages and swaps"| node_storage
node_model_engine -->|"parallel collectives"| node_nccl
node_scheduler -->|"applies token masks"| node_grammar
node_runtime -->|"uses compiled kernels"| node_kernels
node_scheduler -->|"streamed or blocking response"| node_api

click node_server_main "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/main.rs"
click node_serve_args "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/cli/serve_args.rs"
click node_startup "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/main_modules/serve_phases/mod.rs"
click node_api "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/api/mod.rs"
click node_openai_ir "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/openai/to_ir.rs"
click node_anthropic_ir "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/anthropic/to_ir.rs"
click node_request_ir "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/ir/request.rs"
click node_scheduler "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/scheduler/mod.rs"
click node_prefill "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/scheduler/phase_start_prefills.rs"
click node_decode "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/scheduler/decode_step.rs"
click node_model_resolver "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/model_resolver.rs"
click node_model_config "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/atlas-core/src/config/parsers/mod.rs"
click node_model_factory "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/factory.rs"
click node_weight_loader "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/weight_loader/mod.rs"
click node_model_engine "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/engine.rs"
click node_transformer "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/layer/transformer_layer.rs"
click node_moe "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/layers/moe/mod.rs"
click node_runtime "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-runtime/src/gpu.rs"
click node_kv_cache "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-runtime/src/kv_cache/paged_impl.rs"
click node_storage "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-storage/src/kv_paging/backend.rs"
click node_nccl "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-comm/src/nccl_backend.rs"
click node_grammar "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/xgrammar/src/api/compiler.rs"
click node_kernels "https://github.com/avarok-cybersecurity/atlas/blob/main/crates/atlas-kernels/build.rs"

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_server_main,node_serve_args,node_startup,node_api,node_openai_ir,node_anthropic_ir,node_request_ir,node_scheduler,node_prefill,node_decode toneBlue
class node_model_resolver,node_model_config,node_model_factory,node_weight_loader,node_model_engine,node_transformer,node_moe toneAmber
class node_runtime,node_kv_cache,node_storage,node_nccl,node_grammar,node_kernels toneMint
```

## Components

### Serving

HTTP serving, normalization, startup, and generation control.

- [spark-server](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/main.rs): Rust executable · Primary inference server entry point. · `crates/spark-server/src/main.rs`
- [Serve CLI](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/cli/serve_args.rs): CLI configuration · `crates/spark-server/src/cli/serve_args.rs`
- [Serve phases](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/main_modules/serve_phases/mod.rs): startup pipeline · Builds state and initializes executable inference. · `crates/spark-server/src/main_modules/serve_phases/mod.rs`
- [HTTP API](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/api/mod.rs): API lifecycle · Owns authentication, admission, sessions, and response streaming. · `crates/spark-server/src/api/mod.rs`
- [OpenAI lowering](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/openai/to_ir.rs): protocol adapter · `crates/spark-server/src/openai/to_ir.rs`
- [Anthropic lowering](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/anthropic/to_ir.rs): protocol adapter · `crates/spark-server/src/anthropic/to_ir.rs`
- [Request IR](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/ir/request.rs): internal contract · Shared inference request and response representation. · `crates/spark-server/src/ir/request.rs`
- [Scheduler](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/scheduler/mod.rs): generation control · Runs sequence lifecycle, batching, decode, sampling, and token emission. · `crates/spark-server/src/scheduler/mod.rs`
- [Prefill phase](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/scheduler/phase_start_prefills.rs): scheduler stage · `crates/spark-server/src/scheduler/phase_start_prefills.rs`
- [Decode and spec](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/scheduler/decode_step.rs): scheduler stage · Per-token decode, speculative verification, and rollback. · `crates/spark-server/src/scheduler/decode_step.rs`

### Model execution

Model construction and transformer execution.

- [Model resolver](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-server/src/model_resolver.rs): model selection · `crates/spark-server/src/model_resolver.rs`
- [Model config parsers](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/atlas-core/src/config/parsers/mod.rs): family configuration · `crates/atlas-core/src/config/parsers/mod.rs`
- [Model factory](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/factory.rs): model construction · Dispatches model-family construction and loading. · `crates/spark-model/src/factory.rs`
- [Weight loaders](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/weight_loader/mod.rs): weight boundary · Per-family loading and tensor mapping. · `crates/spark-model/src/weight_loader/mod.rs`
- [Model engine](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/engine.rs): forward execution · Separates prefill and decode model execution. · `crates/spark-model/src/engine.rs`
- [Transformer layers](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/layer/transformer_layer.rs): layer composition · Composes attention, FFN, SSM, MoE, vision, and MTP variants. · `crates/spark-model/src/layer/transformer_layer.rs`
- [MoE layers](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-model/src/layers/moe/mod.rs): expert routing · Routed and shared expert execution. · `crates/spark-model/src/layers/moe/mod.rs`

### Runtime platform

Hardware execution, state, storage, and distributed support.

- [GPU runtime](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-runtime/src/gpu.rs): execution runtime · Provides buffers, launches, sampling, and backend dispatch. · `crates/spark-runtime/src/gpu.rs`
- [Paged KV cache](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-runtime/src/kv_cache/paged_impl.rs): stateful memory · Paged attention state for active sequences. · `crates/spark-runtime/src/kv_cache/paged_impl.rs`
- [KV storage paging](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-storage/src/kv_paging/backend.rs): memory tiering · Extends KV paging to persistent and remote storage. · `crates/spark-storage/src/kv_paging/backend.rs`
- [NCCL backend](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/spark-comm/src/nccl_backend.rs): distributed collectives · Multi-GPU and expert-parallel communication. · `crates/spark-comm/src/nccl_backend.rs`
- [Grammar compiler](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/xgrammar/src/api/compiler.rs): constraint compiler · Compiles schemas and grammars into token masks. · `crates/xgrammar/src/api/compiler.rs`
- [Kernel build](https://github.com/avarok-cybersecurity/atlas/blob/main/crates/atlas-kernels/build.rs): hardware kernel bridge · Discovers and compiles target-specific CUDA and Metal kernels. · `crates/atlas-kernels/build.rs`

## Connections

- Serve CLI → spark-server: configures
- spark-server → Serve phases: starts
- spark-server → HTTP API: serves
- Serve phases → Model resolver: resolves model
- Model resolver → Model config parsers: parses family config
- Model resolver → Model factory: selects
- Model factory → Weight loaders: loads weights
- Model factory → Model engine: constructs
- OpenAI lowering → Request IR: normalizes
- Anthropic lowering → Request IR: normalizes
- HTTP API → OpenAI lowering: OpenAI requests
- HTTP API → Anthropic lowering: Anthropic requests
- Request IR → Scheduler: admitted requests
- Scheduler → Prefill phase: batches prompts
- Scheduler → Decode and spec: generates tokens
- Prefill phase → Model engine: prefill forward
- Decode and spec → Model engine: decode forward
- Model engine → Transformer layers: executes layers
- Transformer layers → MoE layers: routes experts
- Model engine → GPU runtime: launches tensors
- Scheduler → Paged KV cache: manages sequence state
- Paged KV cache → KV storage paging: pages and swaps
- Model engine → NCCL backend: parallel collectives
- Scheduler → Grammar compiler: applies token masks
- GPU runtime → Kernel build: uses compiled kernels
- Scheduler → HTTP API: streamed or blocking response
