koan-data-modeling

Define aggregate-first domain models with lifecycle hooks and value objects in Koan Framework.

4|3|Updated Aug 18, 2025
One-click install
npx skills add https://github.com/sylin-org/koan-framework --skill koan-data-modeling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: koan-data-modeling
Source: https://github.com/sylin-org/koan-framework/tree/main/.claude/skills/data-modeling
Command: npx skills add https://github.com/sylin-org/koan-framework --skill koan-data-modeling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Designing effective data models that encapsulate business logic, manage relationships, and enforce invariants can be complex. This Skill provides a clear, aggregate-first approach to data modeling within Koan Framework, simplifying domain-driven design.

Core Features & Use Cases

  • Aggregate Boundaries: Define entities as aggregates that encapsulate their own business logic and maintain internal consistency.
  • Value Objects: Use immutable value objects (e.g., Money, Address) to represent cohesive data, improving type safety and reducing errors.
  • Lifecycle Hooks: Enforce business rules and invariants by hooking into entity lifecycle events (before save, after load, etc.).
  • Navigation Helpers: Easily define and traverse relationships between entities using simple foreign keys and helper methods, without complex ORM mapping.
  • Use Case: Model an Order entity as an aggregate, ensuring its Total and Status are updated through business methods, not direct property assignments. Use a Money value object for currency, and define a lifecycle hook to prevent negative prices for Product entities.

Quick Start

To define an Order entity with a Money value object and a navigation helper: public record Money(decimal Amount, string Currency); public class Order : Entity<Order> { public string CustomerId { get; set; } = ""; public Money Total { get; private set; } = new(0m, "USD"); public Task<Customer?> GetCustomer() => Customer.Get(CustomerId); }

Frequently Asked Questions about koan-data-modeling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define entity relationships and enforce business logic in domain-driven design?

Domain-driven design uses aggregates to encapsulate entities and their business logic. Define aggregate boundaries, apply lifecycle hooks to enforce invariants, use value objects for cohesive data like currency, and add navigation helpers to traverse relationships between entities without complex ORM mapping.

What's the difference between entities and value objects in data modeling?

Entities have unique identities and lifecycle states; value objects are immutable and identified only by their attributes. Use value objects (e.g., Money, Address) for cohesive, type-safe data. Entities like Order aggregate multiple value objects and enforce business rules through lifecycle hooks and methods.

How do lifecycle hooks help maintain data consistency in aggregates?

Lifecycle hooks execute during entity lifecycle events—before save, after load—allowing you to enforce business rules and invariants automatically. For example, prevent negative prices on products or update aggregate totals whenever related entities change, ensuring data consistency without manual checks.

Can I use domain-driven design patterns without a complex ORM?

Yes. Define navigation helpers using simple foreign keys and helper methods to traverse relationships between entities. This approach provides relationship management and data validation without requiring complex ORM mapping, keeping your domain model focused on business logic.

What problems does aggregate-first data modeling solve?

Aggregate-first modeling simplifies domain design by grouping related entities, enforcing invariants through lifecycle hooks, managing relationships with navigation helpers, and handling cross-cutting concerns like soft deletes and audit trails—all while keeping business logic encapsulated and maintainable.