Example: Develop a center application

更新时间:
复制 MD 格式

After completing the technical model design, you can start developing the shared capability center. This topic demonstrates how to develop a shared capability center using a BizWorks center application. A center application is one that is modeled, developed, deployed, and maintained on the BizWorks platform. The platform hosts the application's runtime and provides features like scaffold generation to accelerate development.

On the Application List page of the sample project, you can find the automatically created center application named Sample Commodity Center. The page lists the application's Code, Application Type, and Creation Time, and provides Edit Properties and Delete actions.

Click the application name Sample Commodity Center. The Application Overview page for version v1.0.0 of the sample project opens by default.

For more information, see View the overview of a center application.

Note

When creating a center application through the standard process, you also need to specify information such as the code repository and credentials. For more information, see Create and manage center applications. These steps are skipped because the sample application is automatically generated.

Manage models

On the Bounded Context page of the sample application, you can see that the application's bounded context is already associated with the Commodity Context. The code for the Commodity Context is Commodity, its business domain is Commodity Domain, and the associated version is v1.0.0 (In Development). You can perform the Change Version and Disassociate actions.

Model management allows you to change the bounded context and version associated with the application and continue adjusting the model. For more information, see Manage models.

Generate code

BizWorks provides a code generation feature. Based on the application's associated bounded context and data models, BizWorks generates corresponding interface definitions, interface implementations, domain service classes, aggregate roots, value objects, entity classes, data object classes, and Object-Relational Mapping (ORM) code. It also generates code for common create, read, update, and delete (CRUD) operations to simplify business activity development.

Note

In the sample application, you must complete the code generation step before you can proceed.

  1. On the Code Generation page of the sample application (Sample Commodity Center), click Code Generation. In the Code Generation panel, all required items are preconfigured, allowing you to click Generate Code directly. The panel includes sections such as Project Build Method, Basic Information, DDD Code Structure, Generated Code Structure, and Component Dependencies, with an Start Execution button at the bottom.

    The code generation for the sample application saves the generated scaffold to a new branch, uses MyBatis as the data ORM component, and defaults to a two-level module structure. For more information, see Generate code.

  2. On the Code Generation page, click Download Code in the Actions column for the newly generated branch. After downloading the code to your local machine, unzip it to view the code structure. The top of the page displays the Code Repository Information (Code Source Type, Code Group, and Code Repository Address), and the list below shows the generation status of the branch.

    Note

    For the sample application, you can only view the code by downloading it after generation. If you create a center application using the standard BizWorks process, you can open its code repository in your local IDE to view and edit the code after generation.

    • After you download and unzip the code, you will see that the top-level directories correspond to the bounded contexts and related components. The root directory contains folders such as APP-META, businesscapability-commoditypublish, businessdomain-commodity, and bw-demo-app-71b4a65d81-starter, as well as the pom.xml and settings.xml files.

    • Go to the businessdomain-commodity (Commodity Context) folder. Its structure follows the layering principles of Domain-Driven Design (DDD) architecture. The directory contains sub-module folders such as commodity-app, commodity-client, commodity-domain, commodity-entry, commodity-extensionpoint, and commodity-infrastructure.

      The roles of the modules are as follows:

      Module

      Responsibility

      Description

      Entry

      Core business entry point.

      Serves as the business entry point. If the application uses Spring Cloud, controllers are written in this module. The controllers call the underlying business logic to complete the process.

      App

      Business invocation entry point.

      The Entry layer invokes business logic by calling the App layer. The App layer is responsible for calling the business logic in the Domain layer and converting between Data Transfer Objects (DTOs) and domain entities.

      Domain

      Domain implementation layer: core business logic.

      The Domain layer contains the core business logic. After modeling, the business logic is implemented by using domain entities and domain services, which follows the rich domain model pattern.

      To make external calls, invoke the repository interfaces defined in the Domain layer. The Infrastructure layer handles the technical implementation of this external access.

      Infrastructure

      Infrastructure layer: responsible for technical implementation, such as accessing databases, caches, Remote Procedure Calls (RPCs), and message queues (MQs).

      The Domain layer implements business logic, and the Infrastructure layer implements the technical parts of this logic (such as persistence, RPC requests, sending MQ messages, or caching) through repository implementations.

      In addition to technical implementation, the Infrastructure layer defines Data Objects (DOs), converts between DOs and domain entities, and integrates and calls external service clients.

      Starter

      Application startup.

      A package for starting a standalone application that allows flexible changes to the startup method.

      Client

      Domain service interface definition.

      An SDK for external application integration, which simplifies capability invocation. The SDK defines domain service interfaces, DTOs for interface parameters and return values, interface error codes, and custom business exceptions.

      ExtensionPoint

      Responsible for extension point interface definition.

      An SDK for external application integration that allows for the implementation of custom business logic based on defined extension points.

