
game-architecture
Game architecture patterns and best practices for browser games. Use when designing game systems, planning architecture, structuring a game project, or making architectural decisions about game code.
- Installs
- 1.2K
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/playableintelligence/game-creator --skill game-architecture- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads game-architecture automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Game Architecture Patterns
Reference knowledge for building well-structured browser games. These patterns apply to both Three.js (3D) and Phaser (2D) games.
Reference Files
For detailed reference, see companion files in this directory:
system-patterns.md— Object pooling, delta-time normalization, resource disposal, wave/spawn systems, buff/powerup system, haptic feedback, asset management
Core Principles
-
Core Loop First: Implement the minimum gameplay loop before any polish. The order is: input -> movement -> fail condition -> scoring -> restart. Only after the core loop works should you add visuals, audio, or juice. Keep initial scope small: 1 scene/level, 1 mechanic, 1 fail condition.
-
Event-Driven Communication: Modules never import each other for communication. All cross-module messaging goes through a singleton EventBus with predefined event constants.
-
Centralized State: A single GameState singleton holds all game state. Systems read state directly and modify it through events. No scattered state across modules.
-
Configuration Centralization: Every magic number, balance value, asset path, spawn point, and timing value goes in
Constants.js. Game logic files contain zero hardcoded values. -
Orchestrator Pattern: One
Game.jsclass initializes all systems, manages game flow (boot -> gameplay -> death/win -> restart), and runs the main loop. Systems don't self-initialize. No title screen by default — boot directly into gameplay. Only add a title/menu scene if the user explicitly asks for one. -
Restart-Safe and Deterministic: Gameplay must survive full restart cycles cleanly.
GameState.reset()restores a complete clean slate. All event listeners are removed in cleanup/shutdown. No stale references, lingering timers, leaked tweens, or orphaned physics bodies survive across restarts. Test by restarting 3x in a row — the third run must behave identically to the first. -
Clear Separation of Concerns: Code is organized into functional layers:
core/- Foundation (Game, EventBus, GameState, Constants)systems/- Engine-level systems (input, physics, audio, particles)gameplay/- Game mechanics (player, enemies, weapons, scoring)level/- World building (level construction, asset loading)ui/- Interface (menus, HUD, overlays)
Event System Design
Event Naming Convention
Use domain:action format grouped by feature area:
export const Events = {
// Player
PLAYER_DAMAGED: 'player:damaged',
PLAYER_HEALED: 'player:healed',
PLAYER_DIED: 'player:died',
// Enemy
ENEMY_SPAWNED: 'enemy:spawned',
ENEMY_KILLED: 'enemy:killed',
// Game flow
GAME_STARTED: 'game:started',
GAME_PAUSED: 'game:paused',
GAME_OVER: 'game:over',
// System
ASSETS_LOADED: 'assets:loaded',
LOADING_PROGRESS: 'loading:progress'
};
Event Data Contracts
Always pass structured data objects, never primitives:
// Good
eventBus.emit(Events.PLAYER_DAMAGED, { amount: 10, source: 'enemy', damageType: 'melee' });
// Bad
eventBus.emit(Events.PLAYER_DAMAGED, 10);
State Management
GameState Structure
Organize state into clear domains:
class GameState {
constructor() {
this.player = { health, maxHealth, speed, inventory, buffs };
this.combat = { killCount, waveNumber, score };
this.game = { started, paused, isPlaying };
}
}
Game Flow
Standard flow for both 2D and 3D games:
Boot/Load -> Gameplay <-> Pause Menu (if requested)
-> Game Over -> Gameplay (restart)
No title screen by default. Games boot directly into gameplay. The Play.fun widget handles score display, leaderboards, and wallet connect in a deadzone at the top of the game, so no in-game score HUD is needed. Only add a title/menu scene if the user explicitly requests one.
Common Architecture Pitfalls
- Unwired physics bodies — Creating a static physics body (e.g., ground, wall) without wiring it to other bodies via
physics.add.collider()orphysics.add.overlap()has no gameplay effect. Every boundary or obstacle needs explicit collision wiring to the entities it should interact with. After creating any static body, immediately add the collider call. - Interactive elements blocked by overlapping display objects — When building UI (buttons, menus), the topmost display object in the scene list receives pointer events. Never hide the interactive element behind a decorative layer. Either make the visual element itself interactive, or ensure nothing is rendered on top of the hit area.
- Polish before gameplay — Adding particles, screen shake, and transitions before the core loop works is a common time sink. Get input -> action -> fail condition -> scoring -> restart working first. Everything else is polish.
- No cleanup on restart — Forgetting to remove event listeners, destroy timers, and dispose resources in
shutdown()causes ghost behavior, double-firing events, and memory leaks after restart.
Pre-Ship Validation Checklist
Before considering a game complete, verify all items:
- Core loop — Player can start, play, lose/win, and see the result
- Restart — Works cleanly 3x in a row with identical behavior
- Mobile input — Touch/tap/swipe/gyro works; 44px minimum tap targets
- Desktop input — Keyboard + mouse works
- Responsive — Canvas resizes correctly on window resize
- Constants — Zero hardcoded magic numbers in game logic
- EventBus — No direct cross-module imports for communication
- Cleanup — All listeners removed in shutdown, resources disposed
- Mute toggle — See
mute-buttonrule - Delta-based — All movement uses delta time, not frame count
- Build —
npm run buildsucceeds with no errors - No errors — No uncaught exceptions or console errors at runtime
FAQ
What does the game-architecture skill do?
Game architecture patterns and best practices for browser games. Use when designing game systems, planning architecture, structuring a game project, or making architectural decisions about game code.
How do I install game-architecture?
Run npx skills add https://github.com/playableintelligence/game-creator --skill game-architecture in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/game-architecture/ (personal) or .claude/skills/game-architecture/ (project).
Which AI agents can use game-architecture?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is game-architecture safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains game-architecture?
It is published by playableintelligence in playableintelligence/game-creator. It has 1,204 recorded installs.
More from playableintelligence/game-creator
game-designer
playableintelligence/game-creator
Game UI/UX designer that analyzes and improves the visual polish, atmosphere, and player experience of browser games. Use when a game needs visual improvements, better backgrounds, particles, animations, screen transitions, juice/feel, or overall aesthetic upgrades.
game-assets
playableintelligence/game-creator
Game asset engineer that creates pixel art sprites, animated characters, and visual entities for browser games. Use when a game needs better character art, enemy sprites, item visuals, or any upgrade from basic geometric shapes to recognizable pixel art.
design-game
playableintelligence/game-creator
Audit and improve the visual design, polish, and player experience of an existing game. Use when the user says "make my game look better", "improve the design", "add polish", "add juice", "add particles", "fix the UI", or "make it more visually appealing". Do NOT use for gameplay logic changes (use add-feature instead).
phaser
playableintelligence/game-creator
Build 2D browser games with Phaser 3 using scene-based architecture and centralized state. Use when creating a new 2D game, adding 2D game features, working with Phaser, or building sprite-based web games.
game-audio
playableintelligence/game-creator
Game audio engineer using Web Audio API for procedural music and sound effects in browser games. Zero dependencies. Use when adding music or SFX to a game.
threejs-game
playableintelligence/game-creator
Build 3D browser games with Three.js using event-driven modular architecture. Use when creating a new 3D game, adding 3D game features, setting up Three.js scenes, or working on any Three.js game project.
Popular code quality & workflow skills
grill-me
mattpocock/skills
A relentless interview to sharpen a plan or design.
improve-codebase-architecture
mattpocock/skills
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
handoff
mattpocock/skills
Compact the current conversation into a handoff document for another agent to pick up.
domain-modeling
mattpocock/skills
Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.
codebase-design
mattpocock/skills
Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.
diagnosing-bugs
mattpocock/skills
Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.