DDDplus Framework Documentation

repository·master·Indexed 22 days ago

https://github.com/funkygao/cp-ddd-framework

A lightweight DDD enhancement framework supporting forward modeling with patched building blocks and reverse modeling via AST parsing. It includes a Reverse Modeling DSL, an Architecture Guard using DDDPlusEnforcer for pattern validation, and a plugin system for dynamic business extensions. The framework provides a registry for discovering Spring beans annotated with @DomainService, @Pattern, and @Policy to manage complex system architecture evolution.

Tokens
6.6K
Snippets
17
Records
32
Agent score
78%

What's inside DDDplus

  1. What is DDDplus?

    master

    DDDplus is a lightweight Domain-Driven Design (DDD) framework designed for both forward and reverse business modeling. It aims to support the evolution of complex business systems by bridging the gap between code and business models.

    Key capabilities include:

    • Expanded DDD Building Blocks: Provides additional constructs to solve common difficulties in implementing DDD.
    • Reverse Modeling via DSL: Uses a Domain Specific Language (DSL) for declarative annotations, allowing code to be visualized as complete business models through static analysis.
    • Extension Points: Supports multiple routing patterns to handle complex business scenarios.
    • Unified Language: Connects architects, product managers, and developers by making code a visual representation of business knowledge.
  2. Identify when to decouple or couple components

    master

    When designing a system architecture, use the following criteria to decide between decoupling and coupling:

    Seek Decoupling when:

    • Business functions are different.
    • Code change patterns are different.
    • Scalability requirements differ.
    • Fault tolerance requirements differ.
    • Data security requirements differ.

    Coupling is necessary when:

    • Database transactions are required.
    • Data dependencies exist.
    • Workflow orchestration is required.
  3. Core concepts of Business Modeling

    master

    Business Modeling describes the objects, elements, behaviors, attributes, and relationships within an enterprise. Key concepts include:

    Generalized Contract

    Includes protocols, consensus, promises, and agreements that require fulfillment. The lifecycle consists of: Inquiry (询价) → Quotation (报价) → Contract Signing (合同签订) → Fulfillment (履约). Note that activities before signing lack legal effect. Fulfillment produces evidence (凭证) to prove obligations were met.

    Business Process

    A business process is a chain of responsibility transfers. It consists of four hierarchical layers:

    1. Domain (领域)
    2. Business (业务)
    3. Process (流程)
    4. Activity (活动): The basic unit of business function description.

    Domain Knowledge

    Encompasses domain background, domain business (processes, objects, rules), domain technology, and domain personnel.

    Business Rules

    Constraints on business processes. Types include:

    • Constraint Rules (约束性规则): Mandatory (e.g., laws, policies).
    • Normative Rules (规范性规则): Should be followed (e.g., industry standards, internal regulations).
    • Recommended Rules (推荐性规则): Suggestions (e.g., best practices).
    • Conditional Rules (条件性规则): Applicable only under specific conditions (e.g., promotions).
  4. Understand the boundaries of coupling

    master

    Coupling can be categorized across two axes: Technology vs. Business and Static vs. Dynamic.

    • Static Coupling (Compile time): Occurs at the technology level.
    • Dynamic Coupling (Runtime): Occurs at the technology level.
    • Logic Coupling (Feature): Occurs at the business level and is explicit.
    • Semantic Coupling (Contract): Occurs at the business level and is implicit.
  5. Quickstart: Reverse Modeling for Legacy Systems

    master

    Reverse modeling is independent of forward modeling. You can use it on legacy systems to extract business insights, restore architectural designs, and identify design flaws by using AST (Abstract Syntax Tree) static analysis.

    1. Add the dddplus-visualization dependency.
    2. Annotate your code using the DDDplus DSL.
    3. Run the Maven plugin to generate multi-perspective views (e.g., PlantUML or text models).
    <!-- Maven Dependency -->
    <dependency>
        <groupId>io.github.dddplus</groupId>
        <artifactId>dddplus-visualization</artifactId>
    </dependency>
    
    <!-- Maven Plugin Command to generate models -->
    mvn io.github.dddplus:dddplus-maven-plugin:model \
        -DrootDir=${colon separated source code dirs} \
        -DplantUml=${target business model in svg format} \
        -DtextModel=${target business model in txt format}
  6. Quickstart: Reverse Modeling with DDDplus

    master

    Reverse modeling visualizes complete domain knowledge from your existing code by parsing the AST.

    1. Add the dddplus-spec dependency to your project.
    2. Annotate your code using the DDDplus DSL.
    3. Use the dddplus-maven-plugin to render the domain model in multiple views (e.g., PlantUML SVG or text format).
    <!-- Maven Dependency -->
    <dependency>
        <groupId>io.github.dddplus</groupId>
        <artifactId>dddplus-spec</artifactId>
    </dependency>
    
    <!-- Maven Plugin Command to render models -->
    mvn io.github.dddplus:dddplus-maven-plugin:model \
        -DrootDir=${colon separated source code dirs} \
        -DplantUml=${target business model in svg format} \
        -DtextModel=${target business model in txt format}
  7. Quickstart: Forward Modeling with DDDplus

    master

    Forward modeling allows you to build domain models using patched DDD building blocks. To use DDDplus for forward modeling, add the dddplus-runtime dependency to your project.

    Spring Boot Integration

    To integrate with Spring Boot, ensure that your @SpringBootApplication scans both your base packages and the io.github.dddplus package.

    <!-- Maven Dependency -->
    <dependency>
        <groupId>io.github.dddplus</groupId>
        <artifactId>dddplus-runtime</artifactId>
    </dependency>
    
    <!-- Spring Boot Integration -->
    @SpringBootApplication(scanBasePackages = {"${your base packages}", "io.github.dddplus"})
    public class Application {
        public static void main(String[] args) {
            SpringApplication.run(Application.class);
        }
    }
  8. Quickstart: Forward Modeling with Spring Boot

    master

    To use DDDplus for forward modeling (building business models through code), add the dddplus-runtime dependency to your project. If you are using Spring Boot, ensure that the DDDplus packages are included in your component scanning.

    <!-- Maven Dependency -->
    <dependency>
        <groupId>io.github.dddplus</groupId>
        <artifactId>dddplus-runtime</artifactId>
    </dependency>
    
    <!-- Spring Boot Integration -->
    @SpringBootApplication(scanBasePackages = {"${your base packages}", "io.github.dddplus"})
    public class WebApplication {
        public static void main(String[] args) {
            SpringApplication.run(WebApplication.class, args);
        }
    }
  9. Access the Reverse Modeling DSL API documentation

    master

    For detailed technical specifications, class hierarchies, and method signatures of the Reverse Modeling DSL, refer to the official Javadoc. This documentation provides the complete API surface for interacting with the DSL components.

    https://funkygao.github.io/cp-ddd-framework/doc/apidocs/io/github/dddplus/dsl/package-summary.html
  10. Apply the Business Modeling methodology

    master

    The DDDplus methodology follows these guiding principles:

    Guiding Principles

    • Abstract elements (抽象要素)
    • Clarify relationships (理清关系)
    • Find patterns/laws (寻找规律)

    Model Layering

    1. Conceptual Model (概念模型)
    2. Logical Model (逻辑模型)
    3. Physical Model (物理模型)

    The Two Flows

    • Business Flow (业务流)
    • Data Flow (数据流)

    Prerequisites for Business Reuse

    To reuse a business component, ensure:

    • Business Reusability: The business has inherent generality.
    • Standardization: The business follows clear standards.
    • Technical Support: Availability of standardized interfaces or APIs.
    • Organizational Support: A culture and strategy for reuse.
    • Business Management: Versioning, permission, and security management.
  11. Resolve business rule conflicts

    master

    When business rules conflict due to complexity, poor design, imperfect implementation, or data quality issues, use these strategies:

    1. Priority Ranking (优先级排序): Set high-priority rules to override low-priority ones (e.g., a 'ship in 3 days' rule overrides a 'ship in 5 days' rule).
    2. Rule Merging (规则合并): Combine contradictory rules into a new, unified rule (e.g., requiring partial address at order time and full address before shipping).
    3. Rule Nesting (规则嵌套): Nest specific rules within general rules (e.g., nesting a local government holiday promotion rule inside a general corporate coupon restriction rule).
    4. Rule Adjustment (规则调整): Modify rules to ensure legality, effectiveness, and fairness if other methods fail.