# nx-ai/tirex-2 architecture

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

- Interactive diagram: https://gitdiagram.com/nx-ai/tirex-2
- Repository: https://github.com/nx-ai/tirex-2

## Overview

TiRex-2 is a pretrained multivariate time-series forecasting model. Users provide target history and optional past or future-known covariates; the forecasting API prepares and batches inputs, the model predicts quantile forecasts, and adapters or plotting present results. The repository also provides an inference service with HTTP/MCP and optional MQTT interfaces. Core model stages are represented at the level supported by the excerpts and SOURCE INDEX; unsampled implementation details are not inferred.

Main entry points: [`src/tirex2/model/tirex2.py`](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/tirex2.py) (TiRex2 backbone), [`src/tirex2/api_adapter/forecast.py`](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/forecast.py) (Forecast API), [`src/tirex2/model/component/bi_xlstm.py`](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/bi_xlstm.py) (Bi-xLSTM mixer), [`inference/app/main.py`](https://github.com/nx-ai/tirex-2/blob/main/inference/app/main.py) (Service startup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Forecast APIs"]
  node_forecast_api["Forecast API<br/>[forecast.py]"]
  node_series_type["Series inputs<br/>[types.py]"]
  node_dataframe_adapter["DataFrame adapter"]
  node_gluonts_adapter["GluonTS adapter<br/>[gluon.py]"]
  node_standard_adapter["Standard adapter"]
  node_demo["Demo data<br/>[demo.py]"]
  node_plotting["Forecast plots<br/>[plotting.py]"]
end

subgraph group_model["Forecast Model"]
  node_backbone["TiRex2 backbone<br/>[tirex2.py]"]
  node_postprocessor["Input/output processing<br/>[postprocessor.py]"]
  node_tokenizer["Patch tokenizer<br/>[patch_tokenizer.py]"]
  node_scaler["Series scaling<br/>[scaler.py]"]
end

subgraph group_components["Model Components"]
  node_mixing_block["Variate mixing"]
  node_attention["Attention mixer<br/>[attention_block.py]"]
  node_bixlstm["Bi-xLSTM mixer<br/>[bi_xlstm.py]"]
  node_slstm["FlashRNN sLSTM<br/>[flashrnn_slstm.py]"]
  node_mlstm["mLSTM layer<br/>[mlstm_block.py]"]
  node_mixed_config["Mixed xLSTM config"]
  node_mlp["MLP layer<br/>[mlp.py]"]
  node_norm["Layer normalization<br/>[layernorm.py]"]
end

subgraph group_serving["Inference Service"]
  node_http_server["HTTP/MCP endpoints<br/>[http_server.py]"]
  node_service_model["Serving model loader<br/>[model.py]"]
  node_mqtt_server["MQTT interface<br/>[mqtt_server.py]"]
  node_service_config["Service settings<br/>[config.py]"]
  node_service_main["Service startup<br/>[main.py]"]
end

node_user(("Forecast user"))
node_http_client(("HTTP/MCP client"))
node_mqtt_client(("MQTT broker"))

node_user -->|"requests forecast"| node_forecast_api
node_forecast_api -->|"predicts with"| node_backbone
node_forecast_api -->|"uses adapter"| node_dataframe_adapter
node_forecast_api -->|"uses adapter"| node_gluonts_adapter
node_gluonts_adapter -->|"uses adapter"| node_standard_adapter
node_forecast_api -->|"accepts series"| node_series_type
node_demo -->|"creates inputs"| node_series_type
node_demo -->|"plots forecasts"| node_plotting
node_user -->|"visualizes results"| node_plotting
node_backbone -->|"prepares and restores"| node_postprocessor
node_backbone -->|"tokenizes inputs"| node_tokenizer
node_backbone -->|"scales inputs"| node_scaler
node_backbone -->|"builds stack"| node_mixing_block
node_mixing_block -->|"builds mixer"| node_attention
node_mixing_block -->|"uses time mixer"| node_bixlstm
node_bixlstm -->|"uses recurrent layer"| node_slstm
node_bixlstm -->|"uses recurrent layer"| node_mlstm
node_bixlstm -->|"uses configuration"| node_mixed_config
node_attention -->|"uses feed-forward layer"| node_mlp
node_backbone -->|"uses normalization"| node_norm
node_http_client -->|"sends requests"| node_http_server
node_http_server -->|"uses loaded model"| node_service_model
node_service_model -->|"loads model"| node_backbone
node_service_main -->|"starts server"| node_http_server
node_service_main -->|"starts interface"| node_mqtt_server
node_service_main -->|"reads settings"| node_service_config
node_mqtt_server -->|"uses settings"| node_service_config
node_mqtt_client -.->|"exchanges messages"| node_mqtt_server

click node_forecast_api "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/forecast.py"
click node_series_type "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/types.py"
click node_dataframe_adapter "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/dataframe_adapter.py"
click node_gluonts_adapter "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/gluon.py"
click node_standard_adapter "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/standard_adapter.py"
click node_demo "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/demo.py"
click node_plotting "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/plotting.py"
click node_backbone "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/tirex2.py"
click node_postprocessor "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/postprocessor.py"
click node_tokenizer "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/patch_tokenizer.py"
click node_scaler "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/scaler.py"
click node_mixing_block "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/variate_mixing_block.py"
click node_attention "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/attention_block.py"
click node_bixlstm "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/bi_xlstm.py"
click node_slstm "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/flashrnn_slstm.py"
click node_mlstm "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/mlstm_block.py"
click node_mixed_config "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/xlstm_mixed_config.py"
click node_mlp "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/mlp.py"
click node_norm "https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/layernorm.py"
click node_http_server "https://github.com/nx-ai/tirex-2/blob/main/inference/app/http_server.py"
click node_service_model "https://github.com/nx-ai/tirex-2/blob/main/inference/app/model.py"
click node_mqtt_server "https://github.com/nx-ai/tirex-2/blob/main/inference/app/mqtt_server.py"
click node_service_config "https://github.com/nx-ai/tirex-2/blob/main/inference/app/config.py"
click node_service_main "https://github.com/nx-ai/tirex-2/blob/main/inference/app/main.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_forecast_api,node_series_type,node_dataframe_adapter,node_gluonts_adapter,node_standard_adapter,node_demo,node_plotting,node_user,node_http_client toneBlue
class node_backbone,node_postprocessor,node_tokenizer,node_scaler toneAmber
class node_mixing_block,node_attention,node_bixlstm,node_slstm,node_mlstm,node_mixed_config,node_mlp,node_norm toneMint
class node_http_server,node_service_model,node_mqtt_server,node_service_config,node_service_main toneRose
class node_mqtt_client toneIndigo
```

## Components

### Forecast APIs

- [Forecast API](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/forecast.py): `src/tirex2/api_adapter/forecast.py`
- [Series inputs](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/types.py): `src/tirex2/model/types.py`
- [DataFrame adapter](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/dataframe_adapter.py): `src/tirex2/api_adapter/dataframe_adapter.py`
- [GluonTS adapter](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/gluon.py): `src/tirex2/api_adapter/gluon.py`
- [Standard adapter](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/api_adapter/standard_adapter.py): `src/tirex2/api_adapter/standard_adapter.py`
- [Demo data](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/demo.py): `src/tirex2/demo.py`
- [Forecast plots](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/plotting.py): `src/tirex2/plotting.py`

### Forecast Model

- [TiRex2 backbone](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/tirex2.py): `src/tirex2/model/tirex2.py`
- [Input/output processing](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/postprocessor.py): `src/tirex2/model/component/postprocessor.py`
- [Patch tokenizer](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/patch_tokenizer.py): `src/tirex2/model/component/patch_tokenizer.py`
- [Series scaling](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/scaler.py): `src/tirex2/model/component/scaler.py`

### Model Components

- [Variate mixing](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/variate_mixing_block.py): `src/tirex2/model/component/variate_mixing_block.py`
- [Attention mixer](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/attention_block.py): `src/tirex2/model/component/attention_block.py`
- [Bi-xLSTM mixer](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/bi_xlstm.py): `src/tirex2/model/component/bi_xlstm.py`
- [FlashRNN sLSTM](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/flashrnn_slstm.py): `src/tirex2/model/component/flashrnn_slstm.py`
- [mLSTM layer](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/mlstm_block.py): `src/tirex2/model/component/mlstm_block.py`
- [Mixed xLSTM config](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/xlstm_mixed_config.py): `src/tirex2/model/component/xlstm_mixed_config.py`
- [MLP layer](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/mlp.py): `src/tirex2/model/component/mlp.py`
- [Layer normalization](https://github.com/nx-ai/tirex-2/blob/main/src/tirex2/model/component/layernorm.py): `src/tirex2/model/component/layernorm.py`

### Inference Service

- [HTTP/MCP endpoints](https://github.com/nx-ai/tirex-2/blob/main/inference/app/http_server.py): `inference/app/http_server.py`
- [Serving model loader](https://github.com/nx-ai/tirex-2/blob/main/inference/app/model.py): `inference/app/model.py`
- [MQTT interface](https://github.com/nx-ai/tirex-2/blob/main/inference/app/mqtt_server.py): `inference/app/mqtt_server.py`
- [Service settings](https://github.com/nx-ai/tirex-2/blob/main/inference/app/config.py): `inference/app/config.py`
- [Service startup](https://github.com/nx-ai/tirex-2/blob/main/inference/app/main.py): `inference/app/main.py`

### Other components

- **Forecast user**
- **HTTP/MCP client**
- **MQTT broker**

## Connections

- Forecast user → Forecast API: requests forecast (evidence: `README.md`)
- Forecast API → TiRex2 backbone: predicts with (evidence: `src/tirex2/api_adapter/forecast.py`)
- Forecast API → DataFrame adapter: uses adapter (evidence: `src/tirex2/api_adapter/forecast.py`)
- Forecast API → GluonTS adapter: uses adapter (evidence: `src/tirex2/api_adapter/forecast.py`)
- GluonTS adapter → Standard adapter: uses adapter (evidence: `src/tirex2/api_adapter/gluon.py`)
- Forecast API → Series inputs: accepts series (evidence: `src/tirex2/api_adapter/forecast.py`)
- Demo data → Series inputs: creates inputs (evidence: `src/tirex2/demo.py`)
- Demo data → Forecast plots: plots forecasts (evidence: `src/tirex2/demo.py`)
- Forecast user → Forecast plots: visualizes results (evidence: `README.md`)
- TiRex2 backbone → Input/output processing: prepares and restores (evidence: `src/tirex2/model/tirex2.py`)
- TiRex2 backbone → Patch tokenizer: tokenizes inputs (evidence: `src/tirex2/model/tirex2.py`)
- TiRex2 backbone → Series scaling: scales inputs (evidence: `src/tirex2/model/tirex2.py`)
- TiRex2 backbone → Variate mixing: builds stack (evidence: `src/tirex2/model/tirex2.py`)
- Variate mixing → Attention mixer: builds mixer (evidence: `src/tirex2/model/component/variate_mixing_block.py`)
- Variate mixing → Bi-xLSTM mixer: uses time mixer (evidence: `src/tirex2/model/component/variate_mixing_block.py`)
- Bi-xLSTM mixer → FlashRNN sLSTM: uses recurrent layer (evidence: `src/tirex2/model/component/bi_xlstm.py`)
- Bi-xLSTM mixer → mLSTM layer: uses recurrent layer (evidence: `src/tirex2/model/component/bi_xlstm.py`)
- Bi-xLSTM mixer → Mixed xLSTM config: uses configuration (evidence: `src/tirex2/model/component/bi_xlstm.py`)
- Attention mixer → MLP layer: uses feed-forward layer (evidence: `src/tirex2/model/component/attention_block.py`)
- TiRex2 backbone → Layer normalization: uses normalization (evidence: `src/tirex2/model/tirex2.py`)
- HTTP/MCP client → HTTP/MCP endpoints: sends requests (evidence: `README.md`)
- HTTP/MCP endpoints → Serving model loader: uses loaded model (evidence: `inference/app/http_server.py`)
- Serving model loader → TiRex2 backbone: loads model (evidence: `inference/app/model.py`)
- Service startup → HTTP/MCP endpoints: starts server (evidence: `inference/app/main.py`)
- Service startup → MQTT interface: starts interface (evidence: `inference/app/main.py`)
- Service startup → Service settings: reads settings (evidence: `inference/app/main.py`)
- MQTT interface → Service settings: uses settings (evidence: `inference/app/mqtt_server.py`)
- MQTT broker → MQTT interface: exchanges messages
