# fluorohydride/ygopro-core architecture

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

- Interactive diagram: https://gitdiagram.com/fluorohydride/ygopro-core
- Repository: https://github.com/fluorohydride/ygopro-core

## Overview

YGOPro script engine is an embeddable Lua-driven card-duel rules engine. The principal workflow is that a host supplies card and script readers, creates and configures a duel, submits player responses while advancing game ticks, and reads messages and state queries. Lua bindings expose card, duel, effect, group, and debugging capabilities; the rules engine processes duel state and operations. The source index and README support the main subsystem boundaries, but excerpts do not show every internal call, so uncertain links are omitted.

Main entry points: [`ocgapi.cpp`](https://github.com/fluorohydride/ygopro-core/blob/master/ocgapi.cpp) (Duel API), [`field.cpp`](https://github.com/fluorohydride/ygopro-core/blob/master/field.cpp) (Field state and rules), [`scriptlib.h`](https://github.com/fluorohydride/ygopro-core/blob/master/scriptlib.h) (Script interface), [`duel.cpp`](https://github.com/fluorohydride/ygopro-core/blob/master/duel.cpp) (Duel instance)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Host API"]
  node_api["Duel API<br/>[ocgapi.cpp]"]
  node_callbacks["Host callbacks<br/>[ocgapi.h]"]
end

subgraph group_lua["Lua Scripting"]
  node_interpreter["Lua interpreter<br/>[interpreter.cpp]"]
  node_scriptlib["Script interface<br/>[scriptlib.h]"]
  node_cardlib["Card bindings<br/>[libcard.cpp]"]
  node_duellib["Duel bindings<br/>[libduel.cpp]"]
  node_effectlib["Effect bindings<br/>[libeffect.cpp]"]
  node_grouplib["Group bindings<br/>[libgroup.cpp]"]
  node_debuglib["Debug bindings<br/>[libdebug.cpp]"]
end

subgraph group_rules["Duel Rules"]
  node_duel["Duel instance<br/>[duel.cpp]"]
  node_processor["Duel processor<br/>[processor.cpp]"]
  node_field["Field state and rules<br/>[field.cpp]"]
  node_operations["Card operations<br/>[operations.cpp]"]
  node_playerops["Player operations<br/>[playerop.cpp]"]
end

subgraph group_model["Game Model"]
  node_card["Card state<br/>[card.cpp]"]
  node_effect["Effect state<br/>[effect.cpp]"]
  node_group["Card groups<br/>[group.cpp]"]
  node_protocol["Shared protocol types<br/>[common.h]"]
  node_buffer["Message buffer<br/>[buffer.h]"]
end

node_host(("Embedding host"))

node_host -->|"configures and drives"| node_api
node_host -->|"provides readers"| node_callbacks
node_api -->|"creates and advances"| node_duel
node_api -->|"uses callbacks"| node_callbacks
node_api -->|"preloads scripts"| node_interpreter
node_api -->|"queries duel state"| node_field
node_api -->|"reads messages"| node_buffer
node_duel -->|"owns interpreter"| node_interpreter
node_duel -->|"owns field state"| node_field
node_interpreter -->|"registers script API"| node_scriptlib
node_scriptlib -->|"declares bindings"| node_cardlib
node_scriptlib -->|"declares bindings"| node_duellib
node_scriptlib -->|"declares bindings"| node_effectlib
node_scriptlib -->|"declares bindings"| node_grouplib
node_scriptlib -->|"declares bindings"| node_debuglib
node_processor -->|"processes field state"| node_field
node_field -->|"updates cards"| node_card
node_field -->|"evaluates effects"| node_effect
node_operations -->|"operates on field"| node_field
node_playerops -->|"operates on field"| node_field
node_card -->|"filters effects"| node_effect
node_duel -->|"creates groups"| node_group
node_api -->|"exposes message types"| node_protocol

click node_api "https://github.com/fluorohydride/ygopro-core/blob/master/ocgapi.cpp"
click node_callbacks "https://github.com/fluorohydride/ygopro-core/blob/master/ocgapi.h"
click node_duel "https://github.com/fluorohydride/ygopro-core/blob/master/duel.cpp"
click node_interpreter "https://github.com/fluorohydride/ygopro-core/blob/master/interpreter.cpp"
click node_scriptlib "https://github.com/fluorohydride/ygopro-core/blob/master/scriptlib.h"
click node_cardlib "https://github.com/fluorohydride/ygopro-core/blob/master/libcard.cpp"
click node_duellib "https://github.com/fluorohydride/ygopro-core/blob/master/libduel.cpp"
click node_effectlib "https://github.com/fluorohydride/ygopro-core/blob/master/libeffect.cpp"
click node_grouplib "https://github.com/fluorohydride/ygopro-core/blob/master/libgroup.cpp"
click node_debuglib "https://github.com/fluorohydride/ygopro-core/blob/master/libdebug.cpp"
click node_processor "https://github.com/fluorohydride/ygopro-core/blob/master/processor.cpp"
click node_field "https://github.com/fluorohydride/ygopro-core/blob/master/field.cpp"
click node_operations "https://github.com/fluorohydride/ygopro-core/blob/master/operations.cpp"
click node_playerops "https://github.com/fluorohydride/ygopro-core/blob/master/playerop.cpp"
click node_card "https://github.com/fluorohydride/ygopro-core/blob/master/card.cpp"
click node_effect "https://github.com/fluorohydride/ygopro-core/blob/master/effect.cpp"
click node_group "https://github.com/fluorohydride/ygopro-core/blob/master/group.cpp"
click node_protocol "https://github.com/fluorohydride/ygopro-core/blob/master/common.h"
click node_buffer "https://github.com/fluorohydride/ygopro-core/blob/master/buffer.h"

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_api,node_callbacks toneBlue
class node_interpreter,node_scriptlib,node_cardlib,node_duellib,node_effectlib,node_grouplib,node_debuglib toneAmber
class node_duel,node_processor,node_field,node_operations,node_playerops toneMint
class node_card,node_effect,node_group,node_protocol,node_buffer toneRose
class node_host toneIndigo
```

## Components

### Host API

- [Duel API](https://github.com/fluorohydride/ygopro-core/blob/master/ocgapi.cpp): `ocgapi.cpp`
- [Host callbacks](https://github.com/fluorohydride/ygopro-core/blob/master/ocgapi.h): `ocgapi.h`

### Lua Scripting

- [Lua interpreter](https://github.com/fluorohydride/ygopro-core/blob/master/interpreter.cpp): `interpreter.cpp`
- [Script interface](https://github.com/fluorohydride/ygopro-core/blob/master/scriptlib.h): `scriptlib.h`
- [Card bindings](https://github.com/fluorohydride/ygopro-core/blob/master/libcard.cpp): `libcard.cpp`
- [Duel bindings](https://github.com/fluorohydride/ygopro-core/blob/master/libduel.cpp): `libduel.cpp`
- [Effect bindings](https://github.com/fluorohydride/ygopro-core/blob/master/libeffect.cpp): `libeffect.cpp`
- [Group bindings](https://github.com/fluorohydride/ygopro-core/blob/master/libgroup.cpp): `libgroup.cpp`
- [Debug bindings](https://github.com/fluorohydride/ygopro-core/blob/master/libdebug.cpp): `libdebug.cpp`

### Duel Rules

- [Duel instance](https://github.com/fluorohydride/ygopro-core/blob/master/duel.cpp): `duel.cpp`
- [Duel processor](https://github.com/fluorohydride/ygopro-core/blob/master/processor.cpp): `processor.cpp`
- [Field state and rules](https://github.com/fluorohydride/ygopro-core/blob/master/field.cpp): `field.cpp`
- [Card operations](https://github.com/fluorohydride/ygopro-core/blob/master/operations.cpp): `operations.cpp`
- [Player operations](https://github.com/fluorohydride/ygopro-core/blob/master/playerop.cpp): `playerop.cpp`

### Game Model

- [Card state](https://github.com/fluorohydride/ygopro-core/blob/master/card.cpp): `card.cpp`
- [Effect state](https://github.com/fluorohydride/ygopro-core/blob/master/effect.cpp): `effect.cpp`
- [Card groups](https://github.com/fluorohydride/ygopro-core/blob/master/group.cpp): `group.cpp`
- [Shared protocol types](https://github.com/fluorohydride/ygopro-core/blob/master/common.h): `common.h`
- [Message buffer](https://github.com/fluorohydride/ygopro-core/blob/master/buffer.h): `buffer.h`

### Other components

- **Embedding host**

## Connections

- Embedding host → Duel API: configures and drives (evidence: `README.md`)
- Embedding host → Host callbacks: provides readers (evidence: `README.md`)
- Duel API → Duel instance: creates and advances (evidence: `README.md`)
- Duel API → Host callbacks: uses callbacks (evidence: `ocgapi.cpp`)
- Duel API → Lua interpreter: preloads scripts (evidence: `ocgapi.cpp`)
- Duel API → Field state and rules: queries duel state (evidence: `ocgapi.cpp`)
- Duel API → Message buffer: reads messages (evidence: `ocgapi.cpp`)
- Duel instance → Lua interpreter: owns interpreter (evidence: `duel.cpp`)
- Duel instance → Field state and rules: owns field state (evidence: `duel.cpp`)
- Lua interpreter → Script interface: registers script API (evidence: `interpreter.cpp`)
- Script interface → Card bindings: declares bindings (evidence: `scriptlib.h`)
- Script interface → Duel bindings: declares bindings (evidence: `scriptlib.h`)
- Script interface → Effect bindings: declares bindings (evidence: `scriptlib.h`)
- Script interface → Group bindings: declares bindings (evidence: `scriptlib.h`)
- Script interface → Debug bindings: declares bindings (evidence: `README.md`)
- Duel processor → Field state and rules: processes field state (evidence: `processor.cpp`)
- Field state and rules → Card state: updates cards (evidence: `field.cpp`)
- Field state and rules → Effect state: evaluates effects (evidence: `field.cpp`)
- Card operations → Field state and rules: operates on field (evidence: `operations.cpp`)
- Player operations → Field state and rules: operates on field (evidence: `playerop.cpp`)
- Card state → Effect state: filters effects (evidence: `card.cpp`)
- Duel instance → Card groups: creates groups
- Duel API → Shared protocol types: exposes message types
