Skip to main content

Domain Modelling

Available in product edition: Professional

To implement the designed domain within the NestJS stack, AI coding assistants are utilized to generate code based on your design specifications. This approach provides:

  • Design-Driven Code Generation: Code is generated based on your Solution Designer models
  • Rapid Development: Accelerate implementation while maintaining quality
  • Flexible Patterns: Support for various DDD patterns and architectural decisions
Important Disclaimer

The quality of generated code depends entirely on the AI coding assistant's capabilities and training data. Always review, test and validate AI-generated code before using it in production. The design files provide context, but the final code quality and correctness are the responsibility of the developer.

ℹ️Domain Modelling Implementation

Unlike other extensions (API Modelling, Integration Modelling), domain modelling does not generate any components in the k5 SDK. The complete domain implementation must be provided manually in your project using AI coding assistants and the prompts provided below.

AI Coding Assistant Prompts

To effectively implement domain modelling with AI assistance, use the following specialized prompts. These prompts are designed to work with AI coding assistants like Cursor IDE and GitHub Copilot to generate consistent, design-compliant code.

Entity Implementation

Create classes for one entity and dependent items
Based on the design files, create a class with properties for entity <EntityXYZ> including all not existing entities that it is relying on.
Create classes for all entities of a namespace
Based on the design files, create classes with properties for all entities defined in namespace <NamespaceXYZ>.
List discrepancies between design and current implementation
Based on the entity design files, list all places where the current implementation doesn't match.
Ensure alignment of entity implementation with design specification
Make sure existing entities and their properties align with design files.

For one entity:

Make sure entity <EntityXYZ> and it's properties align with design files.

Data Persistence

Implement data persistence for root entities
Based on the design files, implement data persistence for all root entities of domain namespace <NamespaceXYZ>.

Business Logic Implementation

Implement commands of an entity
Implement all commands of entity <EntityXYZ> as methods on the entity.

If you want to make sure that only directly associated commands are implemented you can add the following:

Ignore the parent commands.
Implement all commands of a namespace
Implement all commands defined in namespace <NamespaceXYZ> as methods on the entities. Make sure you implement them according to the described implementation logic.
Implement one domain service
Implement domain service <ServiceXYZ> as separate service class.
Implement all services of a namespace
Based on the service design files, implement all domain services of namespace <NamespaceXYZ>. Make sure you implement them according to the described implementation logic.
List discrepancies between design and current implementation
Based on the command and domain service design files and their described implementation logic, list all places where the current implementation doesn't match.
Ensure alignment of current implementation with design specification
Make sure existing command and domain service implementations align with design files.

For one command:

Make sure command <CommandXYZ> aligns with design files.

For one service:

Make sure service <ServiceXYZ> aligns with design files.

Best Practices

Design File Maintenance

  • Keep design files up-to-date with domain changes
  • Ensure design files accurately reflect current business requirements
  • Use consistent naming conventions and patterns in design specifications

AI Assistant Usage

  • Provide design files as context for all coding sessions
  • Use domain-specific prompts for consistent results
  • Regularly validate generated code against design specifications
  • Iterate on implementations while maintaining design compliance

Domain Implementation

  • Follow Domain-Driven Design principles
  • Keep domain logic separate from infrastructure concerns
  • Use dependency injection for better testability
  • Implement proper error handling and validation

Code Quality

  • Always review AI-generated code before committing
  • Write comprehensive tests for domain logic
  • Use TypeScript's type system effectively
  • Follow NestJS best practices and patterns

This approach enables you to leverage AI coding assistants in a sustainable, design-compliant manner while implementing robust domain models that follow DDD principles.