# xberg-io/xberg architecture

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

- Interactive diagram: https://gitdiagram.com/xberg-io/xberg
- Repository: https://github.com/xberg-io/xberg

## Overview

Xberg is a cross-language document-intelligence engine. Users submit files or URLs through its CLI, API, or language bindings; the engine detects and extracts content, optionally enriching it with OCR, layout analysis, transcription, embeddings, and other capabilities, then returns structured results. The graph emphasizes these documented product stages and the sampled PDF/OCR paths. Many subsystem links are documented rather than verified in source excerpts, so those edges cite the README; uncertain runtime wiring is omitted.

Main entry points: [`crates/xberg/src`](https://github.com/xberg-io/xberg/tree/main/crates/xberg/src) (Extraction Engine), [`crates/xberg/src/extractors/pdf/ocr/pipeline.rs`](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/extractors/pdf/ocr/pipeline.rs) (PDF OCR), [`packages`](https://github.com/xberg-io/xberg/tree/main/packages) (Language Bindings), [`crates/xberg-cli/src/main.rs`](https://github.com/xberg-io/xberg/blob/main/crates/xberg-cli/src/main.rs) (CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_cli["CLI<br/>[main.rs]"]
end

subgraph group_extraction["Document Extraction"]
  node_core["Extraction Engine"]
  node_pdfstructure["PDF Structure<br/>[pipeline.rs]"]
  node_pdfocr["PDF OCR<br/>[pipeline.rs]"]
end

subgraph group_enrichment["AI Enrichment"]
  node_layout["Layout Detection<br/>[engine.rs]"]
  node_ocrmodels["Candle OCR<br/>[engine.rs]"]
  node_transcription["Transcription<br/>[engine.rs]"]
  node_embeddings["Embeddings<br/>[engine.rs]"]
  node_sparse["Sparse Embeddings<br/>[engine.rs]"]
  node_late["Late Interaction<br/>[engine.rs]"]
  node_reranking["Reranking<br/>[engine.rs]"]
  node_ner["Named Entities<br/>[engine.rs]"]
  node_redaction["Text Redaction<br/>[engine.rs]"]
end

subgraph group_results["Results and Types"]
  node_resulttypes["Document Types<br/>[internal.rs]"]
  node_metadata["Metadata<br/>[metadata.rs]"]
  node_pages["Page Content<br/>[page.rs]"]
end

subgraph group_extensions["Bindings and Integrations"]
  node_bindings["Language Bindings"]
  node_surrealdb["SurrealDB Pipeline<br/>[pipeline.py]"]
  node_txtai["txtai Pipeline<br/>[pipeline.py]"]
end

node_user(("User"))
node_output["Extracted Content"]

node_user -->|"submits documents"| node_cli
node_cli -.->|"invokes extraction"| node_core
node_core -->|"extracts PDF structure"| node_pdfstructure
node_core -->|"runs OCR"| node_pdfocr
node_pdfocr -->|"builds document"| node_resulttypes
node_pdfocr -->|"uses layout"| node_layout
node_pdfocr -->|"selects OCR backend"| node_ocrmodels
node_core -->|"transcribes media"| node_transcription
node_core -->|"generates embeddings"| node_embeddings
node_core -->|"generates sparse vectors"| node_sparse
node_core -->|"computes late interaction"| node_late
node_core -->|"reranks results"| node_reranking
node_core -->|"extracts entities"| node_ner
node_core -->|"redacts text"| node_redaction
node_core -->|"produces metadata"| node_metadata
node_core -->|"produces page content"| node_pages
node_resulttypes -->|"renders content"| node_output
node_bindings -->|"calls engine"| node_core
node_surrealdb -->|"uses Python API"| node_bindings
node_txtai -->|"uses Python API"| node_bindings

click node_cli "https://github.com/xberg-io/xberg/blob/main/crates/xberg-cli/src/main.rs"
click node_core "https://github.com/xberg-io/xberg/tree/main/crates/xberg/src"
click node_pdfstructure "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/pdf/structure/pipeline.rs"
click node_pdfocr "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/extractors/pdf/ocr/pipeline.rs"
click node_layout "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/layout/engine.rs"
click node_ocrmodels "https://github.com/xberg-io/xberg/blob/main/crates/xberg-candle-ocr/src/models/deepseek_ocr/engine.rs"
click node_transcription "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/transcription/engine.rs"
click node_embeddings "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/embeddings/engine.rs"
click node_sparse "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/sparse_embeddings/engine.rs"
click node_late "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/late_interaction/engine.rs"
click node_reranking "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/reranking/engine.rs"
click node_ner "https://github.com/xberg-io/xberg/blob/main/crates/xberg-gliner/src/engine.rs"
click node_redaction "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/text/redaction/engine.rs"
click node_resulttypes "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/types/internal.rs"
click node_metadata "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/types/metadata.rs"
click node_pages "https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/types/page.rs"
click node_bindings "https://github.com/xberg-io/xberg/tree/main/packages"
click node_surrealdb "https://github.com/xberg-io/xberg/blob/main/integrations/python/surrealdb/src/surrealdb_xberg/pipeline.py"
click node_txtai "https://github.com/xberg-io/xberg/blob/main/integrations/python/txtai/src/txtai_xberg/pipeline.py"

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_cli,node_user toneBlue
class node_core,node_pdfstructure,node_pdfocr toneAmber
class node_layout,node_ocrmodels,node_transcription,node_embeddings,node_sparse,node_late,node_reranking,node_ner,node_redaction toneMint
class node_resulttypes,node_metadata,node_pages toneRose
class node_bindings,node_surrealdb,node_txtai,node_output toneIndigo
```

## Components

### User Interfaces

- [CLI](https://github.com/xberg-io/xberg/blob/main/crates/xberg-cli/src/main.rs): `crates/xberg-cli/src/main.rs`

### Document Extraction

- [Extraction Engine](https://github.com/xberg-io/xberg/tree/main/crates/xberg/src): `crates/xberg/src`
- [PDF Structure](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/pdf/structure/pipeline.rs): `crates/xberg/src/pdf/structure/pipeline.rs`
- [PDF OCR](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/extractors/pdf/ocr/pipeline.rs): `crates/xberg/src/extractors/pdf/ocr/pipeline.rs`

### AI Enrichment

- [Layout Detection](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/layout/engine.rs): `crates/xberg/src/layout/engine.rs`
- [Candle OCR](https://github.com/xberg-io/xberg/blob/main/crates/xberg-candle-ocr/src/models/deepseek_ocr/engine.rs): `crates/xberg-candle-ocr/src/models/deepseek_ocr/engine.rs`
- [Transcription](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/transcription/engine.rs): `crates/xberg/src/transcription/engine.rs`
- [Embeddings](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/embeddings/engine.rs): `crates/xberg/src/embeddings/engine.rs`
- [Sparse Embeddings](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/sparse_embeddings/engine.rs): `crates/xberg/src/sparse_embeddings/engine.rs`
- [Late Interaction](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/late_interaction/engine.rs): `crates/xberg/src/late_interaction/engine.rs`
- [Reranking](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/reranking/engine.rs): `crates/xberg/src/reranking/engine.rs`
- [Named Entities](https://github.com/xberg-io/xberg/blob/main/crates/xberg-gliner/src/engine.rs): `crates/xberg-gliner/src/engine.rs`
- [Text Redaction](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/text/redaction/engine.rs): `crates/xberg/src/text/redaction/engine.rs`

### Results and Types

- [Document Types](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/types/internal.rs): `crates/xberg/src/types/internal.rs`
- [Metadata](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/types/metadata.rs): `crates/xberg/src/types/metadata.rs`
- [Page Content](https://github.com/xberg-io/xberg/blob/main/crates/xberg/src/types/page.rs): `crates/xberg/src/types/page.rs`

### Bindings and Integrations

- [Language Bindings](https://github.com/xberg-io/xberg/tree/main/packages): `packages`
- [SurrealDB Pipeline](https://github.com/xberg-io/xberg/blob/main/integrations/python/surrealdb/src/surrealdb_xberg/pipeline.py): `integrations/python/surrealdb/src/surrealdb_xberg/pipeline.py`
- [txtai Pipeline](https://github.com/xberg-io/xberg/blob/main/integrations/python/txtai/src/txtai_xberg/pipeline.py): `integrations/python/txtai/src/txtai_xberg/pipeline.py`

### Other components

- **User**
- **Extracted Content**

## Connections

- User → CLI: submits documents
- CLI → Extraction Engine: invokes extraction
- Extraction Engine → PDF Structure: extracts PDF structure (evidence: `crates/xberg/src/pdf/structure/pipeline.rs`)
- Extraction Engine → PDF OCR: runs OCR (evidence: `crates/xberg/src/extractors/pdf/ocr/pipeline.rs`)
- PDF OCR → Document Types: builds document (evidence: `crates/xberg/src/extractors/pdf/ocr/pipeline.rs`)
- PDF OCR → Layout Detection: uses layout (evidence: `crates/xberg/src/extractors/pdf/ocr/pipeline.rs`)
- PDF OCR → Candle OCR: selects OCR backend
- Extraction Engine → Transcription: transcribes media (evidence: `crates/xberg/src/transcription/engine.rs`)
- Extraction Engine → Embeddings: generates embeddings
- Extraction Engine → Sparse Embeddings: generates sparse vectors
- Extraction Engine → Late Interaction: computes late interaction
- Extraction Engine → Reranking: reranks results
- Extraction Engine → Named Entities: extracts entities
- Extraction Engine → Text Redaction: redacts text (evidence: `crates/xberg/src/text/redaction/engine.rs`)
- Extraction Engine → Metadata: produces metadata (evidence: `crates/xberg/src/text/redaction/engine.rs`)
- Extraction Engine → Page Content: produces page content (evidence: `crates/xberg/src/extractors/pdf/ocr/pipeline.rs`)
- Document Types → Extracted Content: renders content
- Language Bindings → Extraction Engine: calls engine
- SurrealDB Pipeline → Language Bindings: uses Python API (evidence: `integrations/python/surrealdb/src/surrealdb_xberg/pipeline.py`)
- txtai Pipeline → Language Bindings: uses Python API (evidence: `integrations/python/txtai/src/txtai_xberg/pipeline.py`)