Scan code and merge models

When designing and developing with BizWorks, you might need to modify a model after the code scaffold is generated. Returning to the model, making changes, and regenerating the scaffold can interrupt the development workflow and reduce efficiency. To address this issue, the platform provides two-way synchronization between metadata and code. Developers can use specific annotations to add, modify, or delete model metadata during development. After development is complete, developers can push their changes to the platform. The platform then merges these changes with its existing metadata to create the final, confirmed metadata.

Note

Because you do not have commit permissions for the sample application's code, you cannot try the code scanning and merging features. You can try these features by creating a new center application.

For more information, see Scan code and merge models.

Deploy a center application instance

During the development phase, after generating the code scaffold, developers proceed with detailed design and coding. After local development and unit testing, they need to deploy the modules as microservices for joint debugging in a container environment.

Since the sample application does not involve actual coding, this step is skipped. After generating the code, you can directly package and deploy the application to the development environment. BizWorks provides a basic CI/CD process and also supports integration with third-party DevOps products. This topic focuses on demonstrating how to deploy the center application using the built-in CI/CD feature.

  1. On the Application Deployment page of the sample application, you can see two sample environments that were created automatically: a Development Environment and a Production Environment. The page displays icons for four environment types, and each environment card has a Create Deployment Instance button.

    For information about how to create and manage environments, see Create and manage project environments.

  2. Click the Sample Development Environment card. In the New Instance Deployment - Deployment Configuration panel, configure the Code Branch (select the one created during code generation), Deployment Pipeline (only the default is available), and Resource Configuration (read-only), and then click Next. The panel also includes options for Select Application Version, Select Type, Deployment Strategy (defaults to rolling release), and Deployment Environment. The default resource quota is 0.5 CPU cores and 1024 MB of memory.

  3. In the New Instance Deployment - Deployment Configuration panel, advanced options such as Lifecycle Management, Environment Variables, Storage, Health Check, Application Monitoring, and Tags are not configurable. Click Start Deployment.

    Note

    The sample project has fixed limitations on pipeline selection and instance resource configuration. Therefore, advanced options such as Lifecycle Management, Environment Variables, and Storage are not configurable.

  4. Click the Sample Development Environment card where the deployment is in progress. In the Application Deployment Instance panel, find the deployment record in the Deployment History section with a Status of In Progress and click Logs in the Actions column to view the running status and detailed information of the current deployment. The top of the panel displays the Expected Pods and Current Pods. The Deployment History table below includes columns for ID, Type, Status, Operator, and Completion Time.

  5. Refresh the page. After the deployment Status changes to Deployment Succeeded, click the Sample Development Environment card. The invocation domain name for the application in this environment is now displayed in the Application Deployment Instance panel.

    Open the invocation domain name in a browser. You will see a "Hello BizWorks" page, which confirms that the sample application instance is accessible.

    Note
    • This invocation domain name was automatically created and its DNS configured when the sample project was activated, making it directly accessible. For more information about environments and their bound domain names, see Create and manage project environments.

    • The "Hello BizWorks" page is included only in the code generated for the sample application to guide you through this topic. This code and functionality are not included when you create a standard center application.

  6. Optional: To access the API, complete the API request URL with the access address of this application instance, use the default request body, and click Send. The API returns a 200 OK status and a JSON response body with code=200. The request path is /Commodity/SpuService/createSpu/v1. In the response, message and data are null, and success is true.

    Note

    This operation only demonstrates the API invocation process for the sample center application. Because only a code scaffold was generated, the deployed code does not contain any corresponding business logic.

    In addition to the features demonstrated, the deployment function for center applications also includes instance management and application monitoring. For more information, see the following documents: