nw-fp-domain-modeling
FeaturedDomain modeling with algebraic data types, smart constructors, and type-level error handling
AI & Automation 636 stars
68 forks Updated today MIT
Install
Quality Score: 98/100
Stars 20%
Recency 20%
Frontmatter 20%
Documentation 15%
Issue Health 10%
License 10%
Description 5%
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
- 9 months ago
- Last Updated
- today
- Language
- Python
- License
- MIT
Similar Skills
Semantically similar based on skill content — not just same category
AI & Automation Listed
functional-modeling-with-algebraic-types
Use when designing domain types, when a record has many optional fields, or when choosing between a record, a union, and a bare primitive.
3 Updated yesterday
yutna DevOps & Infrastructure Featured
nw-fp-principles
Core functional programming thinking patterns and type system foundations, language-agnostic
636 Updated today
nWave-ai AI & Automation Featured
nw-fp-fsharp
F# language-specific patterns, Railway-Oriented Programming, and Computation Expressions
636 Updated today
nWave-ai