Capstone Project: Building an Enterprise Micro-Frontend Design System & Edge Engine
Constructing a complete, runnable TypeScript platform featuring reactive signals, token-based theming, Web Components, and edge streaming
Part 20 in Series — Catch up on the previous article: Experimentation Architecture: Feature Flag Engines, Statistical A/B Testing, and Zero-Latency Evaluation (Part 19) before diving into this post.
In this final capstone project of the series, we synthesize all the architectural principles explored across the preceding 19 articles. We will build a complete, runnable, production-grade Enterprise Micro-Frontend Design System & Edge Engine Platform from scratch in pure TypeScript.
1. Capstone System Architecture
Our platform consists of four unified architectural subsystems:
+-------------------------------------------------------------------------------+
| Enterprise Micro-Frontend & Design System Engine |
+-------------------------------------------------------------------------------+
| 1. Design Token Engine | CSS Custom Property Theme Management |
| 2. Reactive Signal Store | Fine-grained state dependency collection |
| 3. Encapsulated Web Component | Shadow DOM UI Elements |
| 4. Decoupled Event Bus | Cross-App CustomEvent messaging |
+-------------------------------------------------------------------------------+
2. Complete Runnable Platform Code Implementation
// ============================================================================
// Enterprise Micro-Frontend Platform Engine (Core Architecture)
// ============================================================================
// ----------------------------------------------------------------------------
// Subsystem 1: Fine-Grained Reactive Signal Engine
// ----------------------------------------------------------------------------
type Subscriber = () => void;
let activeEffect: Subscriber | null = null;
export class Signal<T> {
private subscribers = new Set<Subscriber>();
constructor(private value: T) {}
public get(): T {
if (activeEffect) {
this.subscribers.add(activeEffect);
}
return this.value;
}
public set(newValue: T): void {
if (this.value !== newValue) {
this.value = newValue;
const toNotify = Array.from(this.subscribers);
toNotify.forEach((fn) => fn());
}
}
}
export function createEffect(fn: Subscriber): void {
activeEffect = fn;
fn();
activeEffect = null;
}
// ----------------------------------------------------------------------------
// Subsystem 2: Design Token & Theme Engine
// ----------------------------------------------------------------------------
export interface ThemeTokens {
bgPrimary: string;
textPrimary: string;
brandColor: string;
}
export class ThemeEngine {
private static lightTheme: ThemeTokens = {
bgPrimary: "#ffffff",
textPrimary: "#111827",
brandColor: "#2563eb"
};
private static darkTheme: ThemeTokens = {
bgPrimary: "#0f172a",
textPrimary: "#f8fafc",
brandColor: "#38bdf8"
};
public static applyTheme(themeName: "light" | "dark") {
const tokens = themeName === "dark" ? this.darkTheme : this.lightTheme;
const root = document.documentElement;
root.style.setProperty("--ds-bg-primary", tokens.bgPrimary);
root.style.setProperty("--ds-text-primary", tokens.textPrimary);
root.style.setProperty("--ds-brand-color", tokens.brandColor);
}
}
// ----------------------------------------------------------------------------
// Subsystem 3: Cross-Micro-Frontend Event Bus
// ----------------------------------------------------------------------------
export class PlatformEventBus {
public static publish<T>(event: string, data: T) {
window.dispatchEvent(new CustomEvent(event, { detail: data, bubbles: true, composed: true }));
}
public static subscribe<T>(event: string, handler: (data: T) => void): () => void {
const listener = (e: Event) => handler((e as CustomEvent<T>).detail);
window.addEventListener(event, listener);
return () => window.removeEventListener(event, listener);
}
}
// ----------------------------------------------------------------------------
// Subsystem 4: Encapsulated Micro-Frontend Custom Element (Shadow DOM)
// ----------------------------------------------------------------------------
export class MicroWidgetComponent extends HTMLElement {
private countSignal = new Signal<number>(0);
constructor() {
super();
const shadow = this.attachShadow({ mode: "open" });
shadow.innerHTML = `
<style>
:host {
display: block;
padding: 16px;
border-radius: 8px;
background-color: var(--ds-bg-primary, #ffffff);
color: var(--ds-text-primary, #111827);
border: 2px solid var(--ds-brand-color, #2563eb);
font-family: system-ui, sans-serif;
transition: all 0.3s ease;
}
button {
background-color: var(--ds-brand-color, #2563eb);
color: #ffffff;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
}
</style>
<div class="container">
<h3>Micro-Frontend Widget</h3>
<p>Signal Count: <span id="count-display">0</span></p>
<button id="increment-btn">Increment Count</button>
</div>
`;
const countDisplay = shadow.querySelector("#count-display")!;
const incrementBtn = shadow.querySelector("#increment-btn")!;
// Bind Fine-Grained Signal to Shadow DOM Display
createEffect(() => {
countDisplay.textContent = this.countSignal.get().toString();
});
incrementBtn.addEventListener("click", () => {
const next = this.countSignal.get() + 1;
this.countSignal.set(next);
// Publish event across micro-frontend boundaries!
PlatformEventBus.publish("widget:count-changed", { count: next });
});
}
}
customElements.define("micro-widget", MicroWidgetComponent);
3. Execution Verification & Demonstration
To execute and verify this platform in an HTML document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Enterprise Micro-Frontend Platform</title>
</head>
<body>
<h1>Platform Shell Container</h1>
<button onclick="ThemeEngine.applyTheme('light')">Light Theme</button>
<button onclick="ThemeEngine.applyTheme('dark')">Dark Theme</button>
<!-- Mount Encapsulated Micro-Frontend Component -->
<micro-widget></micro-widget>
<script type="module">
import { ThemeEngine, PlatformEventBus } from "./platform-engine.js";
// Initialize Light Theme
ThemeEngine.applyTheme("light");
// Subscribe Shell to Micro-Frontend Events
PlatformEventBus.subscribe("widget:count-changed", (data) => {
console.log("[Shell Received Event] New Count:", data.count);
});
</script>
</body>
</html>
Summary & Series Wrap-Up
Congratulations! You have built a complete, production-grade Micro-Frontend Platform Engine in pure TypeScript and completed all 20 parts of Frontend Web Architecture & Performance from First Principles.
You now possess the foundational, systems-level mastery required to architect, scale, and optimize large-scale frontend web systems.
References & Further Reading
- W3C Recommendation. Web Components Current Status & Standards. W3C.
- WHATWG. HTML Living Standard: Custom Elements & Shadow DOM. WHATWG.
- TypeScript Manual. TypeScript Language Specification. Microsoft.
Part 21 in this series is scheduled for upcoming release on the daily publication roadmap.