← Back to Blog

Dec 1, 2026

Code Governance Across Architectural Styles with DDD

A practical account of code governance drawn from refactoring a product center: how governance differs from refactoring, where DDD code complexity comes from, how to govern code, and what to watch for from the Servlet/JSP era through microservices and mobile.

DDD Domain ModelingDDDCode GovernanceRefactoringCOLACoding StandardsCode Review

1. Background

1.1 Context

I have been refactoring my company’s product center as part of a broader move toward component-based services. We inherited it from another team: features were incomplete, several people had contributed, and coding styles were inconsistent. That made maintenance and componentization difficult.

I led the first two phases of the redesign, drawing on DDD and COLA. During that work, code governance began to look like a topic in its own right, rather than simply another name for refactoring. This chapter explores the relationship between governance, refactoring, and improving code smells.

1.2 Governance Versus Refactoring

Refactoring usually starts from a specific problem: existing code needs improvement, perhaps because it cannot support a new feature cleanly. Governance also covers the beginning of a project and its ongoing evolution.

Its scope includes code, scripts, comments, and closely related documentation. Refactoring improves something toward a particular goal; governance establishes conventions and practices intended to keep the project at a consistently high standard. In that sense, governance includes refactoring.

1.3 Governance and Coding Standards

Governance needs standards to work from, but not every convention must be mandatory in every situation. Some guidelines are advisory, while others require enforcement. Governance uses those conventions to improve both code and documentation. Without shared standards, the activity is closer to isolated refactoring or modification.

2. Software Complexity in DDD Code

2.1 Business Call Chains

  1. End-to-end call chains are too long.
  2. Internal calls take too much time.
  3. Similar capabilities repeat the same call chains.
  4. Call chains create performance or comprehension problems.

2.2 Code Layers

  1. Too many layers.
  2. Too few layers.
  3. A class or method is too long and carries too many responsibilities.
  4. Code freely references models and methods from other layers.
  5. Inconsistent styles undermine the layering and its management.

2.3 Models and Services

  1. Complex generalization, composition, and aggregation relationships.
  2. Multiple levels of service inheritance and scenario-specific logic.
  3. Model conversion between layers, such as BO/DO and BO/DTO.
  4. Serialization between database tables and DO/entity/RPC models.
  5. Models that are too minimal.
  6. Tight coupling to too many upstream, downstream, internal, or external systems.

2.4 Processes

  1. Interactions within a thread.
  2. Interactions with external business processes.
  3. Interactions with middleware processes.

3. Code Governance

3.1 What It Means

Code governance manages the code and scripts developers write, including test code. Think of organizing a room or kitchen: what should each item be called, how should it be used, where does it belong, how should it evolve, and how can it be moved without breaking its users?

It also covers coding style, names, service interfaces, packages, and modules.

3.2 Where Problems Arise

The following diagram collects lessons from the product-center refactoring and several years of development, including mistakes I have made and inconsistencies introduced through collaboration.

Mind map of where code problems arise: interfaces and classes, interface naming systems, and other common code smells

3.3 Benefits

What does governance improve, and where does the value come from? This mind map summarizes the benefits.

Mind map of the benefits of code governance: easier reading, easier refactoring, easier extension, easier integration, easier maintenance

3.4 What to Govern

  1. By code type: enums, interfaces, constants, abstract classes, configuration, exceptions, and implementations.

What code to govern, by type: enums, interfaces, constants, abstractions, configuration, exceptions, and implementations

  1. By framework: the classes, models, and entry points associated with each framework.

What code to govern, by framework: common class suffixes used by Dubbo, Spring MVC, Struts 2, Hibernate, Spring Boot/Cloud, and MyBatis

  1. By module responsibility: infrastructure, domain, RPC interface, HTTP interface, and application modules.

What code to govern, by module responsibility: class suffixes in the infrastructure, domain, RPC interface, HTTP interface service, and application layers

3.5 How to Govern Code

Mind map of how to govern code: style and conventions, code review, documentation, refactoring, version management, code content, and testing

3.6 How This Relates to DDD

DDD introduces concepts and patterns that become confusing if their code representations are not maintained. Domain entity names and distinctions between entities and value objects are examples.

A project might represent domain entities with XXXBO, value objects with XXXEnum or XXXConfig, and infrastructure implementations with XXXAdapter, XXXMapper, or XXXRepoImpl. Under those conventions, a DTO appearing where a domain model is expected deserves scrutiny. If one developer calls a domain object a DTO and another calls the same kind of object a BO, the vocabulary becomes inconsistent.

DDD therefore needs code governance and coding conventions to remain effective in complex systems. Whatever the architectural style, modules and packages have responsibilities and dependency relationships. For large projects, I recommend repeated design reviews and code reviews at the implementation level.

4. Governance Across Development Styles

4.1 Servlet/JSP

In early web applications built with Servlets and JSP, filenames often reflected CRUD operations or modules. Business logic and call chains could be tangled; a JSP might query a database directly. Frontend assets were also embedded in JSP files, mixing concerns further.

4.2 Spring MVC

The SSH stack—Struts, Spring, and Hibernate—was widely used in this period, alongside custom frameworks. Integrating three frameworks with different conventions and responsibilities still left governance and layering problems. For small and medium-sized projects, however, their module structures could provide useful guidance.

4.3 RPC and Separate Web Frontends

As frontend and backend development became fully separated, their codebases became more specialized and somewhat easier to govern. Some management applications still kept frontend and backend code in one project, though.

4.4 Microservices

Microservices involve RPC, HTTP, messaging, and many other interaction patterns. Both the business and the technology are more complex, and the full chain from clients to backend systems crosses many layers. Governance becomes especially important: a performance problem or bug in one segment of a critical path can trigger cascading failures.

4.5 Android and iOS

My recent work has focused on backend development, so I do not have enough direct experience to cover governance on these platforms. Contributions from readers would be welcome.

5. Summary

As long as people write code and requirements change, code governance remains necessary. Like other forms of governance, it requires proactive work, sound judgment, and a balance between improving what exists and maintaining its usefulness.

The goal is better project structure and readability, fewer potential bugs and performance problems, and easier extension. Done well, it also improves engineering efficiency.

I have collected further references on code and module governance below.

6. References

Comments

Comments are powered by GitHub Discussions. Sign in with GitHub to join the discussion.