# moses-smt/mosesdecoder architecture

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

- Interactive diagram: https://gitdiagram.com/moses-smt/mosesdecoder
- Repository: https://github.com/moses-smt/mosesdecoder

## Overview

##### Project type and purpose
- This is “Moses,” a large open-source toolkit for statistical machine translation (SMT). It provides:
- A core phrase-based and syntax-based translation decoder (moses/ and moses2/ directories)
- Tools for phrase-table extraction (OnDiskPt/, phrase-extract/, probingpt/)
- Hyperparameter tuning (mert/)
- Language model integration (lm/ and util/, taken from KenLM)
- A server component for remote translation (moses/server/, moses2/server/)
- Many helper scripts (scripts/), examples and regression tests (regression-testing/).

##### File structure
- Top-level executables & libraries
- moses-cmd/ and moses/ (core C++ decoder, search, feature functions, I/O wrappers)
- moses2/ (next-gen codebase)
- mert/ (parameter tuning framework)
- lm/ & util/ (language model building & querying, borrowed from KenLM)
- phrase-extract/, probingpt/, OnDiskPt/ (vocabulary and phrase‐table construction & on‐disk querying)
- server/ and xmlrpc-c config (remote API server)
- Build and configuration
- Jamroot, Jamfile, .travis.yml, azure-pipelines.yml (Boost.Build)
- CMakeLists.txt in some submodules
- Contrib/ and scripts/
- Optional tools, pipelines and examples in Python, Perl, shell, plus Docker files.

##### Insights from README
- Build with Boost.Build (“bjam”) and dependencies: Boost, CMPh, xmlrpc-c
- Highlights two external codebases: bjam-files (Boost) and util+lm (KenLM)
- Points to documentation, mailing list, CI pipelines.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User/Script Layer
    subgraph "User & Script Layer"
        Scripts["Scripts & Pipelines"]:::script
    end
    click Scripts "https://github.com/moses-smt/mosesdecoder/tree/master/scripts/"

    %% CLI Tools Layer
    subgraph "CLI Tools"
        MosesCmd["CLI Frontend - moses"]:::cli
        Moses2Cmd["CLI Frontend - moses2"]:::cli
        MERT["Hyperparameter Tuning (MERT)"]:::cli
        PhraseExtract["Phrase-Extract Tool"]:::cli
        OnDiskPtTool["OnDiskPt Query Tool"]:::cli
        ProbingPtTool["ProbingPt Tool"]:::cli
    end
    click MosesCmd "https://github.com/moses-smt/mosesdecoder/tree/master/moses-cmd/"
    click Moses2Cmd "https://github.com/moses-smt/mosesdecoder/tree/master/moses2/"
    click MERT "https://github.com/moses-smt/mosesdecoder/tree/master/mert/"
    click PhraseExtract "https://github.com/moses-smt/mosesdecoder/tree/master/phrase-extract/"
    click OnDiskPtTool "https://github.com/moses-smt/mosesdecoder/tree/master/OnDiskPt/"
    click ProbingPtTool "https://github.com/moses-smt/mosesdecoder/tree/master/probingpt/"

    %% Engine Layer
    subgraph "Core Engine"
        CoreV1["Core Decoder (moses/)"]:::core
        CoreV2["Next-gen Decoder (moses2/)"]:::core
        Manager["Manager"]:::core
        Search["Search Module"]:::core
        FeatureFactory["FeatureFunction Factory"]:::core
        TMFactory["TranslationModel Backends"]:::core
        LMFactory["LanguageModel Interface"]:::core
        IOWrapper["IOWrapper"]:::core
    end
    click CoreV1 "https://github.com/moses-smt/mosesdecoder/tree/master/moses/"
    click CoreV2 "https://github.com/moses-smt/mosesdecoder/tree/master/moses2/"

    %% Server Layer
    subgraph "Server Components"
        ServerV1["Moses XMLRPC Server"]:::external
        ServerV2["Moses2 XMLRPC Server"]:::external
    end
    click ServerV1 "https://github.com/moses-smt/mosesdecoder/tree/master/moses/server/"
    click ServerV2 "https://github.com/moses-smt/mosesdecoder/tree/master/moses2/server/"

    %% Data Layer
    subgraph "Data Stores & Formats"
        PhraseTable["Phrase-Table Files"]:::data
        LMFiles["Language Model Files"]:::data
    end

    %% External Dependencies
    subgraph "External Dependencies"
        KenLM["KenLM (lm/, util/)"]:::external
        BoostBuild["Build System (Boost.Build/CMake)"]:::external
        XMLRPC["xmlrpc-c Library"]:::external
    end
    click KenLM "https://github.com/moses-smt/mosesdecoder/tree/master/lm/"
    click KenLM "https://github.com/moses-smt/mosesdecoder/tree/master/util/"

    %% Regression Testing
    Regression["Regression-Testing Harness"]:::script
    click Regression "https://github.com/moses-smt/mosesdecoder/tree/master/regression-testing/"

    %% Connections
    Scripts -->|invokes| MosesCmd
    Scripts -->|invokes| Moses2Cmd
    Scripts -->|runs| PhraseExtract
    Scripts -->|runs| OnDiskPtTool
    Scripts -->|runs| ProbingPtTool
    Scripts -->|runs| MERT

    MosesCmd -->|calls| CoreV1
    Moses2Cmd -->|calls| CoreV2
    PhraseExtract -->|generates| PhraseTable
    OnDiskPtTool -->|queries| PhraseTable
    ProbingPtTool -->|probes| PhraseTable
    MERT -->|optimizes via| CoreV1

    CoreV1 -->|manages via| Manager
    CoreV2 -->|manages via| Manager
    Manager -->|executes| Search
    Search -->|requests| FeatureFactory
    FeatureFactory -->|fetches from| TMFactory
    FeatureFactory -->|fetches from| LMFactory
    TMFactory -->|reads| PhraseTable
    LMFactory -->|queries| LMFiles
    LMFactory -->|uses| KenLM
    IOWrapper -->|writes| LMFiles
    CoreV1 -->|wraps with| ServerV1
    CoreV2 -->|wraps with| ServerV2

    ServerV1 -->|uses| XMLRPC
    ServerV2 -->|uses| XMLRPC
    CoreV1 -->|built by| BoostBuild
    CoreV2 -->|built by| BoostBuild
    Regression -->|tests| CoreV1
    Regression -->|tests| CoreV2

    %% Styles
    classDef core fill:#D0E8FF,stroke:#0066CC,color:#003366
    classDef cli fill:#E8F4D0,stroke:#66AA00,color:#336600
    classDef data fill:#D0FFD8,stroke:#00AA44,color:#006622
    classDef external fill:#FFE0B2,stroke:#CC6600,color:#663300
    classDef script fill:#F0F0F0,stroke:#888888,color:#333333
```
