# thiagorpg-stack/fvtt_ajustar_ameacas architecture

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

- Interactive diagram: https://gitdiagram.com/thiagorpg-stack/fvtt_ajustar_ameacas
- Repository: https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas

## Overview

Tormenta20: Ajustar ND is a Foundry VTT module for recalibrating a threat’s stats and text to a target challenge rating and role. A GM opens the adjustment dialog from an actor sheet or directory, configures options and templates, reviews a simulated before-and-after preview, then applies the result—by default as a copy. The rule engine consults parameter tables and calculates combat changes, warnings, and template effects. README-documented capabilities include resistance and spell-circle advice, hand-written text updates, and Boss, Swarm, and Band templates. Some subsystem details are documented but their implementations were not sampled.

Main entry points: [`scripts/ajuste.js`](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/ajuste.js) (Adjustment planner), [`scripts/main.js`](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/main.js) (Module hooks), [`scripts/dialogo.js`](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/dialogo.js) (Adjustment dialog), [`scripts/aplicar.js`](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/aplicar.js) (Simulation and apply)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Foundry entry"]
  node_main["Module hooks<br/>[main.js]"]
  node_foundry[("Foundry actors")]
  node_chat["Foundry chat"]
end

subgraph group_workflow["Adjustment workflow"]
  node_dialog["Adjustment dialog<br/>[dialogo.js]"]
  node_view["Preview view<br/>[dialogo.hbs]"]
  node_apply["Simulation and apply<br/>[aplicar.js]"]
end

subgraph group_rules["Rules engine"]
  node_adjust["Adjustment planner<br/>[ajuste.js]"]
  node_calculation["Combat planning<br/>[calculo.js]"]
  node_damage["Damage balancing<br/>[dano.js]"]
  node_tables["Table lookup<br/>[tabelas.js]"]
  node_tabledata["Threat parameters<br/>[tables.json]"]
  node_text["Sheet text updates<br/>[textos.js]"]
  node_circles["Spell-circle advice<br/>[circulos.js]"]
  node_tiers["Tier warnings<br/>[patamares.js]"]
end

subgraph group_features["Templates and messages"]
  node_templates["Threat templates<br/>[templates.js]"]
  node_welcome["Welcome messages<br/>[boas-vindas.js]"]
end

node_gm(("GM"))

node_gm -->|"opens adjustment"| node_main
node_main -->|"opens dialog"| node_dialog
node_dialog -->|"renders"| node_view
node_dialog -->|"reads actor"| node_foundry
node_dialog -->|"simulates or applies"| node_apply
node_apply -->|"calculates adjustment"| node_adjust
node_apply -->|"loads tables"| node_tabledata
node_apply -->|"measures and writes"| node_foundry
node_adjust -->|"plans combat"| node_calculation
node_adjust -->|"normalizes rating"| node_tables
node_adjust -->|"updates descriptions"| node_text
node_adjust -->|"gets spell advice"| node_circles
node_adjust -->|"gets tier warnings"| node_tiers
node_adjust -->|"applies template effects"| node_templates
node_calculation -->|"queries parameters"| node_tables
node_calculation -->|"balances weapon damage"| node_damage
node_calculation -->|"matches weapon names"| node_text
node_tiers -->|"queries tier values"| node_tables
node_templates -->|"reads rating values"| node_tables
node_templates -->|"gets rating tier"| node_tiers
node_templates -->|"computes damage average"| node_damage
node_main -->|"builds chat message"| node_welcome
node_main -->|"sends whisper"| node_chat

