$npx -y skills add thedivergentai/GD-Agentic-Skills --skill godot-composition-appsExpert architectural standards for building scalable Godot applications (Apps, Tools, UI, or Games) using the Composition pattern. Use when designing node structures, refactoring monolithic scripts, or implementing complex behaviors. Enforces \"Has-A\" relationships over \"Is-A\"
| 1 | # Godot Composition & Architecture (Apps & UI) |
| 2 | |
| 3 | This skill enforces the **Single Responsibility Principle** within Godot's Node system. Whether building an RPG or a SaaS Dashboard, the rule remains: **One Script = One Job.** |
| 4 | |
| 5 | ## The Core Philosophy |
| 6 | |
| 7 | ### The Litmus Test |
| 8 | Before writing a script, ask: **"If I attached this script to a literal rock, would it still function?"** |
| 9 | - **Pass:** An `AuthComponent` on a rock allows the rock to log in. (Context Agnostic) |
| 10 | - **Fail:** A `LoginForm` script on a rock tries to grab text fields the rock doesn't have. (Coupled) |
| 11 | |
| 12 | ### The Backpack Model (Has-A > Is-A) |
| 13 | Stop extending base classes to add functionality. Treat the Root Node as an empty **Backpack**. |
| 14 | - **Wrong (Inheritance):** `SubmitButton` extends `AnimatedButton` extends `BaseButton`. |
| 15 | - **Right (Composition):** `SubmitButton` (Root) **HAS-A** `AnimationComponent` and **HAS-A** `NetworkRequestComponent`. |
| 16 | |
| 17 | ## The Hierarchy of Power (Communication Rules) |
| 18 | |
| 19 | Strictly enforce this communication flow to prevent "Spaghetti Code": |
| 20 | |
| 21 | | Direction | Source → Target | Method | Reason | |
| 22 | |-----------|-----------------|--------|--------| |
| 23 | | **Downward** | Orchestrator → Component | **Function Call** | Manager owns the workers; knows they exist. | |
| 24 | | **Upward** | Component → Orchestrator | **Signals** | Workers are blind; they just yell "I'm done!" | |
| 25 | | **Sideways** | Component A ↔ Component B | **FORBIDDEN** | Siblings must never talk directly. | |
| 26 | |
| 27 | **The Sideways Fix:** Component A signals the Orchestrator; Orchestrator calls function on Component B. |
| 28 | |
| 29 | ## The Orchestrator Pattern |
| 30 | |
| 31 | The Root Node script (e.g., `LoginScreen.gd`, `UserProfile.gd`) is now an **Orchestrator**. |
| 32 | - **Math/Logic:** 0% |
| 33 | - **State Management:** 100% |
| 34 | - **Job:** Wire components together. Listen to Component signals and trigger other Component functions. |
| 35 | |
| 36 | ### Example: App/UI Context |
| 37 | |
| 38 | | Concept | App/UI Example | |
| 39 | |---------|----------------| |
| 40 | | **Orchestrator** | `UserProfile.gd` | |
| 41 | | **Component 1** | `AuthValidator` (Logic) | |
| 42 | | **Component 2** | `AuthVisualSyncer` (Visuals) | |
| 43 | | **Component 3** | `ThemeManager` (Visuals) | |
| 44 | |
| 45 | ## Implementation Standards |
| 46 | |
| 47 | ### 1. Type Safety |
| 48 | Define components globally. Never use dynamic typing for core architecture. |
| 49 | ```gdscript |
| 50 | # auth_component.gd |
| 51 | class_name AuthComponent extends Node |
| 52 | ``` |
| 53 | |
| 54 | ### 2. Dependency Injection |
| 55 | **NEVER** use `get_node("Path/To/Child")`. Paths are brittle. |
| 56 | **ALWAYS** use Typed Exports and drag-and-drop in the Inspector. |
| 57 | ```gdscript |
| 58 | # Orchestrator script |
| 59 | @export var auth: AuthComponent |
| 60 | @export var form_ui: Control |
| 61 | ``` |
| 62 | |
| 63 | ### 3. Scene Unique Names |
| 64 | If internal referencing within a scene is strictly necessary for the Orchestrator, use the `%` Unique Name feature. |
| 65 | ```gdscript |
| 66 | @onready var submit_btn = %SubmitButton |
| 67 | ``` |
| 68 | |
| 69 | ### 4. Stateless Components |
| 70 | Components should process the data given to them. |
| 71 | - **Bad:** `NetworkComponent` finds the username text field itself. |
| 72 | - **Good:** `NetworkComponent` has a function `login(username, password)`. The Orchestrator passes the text field data into that function. |
| 73 | |
| 74 | ## NEVER Do (Expert Architectural Rules) |
| 75 | |
| 76 | ### Hierarchy & Dependencies |
| 77 | - **NEVER use get_parent() to fetch data** — Components must be blind. If they need data, it must be injected via `@export` or passed into a function call. |
| 78 | - **NEVER talk sideways** — `ComponentA` must never call functions on `ComponentB`. High-coupling makes refactoring impossible. Always signal up to the Orchestrator. |
| 79 | - **NEVER use brittle Node Paths** — `get_node("Child/Subchild/Node")` breaks when you move a single node. Use `@export` and the Inspector. |
| 80 | |
| 81 | ### Logic & State |
| 82 | - **NEVER put business logic in the Orchestrator** — The Orchestrator should only have `_on_signal` methods that delegate to other components. |
| 83 | - **NEVER store global state in individual components** — Use a shared `Context` Resource or the Global Autoload for cross-scene state. |
| 84 | - **NEVER assume a component's parent is of a specific type** — If a `HealthComponent` requires its parent to be a `CharacterBody2D`, it fails the "Rock Test." |
| 85 | |
| 86 | ### Polish & Orchestration |
| 87 | - **NEVER skip signal cleanup** — Connecting signals dynamically without disconnecting can lead to memory leaks or multiple execution bugs. |
| 88 | - **NEVER let Logic know about Visuals** — A `CombatComponent` should never call `AnimationPlayer.play()`. It emits `attack_performed`, and a `Syncer` or `Orchestrator` handles the visual response. |
| 89 | |
| 90 | ## Godot 4.7: App UI |
| 91 | |
| 92 | - **Control offset transform** for non-destructive visual tweaks in tool UIs. |
| 93 | - Editor-style **searchable dropdowns** pattern applicable to in-app pickers. |
| 94 | |
| 95 | ## Code Structure Example (General App) |
| 96 | |
| 97 | ### Component: `clipboard_copier.gd` |
| 98 | `` |