# Model the Domain with State Machines and Data Structures

Encode domain logic in data structures like state machines, typed models, or maps to eliminate invalid states and reduce conditional branching.

**Canonical URL:** https://skillshunter.net/skills/discovered-cc0cf12064e2b8706e329886926f20010965b68763b8af0e

**JSON URL:** https://skillshunter.net/api/public/v1/skills/discovered-cc0cf12064e2b8706e329886926f20010965b68763b8af0e

**Markdown URL:** https://skillshunter.net/skills/discovered-cc0cf12064e2b8706e329886926f20010965b68763b8af0e.md

**Instructions download URL:** https://skillshunter.net/skills/discovered-cc0cf12064e2b8706e329886926f20010965b68763b8af0e/download

**Category:** Software & Development

**Source URL:** https://github.com/jueyi6/empstack/blob/74181e31d2f00313f8683ba157966efcabbe109e/skills/principle-model-the-domain/SKILL.md

**Source commit:** 74181e31d2f00313f8683ba157966efcabbe109e

**Listing approved at:** 2026-12-02

**Created at:** 2026-11-30T08:56:21.000000Z

**Updated at:** 2026-12-02T09:15:14.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

This approach is best suited for stateful or heavily branching logic. Consider using a state machine when adding new branches would otherwise increase conditional complexity.

### When to use it

- Replacing scattered booleans with a state machine to manage complex state transitions
- Using typed models to replace loose parameters in complex logic
- Replacing branching logic across files with a centralized map or registry

## Skill instructions

---
name: principle-model-the-domain
description: For stateful or heavily branching logic, use a state machine or table.
disable-model-invocation: true
---

# Model the Domain

Encode the domain in a data structure instead of scattering it across conditionals. The right structure makes invalid states unrepresentable and deletes branches.

Reach for a state machine instead of scattered booleans or phase checks, a typed model instead of loose parameters, a map, registry, or discriminated union instead of branching spread across files, a reducer instead of ad hoc mutations, and an index, queue, or normalized collection where the access pattern calls for it.

Do not force it. Keep boring code when the shape is clear, local, and unlikely to grow, and distrust an abstraction that adds indirection without removing branches or invalid states.

The sign that you skipped this: a feature that grows an if/else chain by one more branch, or a second boolean that must stay in sync with the first.