click node_main "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/main.js"
click node_dialog "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/dialogo.js"
click node_view "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/templates/dialogo.hbs"
click node_apply "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/aplicar.js"
click node_adjust "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/ajuste.js"
click node_calculation "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/calculo.js"
click node_damage "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/dano.js"
click node_tables "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/tabelas.js"
click node_tabledata "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/data/tables.json"
click node_text "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/textos.js"
click node_circles "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/circulos.js"
click node_tiers "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/patamares.js"
click node_templates "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/templates.js"
click node_welcome "https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/boas-vindas.js"

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_foundry,node_chat toneBlue
class node_dialog,node_view,node_apply toneAmber
class node_adjust,node_calculation,node_damage,node_tables,node_tabledata,node_text,node_circles,node_tiers toneMint
class node_templates,node_welcome toneRose
class node_gm toneIndigo
```

## Components

### Foundry entry

- [Module hooks](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/main.js): `scripts/main.js`
- **Foundry actors**
- **Foundry chat**

### Adjustment workflow

- [Adjustment dialog](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/dialogo.js): `scripts/dialogo.js`
- [Preview view](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/templates/dialogo.hbs): `templates/dialogo.hbs`
- [Simulation and apply](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/aplicar.js): `scripts/aplicar.js`

### Rules engine

- [Adjustment planner](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/ajuste.js): `scripts/ajuste.js`
- [Combat planning](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/calculo.js): `scripts/calculo.js`
- [Damage balancing](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/dano.js): `scripts/dano.js`
- [Table lookup](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/tabelas.js): `scripts/tabelas.js`
- [Threat parameters](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/data/tables.json): `data/tables.json`
- [Sheet text updates](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/textos.js): `scripts/textos.js`
- [Spell-circle advice](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/circulos.js): `scripts/circulos.js`
- [Tier warnings](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/patamares.js): `scripts/patamares.js`

### Templates and messages

- [Threat templates](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/templates.js): `scripts/templates.js`
- [Welcome messages](https://github.com/thiagorpg-stack/fvtt_ajustar_ameacas/blob/main/scripts/boas-vindas.js): `scripts/boas-vindas.js`

### Other components

- **GM**

## Connections

- GM → Module hooks: opens adjustment (evidence: `scripts/main.js`)
- Module hooks → Adjustment dialog: opens dialog (evidence: `scripts/main.js`)
- Adjustment dialog → Preview view: renders (evidence: `scripts/dialogo.js`)
- Adjustment dialog → Foundry actors: reads actor (evidence: `scripts/dialogo.js`)
- Adjustment dialog → Simulation and apply: simulates or applies (evidence: `scripts/dialogo.js`)
- Simulation and apply → Adjustment planner: calculates adjustment (evidence: `scripts/aplicar.js`)
- Simulation and apply → Threat parameters: loads tables (evidence: `scripts/aplicar.js`)
- Simulation and apply → Foundry actors: measures and writes (evidence: `scripts/aplicar.js`)
- Adjustment planner → Combat planning: plans combat (evidence: `scripts/ajuste.js`)
- Adjustment planner → Table lookup: normalizes rating (evidence: `scripts/ajuste.js`)
- Adjustment planner → Sheet text updates: updates descriptions (evidence: `scripts/ajuste.js`)
- Adjustment planner → Spell-circle advice: gets spell advice (evidence: `scripts/ajuste.js`)
- Adjustment planner → Tier warnings: gets tier warnings (evidence: `scripts/ajuste.js`)
- Adjustment planner → Threat templates: applies template effects (evidence: `scripts/ajuste.js`)
- Combat planning → Table lookup: queries parameters (evidence: `scripts/calculo.js`)
- Combat planning → Damage balancing: balances weapon damage (evidence: `scripts/calculo.js`)
- Combat planning → Sheet text updates: matches weapon names (evidence: `scripts/calculo.js`)
- Tier warnings → Table lookup: queries tier values (evidence: `scripts/patamares.js`)
- Threat templates → Table lookup: reads rating values (evidence: `scripts/templates.js`)
- Threat templates → Tier warnings: gets rating tier (evidence: `scripts/templates.js`)
- Threat templates → Damage balancing: computes damage average (evidence: `scripts/templates.js`)
- Module hooks → Welcome messages: builds chat message (evidence: `scripts/main.js`)
- Module hooks → Foundry chat: sends whisper (evidence: `scripts/main.js`)
