nw-fp-domain-modeling

Solid

Domain modeling with algebraic data types, smart constructors, and type-level error handling

AI & Automation 526 stars 55 forks Updated 1 weeks ago MIT

Install

View on GitHub

Quality Score: 95/100

Stars 20%
91
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# FP Domain Modeling Domain modeling with types. Make illegal states unrepresentable, workflows as pipelines, error handling at the type level. Cross-references: [fp-principles](../nw-fp-principles/SKILL.md) | [fp-hexagonal-architecture](../nw-fp-hexagonal-architecture/SKILL.md) | [fp-algebra-driven-design](../nw-fp-algebra-driven-design/SKILL.md) --- ## 1. The Two Building Blocks [STARTER] All domain types compose from two operations: - **AND (Record Types)**: Value has ALL of these fields. Order requires CustomerInfo AND ShippingAddress AND OrderLines. - **OR (Choice Types)**: Value is ONE OF these alternatives. ProductCode is either WidgetCode OR GizmoCode. Combined recursively, these express virtually any domain structure. --- ## 2. Domain Wrappers for Primitives [STARTER] Never use primitives directly in the domain model. Each domain concept gets its own wrapper type. **What**: Wrap primitives so the compiler distinguishes CustomerId from OrderId. **When**: Every primitive with domain meaning. **Why**: Prevents accidental mixing (compiler rejects comparing CustomerId with OrderId). Each wrapper carries its own validation rules. The type name IS the documentation. --- ## 3. Validated Construction (Smart Constructors) [STARTER] Raw constructor is private. A `create` function validates input and returns a Result type, making validation failure explicit. **Pattern**: UnitQuantity must be between 1 and 1000. Its `create` function rejects values outside that ...

Details

Author
nWave-ai
Repository
nWave-ai/nWave
Created
3 months ago
Last Updated
1 weeks ago
Language
Python
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category