Document an architecture trade-off
Make an architecture decision explicit
An architecture decision record (ADR) is a short dated record of context, alternatives, a choice, its consequences and a trigger for reconsideration. It should explain the problem rather than declaring a favorite folder structure. Example ADR: the fictional dashboard has two developers, one release schedule, and no independent deployment requirement. Choose a modular application with feature directories, a shared UI layer and one release. Alternatives: a simple layered application (less initial scaffolding) or separately deployed microfrontends (additional runtime and integration costs). Revisit if teams require independently controlled releases and can demonstrate compatibility, observability and rollback. This is a proposed decision, not a measured organizational outcome.
export const modules = [ {id:'App',layer:'app',imports:['OrdersRoute','OrderService']}, {id:'OrdersRoute',layer:'feature',imports:['OrderSummary','selectOrders']}, {id:'OrderSummary',layer:'feature',imports:['summarizeOrders']}, {id:'selectOrders',layer:'domain',imports:[]}, {id:'summarizeOrders',layer:'domain',imports:[]}, {id:'OrderService',layer:'data',imports:[]}];The declared graph records the local fixture’s application, feature, domain and data relationships. External packages such as React are not included. In a real repository generate the graph from actual resolved imports (including aliases, re-exports and supported dynamic imports); a manually maintained graph is not proof of enforcement. In a monorepo, explicit package exports and dependency constraints make public APIs clearer. Exports are a package interface, not a security sandbox.
// A small policy over declared module identities, not an import parser.const allowed={app:['feature','data','ui'],feature:['domain','ui','data'],data:['domain'],domain:[],ui:[]};export function checkGraph(modules) { const byId=new Map(modules.map(m=>[m.id,m])); if(byId.size!==modules.length) throw new Error('Duplicate module'); const problems=[]; for(const m of modules){ if(!Object.hasOwn(allowed,m.layer)) throw new Error('Unknown layer'); for(const id of m.imports){ const target=byId.get(id); if(!target) problems.push(`Missing: ${m.id} -> ${id}`); else if(m.layer!==target.layer && !allowed[m.layer].includes(target.layer)) problems.push(`Forbidden: ${m.id} -> ${id}`); } } const active=new Set(),done=new Set(); function visit(id){ if(active.has(id)){problems.push(`Cycle at ${id}`);return;} if(done.has(id)||!byId.has(id))return; active.add(id); for(const next of byId.get(id).imports)visit(next); active.delete(id);done.add(id); } for(const id of byId.keys())visit(id); return problems;}The teaching policy allows app to compose features and adapters, features to consume lower-level modules, and domain and generic UI to avoid cross-layer dependencies. Same-layer imports are allowed unless cyclic. Missing nodes, reverse dependencies and cycles produce findings. The supplied graph yields an empty list. This recursive traversal is intended for small declared fixtures; a real linter must resolve actual paths and handle large graphs safely. Add checks in CI after the actual graph extraction is verified.
Decide whether independent deployment is justified
export function integrationDecision({independentDeployments, autonomousTeams, sharedRuntimeVerified, rollbackVerified, remoteTrustVerified}) { const gaps=[]; if(!independentDeployments)gaps.push('Independent deployment need'); if(!autonomousTeams)gaps.push('Clear team ownership'); if(!sharedRuntimeVerified)gaps.push('Compatible shared runtime'); if(!rollbackVerified)gaps.push('Integrated rollback'); if(!remoteTrustVerified)gaps.push('Trusted artifact delivery'); return {choice:gaps.length?'modular-app':'evaluate-microfrontends',gaps};}This is a qualitative checklist, not a scoring model. Even if every prerequisite is true it returns evaluate-microfrontends rather than recommending immediate adoption. Module federation can allow independently built modules to integrate at runtime, but host/remote compatibility, React and renderer sharing, shared context, routing, authentication, deployment ordering, error isolation and trusted artifact delivery need explicit testing. Remote JavaScript runs with the privileges of its execution environment; never load arbitrary remote code. A modular application may be simpler and cheaper to operate. Progressive refactoring: first extract a pure domain function, then isolate the adapter, introduce a public feature entry point, move callers incrementally and preserve behavior with tests. Use unit tests for domain rules, integration tests for service contracts, component tests for route interactions and end-to-end tests for actual navigation and deployment. Practice: write an ADR for a second feature and create a forbidden reverse dependency to verify the checker.