What you'll learn: By the end of this lesson you will be able to say what changes when a front end is built by many teams over many years, split a large code base into layers with one-way dependency rules, assign ownership to paths, decide which surfaces need a published contract, enforce those rules with tools instead of review comments, and describe the trade-offs between one deployable app, a monorepo of several apps and micro-frontends.
Think of a city. A village needs no zoning: a shed built in the wrong place is settled over the fence. A city has districts, shared utilities, building codes checked by inspectors, and a map of who is responsible for which road. Without those, many builders working at once produce a tangle.
A front end built by one team in one year is a village; one that dozens of teams change for a decade is a city. Enterprise frontend architecture is the set of decisions that keep the second one workable: how the code is divided, who may depend on what, who is responsible for each part, and how those rules are enforced when nobody is watching.
The running example is the storefront of a grocery marketplace: a checkout app, an account app and a support console, built by separate teams. Every number in this lesson is illustrative.
The core idea
- Scale changes the problem from writing code to coordinating changes. The hard part is no longer a component; it is a hundred changes by people who never meet.
- Structure is dependency rules. Dividing code into layers only helps if the allowed direction of dependency is written down and checked.
- Every path has an owner and every shared surface has a contract. An owner is who is asked; a contract is what they promise not to break.
- Rules that depend on memory decay. A rule enforced by a linter, a required check or an ownership file survives staff changes. A rule in a wiki page does not.
What changes at enterprise scale
The button does not change; the number of people, the lifetime and the cost of being wrong do.
| Pressure | What it looks like | Architectural response |
|---|---|---|
| Many teams | Two teams edit the same files and block each other | Clear ownership of paths and layers |
| Many apps | The same login form exists in four versions | Shared packages with a contract |
| Long lifetime | The person who understood a module has left | Dependency rules and documented decisions, not folklore |
| Different pace | One app upgrades weekly, another yearly | Versioned surfaces and a support window |
| Compliance and audit | Someone must show who approved a change | Required reviews and a trail of checks |
None of these says "use micro-frontends". The deployment shape is one decision among several, and Monolith vs Micro-Frontends covers it. This lesson is about what holds in any shape.
Layers and one-way dependencies
A useful split for a large front end has four layers, from the most specific to the most general. The names are one common choice, not a standard.
- Apps assemble pages and routes and own what ships to users.
- Features are a vertical slice of business functionality, such as a basket or a payment form, with their own state and data access.
- UI is the shared component library: buttons, fields, tabs, with no business knowledge. Component Library Architecture describes how to build it.
- Utilities are pure helpers such as formatting, dates and validation, with no UI and no network.
The rule that makes this a structure rather than a folder naming scheme is the direction: an app may use a feature, a feature may use UI, UI may use utilities, and never the other way. A utility that imports an app is a cycle waiting to happen, and a feature that imports another feature has silently tied two teams' release plans together.
Figure 1. Four layers, one direction
How to read this: an arrow means "is allowed to import". There is no arrow back, and none between two features. The two zones show who answers when something in them breaks; the platform-owned layers change slowly and are used by everyone.
Checking the rules with a tool
A rule that is checked in code review is checked unevenly. Workspace tools can check it for you. Nx's enforce-module-boundaries lint rule is a concrete example: you give each project tags in its configuration (the Nx documentation uses scope:client, scope:admin and scope:shared), and a depConstraints list says, for a sourceTag, which tags it may depend on with onlyDependOnLibsWithTags. A project that imports outside its allowance is reported as an error. The documentation's reason is blunt: if all projects can depend on each other freely, "chaos will ensue".
You do not need Nx for the idea; here is the minimum in plain Node.
Illustration 1: the minimal example
Each package has one layer, each layer lists the layers it may use, and a list of imports is checked against it. The package names are made up:
const layerOf = {
"app-checkout": "app",
"app-account": "app",
"feature-basket": "feature",
"feature-payment": "feature",
"ui-kit": "ui",
"format-utils": "util",
};
const mayDependOn = {
app: ["feature", "ui", "util"],
feature: ["ui", "util"],
ui: ["util"],
util: [],
};
const imports = [
["app-checkout", "feature-basket"],
["app-checkout", "feature-payment"],
["feature-basket", "ui-kit"],
["feature-payment", "format-utils"],
["feature-payment", "feature-basket"],
["ui-kit", "format-utils"],
["format-utils", "app-account"],
];
for (const [from, to] of imports) {
const ok = mayDependOn[layerOf[from]].includes(layerOf[to]);
console.log(ok ? "ok " : "FAIL ", from, `(${layerOf[from]})`, "->", to, `(${layerOf[to]})`);
}
Output, from running it in Node 26.13.1:
ok app-checkout (app) -> feature-basket (feature)
ok app-checkout (app) -> feature-payment (feature)
ok feature-basket (feature) -> ui-kit (ui)
ok feature-payment (feature) -> format-utils (util)
FAIL feature-payment (feature) -> feature-basket (feature)
ok ui-kit (ui) -> format-utils (util)
FAIL format-utils (util) -> app-account (app)
Two imports fail. The payment feature uses the basket feature directly, which couples two teams. A utility reaches up into an app, which is how a cycle starts. Both are easy to write by accident and hard to see in a diff. In a real workspace the same table is the configuration of a lint rule and the check runs on every pull request. The script is the idea, not an Nx implementation.
Ownership of paths
A boundary says what may depend on what. Ownership says who decides. In a repository hosted on GitHub, a CODEOWNERS file maps path patterns to people or teams. GitHub's documentation says the file can live in .github/, the root or docs/, that the last matching pattern takes precedence, that owners are requested for review automatically when a pull request touches their files, and that owners need write permission. Combined with a branch protection rule that requires review from code owners, an owner's approval becomes a condition of merging, and an approval from any one of several listed owners is enough.
This gives a reviewer an address, which is the real point. The question "who should look at this change to the payment feature" has a mechanical answer, so it does not depend on who remembers. Monorepos and Shared Libraries covers how such a repository is laid out.
Contract surfaces
Some code is called by people you will never meet in a meeting. Those surfaces need a contract: a declared set of things you may rely on, and a rule for changing them.
- The UI library's exports. Names, props and defaults. Design System Governance and Versioning says how to classify changes.
- Shared configuration. A lint or TypeScript preset used by every app. ESLint's documentation describes a shareable config as an npm package that exports a configuration object or array, and recommends names such as
@scope/eslint-config. A preset is a package like any other: changing a rule is a change to everyone. - The runtime seams between apps, if you have micro-frontends: URLs, events, a shared session. See Independent Deployment and Shared Dependencies.
- Calls to back-end APIs. See API Contract Evolution for Clients.
Semantic Versioning gives a vocabulary for the change rules: it requires software to declare a public API, and defines MAJOR as an incompatible API change, MINOR as added functionality in a backward compatible manner and PATCH as a backward compatible bug fix. Which parts of a front-end package are its public API is a decision you have to make and write down.
Figure 2. Where contracts sit
How to read this: each arrow crossing from one owner to another is a place where a change by one team can break another. Those are the arrows that need a written promise and an automatic check.
One app, many apps, or micro-frontends
The structure above works in several deployment shapes. Choosing among them is a separate decision.
| Shape | Deploy unit | Team independence | Main cost |
|---|---|---|---|
| One modular app | One | Low to medium; shared release | Release coordination grows with teams |
| Monorepo, several apps | One per app | Medium; shared libraries, separate releases | Tooling for a large repository |
| Micro-frontends | One per slice, composed at build or run time | High, at the price of runtime seams | Duplication, version skew, a harder end-to-end view |
Martin Fowler's article on micro-frontends defines them as an architectural style where independently deliverable frontend applications are composed into a greater whole, and advises organising teams around vertical slices of business functionality rather than technical concerns. A modular monolith with enforced boundaries gets many of the same ownership benefits at lower cost, and is also the best starting point if you later split. Micro-Frontends and Conway's Law discusses how team structure drives the choice.
Illustration 2: the realistic example
The storefront becomes a workspace with three apps (checkout, account, support) and packages: a UI library, a few features, utilities and a shared lint preset. An ownership file maps each app and feature to a team and the UI library and presets to a small platform group. A pipeline (see CI/CD for Front Ends) runs the boundary check and the tests of affected packages on every pull request, and required checks block a merge when one fails. The workspace itself is ordinary: pnpm describes a workspace as projects whose directories are listed under packages in pnpm-workspace.yaml, and npm describes a workspaces property in the root package.json that links each package into node_modules.
Illustration 3: a failure, in miniature
The support console needs a currency formatter that already exists in the checkout feature. A developer imports it from there, and it works. Months later the checkout team moves the formatter and renames it. The support console build breaks, on the day of a checkout release. The import was allowed because no rule forbade it. The fix is a rule: shared code goes down into the utility layer, a feature is never imported across apps, and the boundary check fails the pull request that tries.
Trade-offs
| Choice | Gain | Cost |
|---|---|---|
| Strict layer rules | Predictable dependencies, safe moves | Some code must be pushed down to a shared layer |
| Ownership file with required review | A named reviewer for every path | Slower merges when owners are busy or the map is stale |
| Shared packages with contracts | Reuse and consistency | Every change has a release process |
| Monorepo | One place, one toolchain, atomic changes | Tooling and build time must scale |
| Micro-frontends | Independent delivery | Runtime seams, duplication, version skew |
Build it
This lesson has no lab: the decisions are about structure and ownership, and the small Node script above is the whole mechanism. It needs no install. A paper exercise:
- List the packages of a front end you know and give each a layer.
- Write the
mayDependOntable and run the check over the real imports. - For each failure, decide whether to move the code down or change the rule.
In practice: splitting a growing storefront
This is a realistic scenario, not a case history. It is a composite built from common patterns. It describes no specific company, and every number in it is an illustrative assumption.
The situation
The storefront is one repository with one app and about forty developers in six teams. Pull requests wait for review from whoever is free, a change to a shared helper breaks pages in other teams, and a release needs a meeting. Leadership asks whether to move to micro-frontends.
Starting architecture
Figure 3. One app, folders without rules
How to read this: the warning boxes are the two coupling points: any file may import any other, and every change ships in the same release.
Options considered
| Option | What it fixes | What it costs | Risk |
|---|---|---|---|
| Split into micro-frontends now | Release independence | Runtime composition, shared dependencies, new tooling | A distributed system before the boundaries are known |
| Modular workspace with enforced layers and owners | Review and coupling problems | Moving code, writing rules | Rules ignored if not enforced |
| Do nothing, add reviewers | Nothing structural | Cheap | The same pains return |
The decision
| Field | Decision record |
|---|---|
| Context | Review waits, cross-team breakage and coupled releases in one app. |
| Decision | Move to a workspace with four layers, an ownership file and a boundary check as a required status check. Keep one deployable app for now. Revisit splitting when a team's release cadence is blocked by others even with clean boundaries. |
| Consequences, good | Named reviewers; cross-team imports fail early; any slice can later become its own app. |
| Consequences, bad | Several weeks of moving code; the platform group must maintain the rules. |
| Revisit when | Release coordination, not code coupling, is the main cost. |
Figure 4. After the decision: one app, enforced layers, named owners
How to read this: a change reaches the app only through the two accent boxes, the automatic check and the named reviewer. That path, not a document, is what carries the rules.
Rollout and verification
- Write the layer table and run the check in report-only mode to see how many violations exist.
- Fix by moving code down, team by team, and then turn the check into a required status check.
- Add the ownership file and require code-owner review on the main branch.
- Verify by trying a forbidden import on a throwaway branch and confirming the pipeline fails it.
The 2 a.m. failure
A hurried hotfix adds an import from one feature to another to meet a deadline, and the author, with admin rights, merges around the check. Next morning the checkout and payment features cannot be released independently, and a failed payment deploy blocks checkout too.
First three checks: (1) which pull request introduced the import, and whether the required check was bypassed; (2) which packages now depend on each other; (3) whether the same bypass exists on other branches. Mitigation: revert the import or move the shared code down a layer. Follow-up: restrict bypass to a named group and log its use.
Architect's notes
- Start with the dependency table, not the folder names. Folders follow from it.
- Prefer a modular app with enforced boundaries before a distributed one. It teaches you where the real seams are.
- Every shared surface needs a name, an owner and a change rule. If it has none of the three, it is an accident.
- Make the right thing the checked thing. A required check changes behaviour in a way a wiki page does not.
Common mistakes
- Folders as architecture. Directories with no import rule are decoration.
- Features that import features. The most common hidden coupling.
- Ownership files that nobody maintains. A stale map sends reviews to people who left.
- A shared package with no public API. Everything becomes an API by accident.
- Choosing micro-frontends to fix a code-organisation problem.
Key takeaways
- Scale turns the main problem into coordinating changes between teams.
- Layers only help when the allowed dependency direction is written down and checked.
- Give every path an owner and every shared surface a contract and a change rule.
- Enforce rules with lint, required checks and ownership files, not memory.
- A modular app with enforced boundaries is a strong default; micro-frontends are a deployment decision on top.
Practice exercises
Exercise 1: Starter (30 min). Add a fifth layer, platform (auth, telemetry), to the script. Decide which layers may use it and rerun the check.
Exercise 2: Intermediate (2 hours). Extend the script to find import cycles in the list, and explain why a layer rule already prevents most of them.
Exercise 3: Advanced (half day). For a repository you know, draft the ownership file and list three paths where ownership is unclear.
Related reading
In this course:
- Monolith vs Micro-Frontends: when a split pays for itself.
- Design Systems and Accessibility: the shared UI layer and its accessibility duties.
- Component Library Architecture: the UI layer's own structure.
- Design System Governance and Versioning: the contract for a shared library.
- Monorepos and Shared Libraries: the repository that holds all this.
- CI/CD for Front Ends: the pipeline that enforces it.
Official documentation
- Martin Fowler: Micro Frontends: the definition and the vertical-slice advice.
- Nx: Enforce Module Boundaries: tags and dependency constraints as a lint rule.
- GitHub: About code owners: ownership files and review requests.
- GitHub: About protected branches: required reviews and status checks.
- pnpm: Workspace and npm: Workspaces: how a multi-package repository is declared.
- Semantic Versioning 2.0.0: the vocabulary for change rules.