{"data":{"slug":"discovered-cc0cf12064e2b8706e329886926f20010965b68763b8af0e","title":"Model the Domain with State Machines and Data Structures","summary":"Encode domain logic in data structures like state machines, typed models, or maps to eliminate invalid states and reduce conditional branching.","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","download_url":"https:\/\/skillshunter.net\/skills\/discovered-cc0cf12064e2b8706e329886926f20010965b68763b8af0e\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_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.","instructions":"---\nname: principle-model-the-domain\ndescription: For stateful or heavily branching logic, use a state machine or table.\ndisable-model-invocation: true\n---\n\n# Model the Domain\n\nEncode the domain in a data structure instead of scattering it across conditionals. The right structure makes invalid states unrepresentable and deletes branches.\n\nReach 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.\n\nDo 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.\n\nThe 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.\n","use_cases":["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"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/jueyi6\/empstack\/blob\/74181e31d2f00313f8683ba157966efcabbe109e\/skills\/principle-model-the-domain\/SKILL.md","source_commit":"74181e31d2f00313f8683ba157966efcabbe109e","license":null,"version":null,"listing_approved_at":"2026-12-02","created_at":"2026-11-30T08:56:21.000000Z","updated_at":"2026-12-02T09:15:14.000000Z","seo_title":"Model Domain Logic with State Machines and Data Structures","seo_description":"Encode domain logic in data structures to eliminate invalid states and reduce conditional branching, improving maintainability and clarity.","seo_keywords":["domain modeling","state machine","data structure","invalid states","conditional branching"]}}