# maximiliansabino/gm-llm architecture

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

- Interactive diagram: https://gitdiagram.com/maximiliansabino/gm-llm
- Repository: https://github.com/maximiliansabino/gm-llm

## Overview

This repository is a text-based, LLM-mediated tabletop RPG. A player starts at the main menu, chooses a character and adventure mode, then submits narrated actions or combat commands; the game produces narration and resolves outcomes while recording canonical journey state. Major branches include biome-based combat, open-world exploration, NPC dialogue and memory, and an LLM-judge evaluation tool. Edges are based on README statements and source-index references or excerpts; unsampled implementation details are represented conservatively.

Main entry points: [`combate.py`](https://github.com/maximiliansabino/gm-llm/blob/main/combate.py) (Combat Engine), [`main.py`](https://github.com/maximiliansabino/gm-llm/blob/main/main.py) (Game Loop), [`llm_backend.py`](https://github.com/maximiliansabino/gm-llm/blob/main/llm_backend.py) (LLM Backend), [`mundo_aberto.py`](https://github.com/maximiliansabino/gm-llm/blob/main/mundo_aberto.py) (Open World)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game Runtime"]
  node_main["Game Loop<br/>[main.py]"]
  node_questions["Setup Prompts"]
  node_characters["Characters<br/>[personagens.py]"]
  node_inventory["Items<br/>[itens.py]"]
  node_skills["Abilities<br/>[habilidades.py]"]
end

subgraph group_world["World and Encounters"]
  node_combat["Combat Engine<br/>[combate.py]"]
  node_enemies["Enemy Catalog<br/>[inimigos.py]"]
  node_biomes["Biome Encounters<br/>[biomas.py]"]
  node_openworld["Open World<br/>[mundo_aberto.py]"]
  node_map["Biome Map<br/>[mapa_biomas.py]"]
end

subgraph group_narrative["Narrative and Memory"]
  node_story["Story and NPCs<br/>[historias.py]"]
  node_npcmemory["NPC Memory<br/>[memoria_npc.py]"]
  node_rag["Lore Retrieval<br/>[memoria_rag.py]"]
  node_journey[("Journey State<br/>[jornada.py]")]
  node_sessionlog["Session Log<br/>[session_log.py]"]
end

subgraph group_llm["LLM Services"]
  node_backend["LLM Backend<br/>[llm_backend.py]"]
  node_llmconfig["Backend Config<br/>[llm_config.py]"]
end

subgraph group_assessment["Evaluation"]
  node_judge["LLM Judge<br/>[rpg_judge.py]"]
end

node_player(("Player"))
node_ollama{{"Ollama"}}
node_groq{{"Groq"}}
node_lmstudio{{"LM Studio"}}

node_player -->|"starts game"| node_main
node_main -->|"sets up"| node_questions
node_main -->|"selects"| node_characters
node_main -->|"starts mode"| node_biomes
node_main -->|"starts mode"| node_openworld
node_main -->|"dispatches combat"| node_combat
node_main -->|"loads state"| node_journey
node_main -->|"starts logging"| node_sessionlog
node_main -->|"uses"| node_backend
node_characters -->|"uses items"| node_inventory
node_characters -->|"uses abilities"| node_skills
node_biomes -->|"runs battles"| node_combat
node_biomes -->|"updates location"| node_journey
node_biomes -->|"narrates encounters"| node_story
node_biomes -->|"uses enemies"| node_enemies
node_combat -->|"updates combatants"| node_characters
node_combat -->|"resolves attacks"| node_enemies
node_combat -->|"uses equipment"| node_inventory
node_combat -->|"uses abilities"| node_skills
node_combat -->|"records outcomes"| node_journey
node_combat -->|"logs calls"| node_sessionlog
node_combat -.->|"requests evaluation"| node_backend
node_openworld -->|"uses map"| node_map
node_openworld -->|"dispatches combat"| node_combat
node_openworld -->|"uses narrative"| node_story
node_openworld -->|"uses memory"| node_npcmemory
node_openworld -->|"reads and updates"| node_journey
node_story -->|"requests narration"| node_backend
node_story -->|"reads context"| node_journey
node_story -->|"retrieves lore"| node_rag
node_rag -->|"reads state"| node_journey
node_backend -->|"loads settings"| node_llmconfig
node_backend -->|"records calls"| node_sessionlog
node_backend -.->|"sends requests"| node_ollama
node_backend -.->|"sends requests"| node_groq
node_backend -.->|"sends requests"| node_lmstudio
node_judge -->|"uses backend"| node_backend

click node_main "https://github.com/maximiliansabino/gm-llm/blob/main/main.py"
click node_questions "https://github.com/maximiliansabino/gm-llm/blob/main/perguntas_iniciais.py"
click node_characters "https://github.com/maximiliansabino/gm-llm/blob/main/personagens.py"
click node_inventory "https://github.com/maximiliansabino/gm-llm/blob/main/itens.py"
click node_skills "https://github.com/maximiliansabino/gm-llm/blob/main/habilidades.py"
click node_combat "https://github.com/maximiliansabino/gm-llm/blob/main/combate.py"
click node_enemies "https://github.com/maximiliansabino/gm-llm/blob/main/inimigos.py"
click node_biomes "https://github.com/maximiliansabino/gm-llm/blob/main/biomas.py"
click node_openworld "https://github.com/maximiliansabino/gm-llm/blob/main/mundo_aberto.py"
click node_map "https://github.com/maximiliansabino/gm-llm/blob/main/mapa_biomas.py"
click node_story "https://github.com/maximiliansabino/gm-llm/blob/main/historias.py"
click node_npcmemory "https://github.com/maximiliansabino/gm-llm/blob/main/memoria_npc.py"
click node_rag "https://github.com/maximiliansabino/gm-llm/blob/main/memoria_rag.py"
click node_journey "https://github.com/maximiliansabino/gm-llm/blob/main/jornada.py"
click node_sessionlog "https://github.com/maximiliansabino/gm-llm/blob/main/session_log.py"
click node_backend "https://github.com/maximiliansabino/gm-llm/blob/main/llm_backend.py"
click node_llmconfig "https://github.com/maximiliansabino/gm-llm/blob/main/llm_config.py"
click node_judge "https://github.com/maximiliansabino/gm-llm/blob/main/rpg_judge.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_main,node_questions,node_characters,node_inventory,node_skills toneBlue
class node_combat,node_enemies,node_biomes,node_openworld,node_map toneAmber
class node_story,node_npcmemory,node_rag,node_journey,node_sessionlog toneMint
class node_backend,node_llmconfig toneRose
class node_judge,node_player,node_ollama,node_groq,node_lmstudio toneIndigo
```

## Components

### Game Runtime

- [Game Loop](https://github.com/maximiliansabino/gm-llm/blob/main/main.py): `main.py`
- [Setup Prompts](https://github.com/maximiliansabino/gm-llm/blob/main/perguntas_iniciais.py): `perguntas_iniciais.py`
- [Characters](https://github.com/maximiliansabino/gm-llm/blob/main/personagens.py): `personagens.py`
- [Items](https://github.com/maximiliansabino/gm-llm/blob/main/itens.py): `itens.py`
- [Abilities](https://github.com/maximiliansabino/gm-llm/blob/main/habilidades.py): `habilidades.py`

### World and Encounters

- [Combat Engine](https://github.com/maximiliansabino/gm-llm/blob/main/combate.py): `combate.py`
- [Enemy Catalog](https://github.com/maximiliansabino/gm-llm/blob/main/inimigos.py): `inimigos.py`
- [Biome Encounters](https://github.com/maximiliansabino/gm-llm/blob/main/biomas.py): `biomas.py`
- [Open World](https://github.com/maximiliansabino/gm-llm/blob/main/mundo_aberto.py): `mundo_aberto.py`
- [Biome Map](https://github.com/maximiliansabino/gm-llm/blob/main/mapa_biomas.py): `mapa_biomas.py`

### Narrative and Memory

- [Story and NPCs](https://github.com/maximiliansabino/gm-llm/blob/main/historias.py): `historias.py`
- [NPC Memory](https://github.com/maximiliansabino/gm-llm/blob/main/memoria_npc.py): `memoria_npc.py`
- [Lore Retrieval](https://github.com/maximiliansabino/gm-llm/blob/main/memoria_rag.py): `memoria_rag.py`
- [Journey State](https://github.com/maximiliansabino/gm-llm/blob/main/jornada.py): `jornada.py`
- [Session Log](https://github.com/maximiliansabino/gm-llm/blob/main/session_log.py): `session_log.py`

### LLM Services

- [LLM Backend](https://github.com/maximiliansabino/gm-llm/blob/main/llm_backend.py): `llm_backend.py`
- [Backend Config](https://github.com/maximiliansabino/gm-llm/blob/main/llm_config.py): `llm_config.py`

### Evaluation

- [LLM Judge](https://github.com/maximiliansabino/gm-llm/blob/main/rpg_judge.py): `rpg_judge.py`

### Other components

- **Player**
- **Ollama**
- **Groq**
- **LM Studio**

## Connections

- Player → Game Loop: starts game (evidence: `README.md`)
- Game Loop → Setup Prompts: sets up (evidence: `main.py`)
- Game Loop → Characters: selects (evidence: `main.py`)
- Game Loop → Biome Encounters: starts mode (evidence: `main.py`)
- Game Loop → Open World: starts mode (evidence: `main.py`)
- Game Loop → Combat Engine: dispatches combat (evidence: `main.py`)
- Game Loop → Journey State: loads state (evidence: `main.py`)
- Game Loop → Session Log: starts logging (evidence: `main.py`)
- Game Loop → LLM Backend: uses (evidence: `main.py`)
- Characters → Items: uses items (evidence: `personagens.py`)
- Characters → Abilities: uses abilities (evidence: `personagens.py`)
- Biome Encounters → Combat Engine: runs battles (evidence: `biomas.py`)
- Biome Encounters → Journey State: updates location (evidence: `biomas.py`)
- Biome Encounters → Story and NPCs: narrates encounters (evidence: `biomas.py`)
- Biome Encounters → Enemy Catalog: uses enemies (evidence: `biomas.py`)
- Combat Engine → Characters: updates combatants (evidence: `combate.py`)
- Combat Engine → Enemy Catalog: resolves attacks (evidence: `combate.py`)
- Combat Engine → Items: uses equipment (evidence: `combate.py`)
- Combat Engine → Abilities: uses abilities (evidence: `combate.py`)
- Combat Engine → Journey State: records outcomes (evidence: `combate.py`)
- Combat Engine → Session Log: logs calls (evidence: `combate.py`)
- Combat Engine → LLM Backend: requests evaluation (evidence: `combate.py`)
- Open World → Biome Map: uses map (evidence: `mundo_aberto.py`)
- Open World → Combat Engine: dispatches combat (evidence: `mundo_aberto.py`)
- Open World → Story and NPCs: uses narrative (evidence: `mundo_aberto.py`)
- Open World → NPC Memory: uses memory (evidence: `mundo_aberto.py`)
- Open World → Journey State: reads and updates (evidence: `mundo_aberto.py`)
- Story and NPCs → LLM Backend: requests narration (evidence: `historias.py`)
- Story and NPCs → Journey State: reads context (evidence: `historias.py`)
- Story and NPCs → Lore Retrieval: retrieves lore (evidence: `historias.py`)
- Lore Retrieval → Journey State: reads state (evidence: `memoria_rag.py`)
- LLM Backend → Backend Config: loads settings (evidence: `llm_backend.py`)
- LLM Backend → Session Log: records calls (evidence: `llm_backend.py`)
- LLM Backend → Ollama: sends requests
- LLM Backend → Groq: sends requests
- LLM Backend → LM Studio: sends requests
- LLM Judge → LLM Backend: uses backend (evidence: `rpg_judge.py`)
