# metacubex/mihomo architecture

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

- Interactive diagram: https://gitdiagram.com/metacubex/mihomo
- Repository: https://github.com/metacubex/mihomo

## Overview

mihomo is an asynchronous Python client and Pydantic model library for parsed Honkai: Star Rail player data from the Mihomo API. Its main workflow fetches a UID in either the documented V1 or V2 format, optionally transforms raw data, and parses it into that version’s model. The library also exposes icon URL generation and character deduplication/merging helpers. Model relationships and client calls are shown where source excerpts or README statements support them; unsampled model modules are represented by their exact paths, but their internal behavior is not inferred.

Main entry points: [`mihomo/client.py`](https://github.com/metacubex/mihomo/blob/main/mihomo/client.py) (Mihomo client), [`mihomo/models/character.py`](https://github.com/metacubex/mihomo/blob/main/mihomo/models/character.py) (Character data), [`mihomo/models/base.py`](https://github.com/metacubex/mihomo/blob/main/mihomo/models/base.py) (V2 parsed data), [`mihomo/models/equipment.py`](https://github.com/metacubex/mihomo/blob/main/mihomo/models/equipment.py) (Equipment data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["API client"]
  node_client["Mihomo client<br/>[client.py]"]
  node_errors["Request errors<br/>[errors.py]"]
end

subgraph group_v2["V2 data models"]
  node_v2root["V2 parsed data<br/>[base.py]"]
  node_v2character["Character data<br/>[character.py]"]
  node_combat["Combat data<br/>[combat.py]"]
  node_equipment["Equipment data<br/>[equipment.py]"]
  node_stats["Stats and affixes<br/>[stat.py]"]
  node_player["Player data<br/>[player.py]"]
end

subgraph group_v1["V1 data models"]
  node_v1root["V1 parsed data<br/>[base.py]"]
  node_v1character["V1 character data<br/>[character.py]"]
  node_v1equipment["V1 equipment data<br/>[equipment.py]"]
  node_v1player["V1 player data<br/>[player.py]"]
end

subgraph group_helpers["Data helpers"]
  node_tools["Data transformations<br/>[tools.py]"]
end

node_user(("Library user"))
node_api["Mihomo API"]
node_asset["StarRail assets"]

node_user -->|"calls"| node_client
node_client -->|"requests data"| node_api
node_client -->|"raises"| node_errors
node_client -->|"parses V2"| node_v2root
node_client -->|"parses V1"| node_v1root
node_client -->|"transforms data"| node_tools
node_client -->|"builds icon URLs"| node_asset
node_v2root -->|"uses"| node_v2character
node_v2root -->|"uses"| node_player
node_v2character -->|"uses"| node_combat
node_v2character -->|"uses"| node_equipment
node_v2character -->|"uses"| node_stats
node_equipment -->|"uses"| node_combat
node_equipment -->|"uses"| node_stats
node_v1root -->|"uses"| node_v1character
node_v1root -->|"uses"| node_v1player
node_v1character -->|"uses"| node_v1equipment
node_user -->|"cleans or merges"| node_tools

click node_client "https://github.com/metacubex/mihomo/blob/main/mihomo/client.py"
click node_errors "https://github.com/metacubex/mihomo/blob/main/mihomo/errors.py"
click node_v2root "https://github.com/metacubex/mihomo/blob/main/mihomo/models/base.py"
click node_v2character "https://github.com/metacubex/mihomo/blob/main/mihomo/models/character.py"
click node_combat "https://github.com/metacubex/mihomo/blob/main/mihomo/models/combat.py"
click node_equipment "https://github.com/metacubex/mihomo/blob/main/mihomo/models/equipment.py"
click node_stats "https://github.com/metacubex/mihomo/blob/main/mihomo/models/stat.py"
click node_player "https://github.com/metacubex/mihomo/blob/main/mihomo/models/player.py"
click node_v1root "https://github.com/metacubex/mihomo/blob/main/mihomo/models/v1/base.py"
click node_v1character "https://github.com/metacubex/mihomo/blob/main/mihomo/models/v1/character.py"
click node_v1equipment "https://github.com/metacubex/mihomo/blob/main/mihomo/models/v1/equipment.py"
click node_v1player "https://github.com/metacubex/mihomo/blob/main/mihomo/models/v1/player.py"
click node_tools "https://github.com/metacubex/mihomo/blob/main/mihomo/tools.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_client,node_errors,node_user toneBlue
class node_v2root,node_v2character,node_combat,node_equipment,node_stats,node_player toneAmber
class node_v1root,node_v1character,node_v1equipment,node_v1player,node_api toneMint
class node_tools toneRose
class node_asset toneIndigo
```

## Components

### API client

- [Mihomo client](https://github.com/metacubex/mihomo/blob/main/mihomo/client.py): `mihomo/client.py`
- [Request errors](https://github.com/metacubex/mihomo/blob/main/mihomo/errors.py): `mihomo/errors.py`

### V2 data models

- [V2 parsed data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/base.py): `mihomo/models/base.py`
- [Character data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/character.py): `mihomo/models/character.py`
- [Combat data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/combat.py): `mihomo/models/combat.py`
- [Equipment data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/equipment.py): `mihomo/models/equipment.py`
- [Stats and affixes](https://github.com/metacubex/mihomo/blob/main/mihomo/models/stat.py): `mihomo/models/stat.py`
- [Player data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/player.py): `mihomo/models/player.py`

### V1 data models

- [V1 parsed data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/v1/base.py): `mihomo/models/v1/base.py`
- [V1 character data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/v1/character.py): `mihomo/models/v1/character.py`
- [V1 equipment data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/v1/equipment.py): `mihomo/models/v1/equipment.py`
- [V1 player data](https://github.com/metacubex/mihomo/blob/main/mihomo/models/v1/player.py): `mihomo/models/v1/player.py`

### Data helpers

- [Data transformations](https://github.com/metacubex/mihomo/blob/main/mihomo/tools.py): `mihomo/tools.py`

### Other components

- **Library user**
- **Mihomo API**
- **StarRail assets**

## Connections

- Library user → Mihomo client: calls (evidence: `README.md`)
- Mihomo client → Mihomo API: requests data (evidence: `mihomo/client.py`)
- Mihomo client → Request errors: raises (evidence: `mihomo/client.py`)
- Mihomo client → V2 parsed data: parses V2 (evidence: `mihomo/client.py`)
- Mihomo client → V1 parsed data: parses V1 (evidence: `mihomo/client.py`)
- Mihomo client → Data transformations: transforms data (evidence: `mihomo/client.py`)
- Mihomo client → StarRail assets: builds icon URLs (evidence: `mihomo/client.py`)
- V2 parsed data → Character data: uses (evidence: `mihomo/models/base.py`)
- V2 parsed data → Player data: uses (evidence: `mihomo/models/base.py`)
- Character data → Combat data: uses (evidence: `mihomo/models/character.py`)
- Character data → Equipment data: uses (evidence: `mihomo/models/character.py`)
- Character data → Stats and affixes: uses (evidence: `mihomo/models/character.py`)
- Equipment data → Combat data: uses (evidence: `mihomo/models/equipment.py`)
- Equipment data → Stats and affixes: uses (evidence: `mihomo/models/equipment.py`)
- V1 parsed data → V1 character data: uses (evidence: `mihomo/models/v1/base.py`)
- V1 parsed data → V1 player data: uses (evidence: `mihomo/models/v1/base.py`)
- V1 character data → V1 equipment data: uses (evidence: `mihomo/models/v1/character.py`)
- Library user → Data transformations: cleans or merges (evidence: `README.md`)
