Clean Front-End Architecture for Agile Development
By separating UI components from business logic using a clean, layered architecture inspired by DDD, Hexagonal and Clean Architecture, the article shows how React, zustand hooks, and strict data‑dependency rules reduce coupling, lower development cost, and make agile front‑end code easier to maintain and extend.
This article analyses the pain points of agile front‑end development, especially the high cost caused by tightly coupling UI components with business logic during frequent iterations.
It proposes a clean, layered architecture inspired by Domain‑Driven Design, Hexagonal/Onion architecture, and the Clean Architecture principles. The layers are:
Entities/Models : immutable business data structures.
Use Cases (Application layer) : business rules that operate on models.
Adapters (UI layer) : React components that consume the use‑case outputs.
The article demonstrates the approach with a concrete React example that includes an Account component, a CoinsFly animation component, a WithdrawDialog popup, and a Task component. The code is organized in models , server , and applications directories, and state is managed with zustand hooks.
import { create } from 'zustand';
interface IAccountModel { account: number; }
const accountModel = create
(() => ({ account: undefined }));
export default accountModel;Business services fetch data and update the model:
const accountServer = {
getData() {
setTimeout(() => {
accountModel.setState({ account: 12.34 });
}, 1000);
}
};
export default accountServer;The UI component initializes the application and consumes the reactive model:
import accountApplication from '@/dataArea/home/applications/account';
import accountModel from '@/dataArea/home/models/account';
const Account = () => {
accountApplication.init();
const account = accountModel(state => state.account);
return (
{account}元
);
};
export default Account;Interaction logic such as showing the coin‑fly animation or opening the withdraw dialog is handled by the Task component, which triggers the popup through a shared popApplication and refreshes the account data after the dialog closes.
Key design guidelines highlighted include:
Separate concerns: UI only consumes data, never contains business logic.
Data dependency rules: outer layers consume inner layer data, never the opposite.
Use hooks to encapsulate state and expose it to any component.
Keep components low‑coupling and high‑cohesion.
By applying these principles, the development cost of iterative features is reduced, and the codebase becomes easier to maintain and extend.
DaTaobao Tech
Official account of DaTaobao Technology
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.