COLA 2.0: Redefining Java Backend Architecture with Layered Design & Extensible Components

This article explains how the COLA 2.0 framework restructures Java backend applications by introducing a cleaner layered architecture, redefining components and modules, adding flexible extension points, and providing practical guidance for generating and using COLA‑based services.

Alibaba Cloud Developer
Alibaba Cloud Developer
Alibaba Cloud Developer
COLA 2.0: Redefining Java Backend Architecture with Layered Design & Extensible Components

COLA 2.0 Overview

COLA (Context‑Oriented Lightweight Architecture) is an application‑level framework created by Alibaba senior technical expert Zhang Jianfei to provide a practical, reproducible architecture that controls complexity while remaining understandable and maintainable.

Motivation

Developers often encounter chaotic application hierarchies, unclear component responsibilities, and lack of naming conventions. COLA was created to address these pain points by offering concrete guidelines and constraints.

Key Evolution from 1.0 to 2.0

New Layering: The Domain layer no longer directly depends on the Infrastructure layer; a Gateway concept is introduced, applying the Dependency Inversion Principle.

Component Re‑definition: Components are reorganized, new ones added, and obsolete ones (e.g., Validator, Convertor) removed.

New Extension Points: Additional concepts make extensions more flexible.

Re‑positioned Second‑Party Libraries: They now serve not only as DTOs but also as lightweight Domain Model representations.

Benefits of the New Layering

Domain code becomes pure business logic, free from technical details, enabling parallel development and easier unit testing (TDD).

Component and Module Definitions

In Java, a Component corresponds to a package, while a Module corresponds to a Maven artifact (JAR). A module consists of multiple components.

<modules>
    <module>cola-common</module>
    <module>cola-core</module>
    <module>cola-extension</module>
    <module>cola-test</module>
</modules>

COLA 2.0 Components

Second‑Party Library Components

api – external interfaces

dto.domainmodel – lightweight domain objects for data transfer

dto.domainevent – domain events

Application Layer

service – facade without business logic, can host adapters

eventhandler – processes domain events

executor – handles commands and queries, supports phases and steps

interceptor – AOP handling for all requests

Domain Layer

domain – domain entities (can extend domainmodel)

domainservice – coarse‑grained domain capabilities

gateway – interfaces for external dependencies (storage, RPC, search)

Infrastructure Layer

config – configuration information

message – message handling

repository – CRUD operations, specialization of gateway

gateway – implementation of external gateway interfaces

New Extension Design

COLA 2.0 introduces three concepts for extension: Business (e.g., tmall, taobao), Use Case (e.g., order payment), and Scenario (specific instances such as VIP payment). This three‑level model enables fine‑grained, flexible extensions.

In practice, a user can declare an extension with @Extension(bizId="tmall", useCase="placeOrder", scenario="88vip") to target a precise scenario.

Second‑Party Library Re‑positioning

Beyond simple DTOs, second‑party libraries can expose lightweight domain models that encapsulate both data and behavior, acting as a shared kernel for reusable business logic while still allowing isolation via wrappers when needed.

Extension Mechanisms

COLA supports two extension styles:

Interface‑based extensions: Define an interface in the framework and let users implement it (e.g., ExceptionHandlerI).

Data‑configuration extensions: Use annotations or configuration files to bind data to extension points.

Getting Started with COLA 2.0

COLA provides two Maven archetypes:

mvn archetype:generate -DgroupId=com.alibaba.demo -DartifactId=demo -Dversion=1.0.0-SNAPSHOT -Dpackage=com.alibaba.demo -DarchetypeArtifactId=cola-framework-archetype-service -DarchetypeGroupId=com.alibaba.cola -DarchetypeVersion=2.1.0-SNAPSHOT

For a web‑backed service, use the cola-framework-archetype-web archetype.

Generated projects contain demo code that can be tested with mvn test or run as a Spring Boot application.

Architecture Views

COLA 2.0 includes dependency and call graphs (images omitted for brevity) that illustrate the overall structure of a COLA‑based application.

COLA project structure
COLA project structure
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaDomain-Driven DesignExtension PointsCOLA framework
Alibaba Cloud Developer
Written by

Alibaba Cloud Developer

Alibaba's official tech channel, featuring all of its technology innovations.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.