How hector-rubio-tabares/dem-astro works
1. This is a pnpm monorepo for a microfrontend demo, centered on three apps: an Astro shell, a React microfrontend, and an Angular microfrontend. The repo also contains a shared TypeScript package for cross-app primitives, plus a small script for syncing built remote assets into the shell.
2. The architectural boundary is clear: apps/portfolio-shell-astro is the host/orchestrator, while apps/portfolio-react-mf and apps/portfolio-angular-mf are independently built remotes. The shell is the only user entrypoint; the remotes are loaded into it at runtime rather than navigated to directly in the intended flow.
3. The shell is the control plane. Its src/pages/*.astro pages define the shell routes, and src/scripts/demo-hot.ts appears to be the main runtime orchestrator for loading and coordinating remotes. Supporting scripts include mf-loader.ts for remote loading, mf-runtime.ts for runtime helpers, and message-validator.ts / event-bus.ts for communication and safety.
4. The React microfrontend is a Vite-based app with a dedicated federation entrypoint at src/mf-entry.tsx. That entrypoint suggests it can be exposed both as a normal standalone app and as a remote module. src/ErrorBoundary.tsx indicates local error isolation inside the MF boundary.
5. The Angular microfrontend is a standalone Angular app configured through angular.json, federation.config.js, and the standard src/main.ts / src/app/* structure. Its presence alongside a federation config indicates it is also prepared to be consumed as a remote, even if the federation support is more experimental than React’s.
6. The shared package packages/mf-shared is the main cross-cutting dependency layer. It contains event-bus.ts, message-validator.ts, context.ts, strategies.ts, types.ts, and an index.ts barrel export. This is the repo’s type-safe contract layer for message shapes, event routing, and shared runtime behavior across shell and remotes.
7. Communication is the second major subsystem after loading. The README and file names point to two channels: same-tab messaging through an in-memory EventBus, and multi-tab messaging through browser-native BroadcastChannel. The shell owns the coordination logic, while the remotes publish events into the shared communication layer.
8. Security and resilience are built into the architecture rather than left to the UI layer. Message validation lives in dedicated validator modules, and the repo includes an error-handler.ts in Angular plus ErrorBoundary.tsx in React to prevent one remote from taking down the whole shell. The README also emphasizes origin validation and sanitization, which implies the loader/runtime boundary is treated as an attack surface.
9. Build and deploy flow is split between source apps and static remote artifacts. apps/portfolio-shell-astro/public/mf/... contains built JavaScript/CSS assets for the remotes, which means the shell can serve remote bundles locally or in a packaged form. The root scripts/sync-remotes.mjs likely copies built remote outputs into that public directory so the shell can load them consistently.
10. The runtime topology in dev is three local servers: Astro on one port for the host, React on another for its MF build, and Angular on a third. The shell then dynamically loads the remote bundles from those origins or from synced static assets, making the browser the integration point where the independent apps are composed.
11. Testing is concentrated around the shared runtime and messaging layer rather than UI snapshots. The shell has test files for event-bus and message-validator, which suggests the highest-value correctness boundary is the cross-app protocol, not the individual visual components.
12. For an architecture diagram, the important boxes are: monorepo/workspace at the top; shell host in the center; React and Angular remotes as separate runtime producers; mf-shared as the contract library; and browser-native channels (EventBus and BroadcastChannel) as the communication paths. The most important arrows are shell-to-remote loading, remote-to-shared-contract imports, and bidirectional event flow between all three apps.
Main entry points: demo-hot.ts Demo runtime · portfolio-react-mf React MF · portfolio-angular-mf Angular MF · mf-shared mf-shared
Components 18
Workspace
pnpm monorepo boundary
- Monorepo · Root workspace and dependency graph
Apps
Host and microfrontends
- Astro shell · Single user entrypoint and runtime control plane
apps/portfolio-shell-astro - Shell pages · Route-level pages that mount the microfrontend demo
apps/portfolio-shell-astro/src/pages - Demo runtime · Coordinates remote loading and demo flow
apps/portfolio-shell-astro/src/scripts/demo-hot.ts - MF loader · Loads remote bundles into the shell
apps/portfolio-shell-astro/src/scripts/mf-loader.ts - MF runtime · Shared shell-side helpers for remote composition
apps/portfolio-shell-astro/src/scripts/mf-runtime.ts - Shell bus · Message validation and in-memory event routing
apps/portfolio-shell-astro/src/scripts/event-bus.test.ts - Synced remotes · Built remote artifacts served by the shell
apps/portfolio-shell-astro/public/mf - React MF · Vite-based remote microfrontend
apps/portfolio-react-mf - MF entry · Remote exposure entry used by the shell
apps/portfolio-react-mf/src/mf-entry.tsx - React boundary · Local error boundary for remote resilience
apps/portfolio-react-mf/src/ErrorBoundary.tsx - Angular MF · Standalone Angular microfrontend prepared for federation
apps/portfolio-angular-mf - Angular app · Angular app bootstrap and component layer
apps/portfolio-angular-mf/src/app - Error handler · Angular-side error handling boundary
apps/portfolio-angular-mf/src/app/error-handler.ts
Shared
Cross-app contract layer
- mf-shared · Cross-app contract and runtime primitives
packages/mf-shared - Contracts · Message shapes, context, and strategy definitions
packages/mf-shared/src/types.ts - Bus + validation · Event bus and message validation shared across apps
packages/mf-shared/src/event-bus.ts
Scripts
Repo automation
- Sync remotes · Copies built remote outputs into the shell
scripts/sync-remotes.mjs
Connections 25
- Monorepo → Astro shell: contains · Workspace includes the Astro host
- Monorepo → React MF: contains · Workspace includes the React remote
- Monorepo → Angular MF: contains · Workspace includes the Angular remote
- Monorepo → mf-shared: contains · Workspace includes the shared package
- Monorepo → Sync remotes: contains · Workspace includes remote sync automation
- Astro shell → Shell pages: routes · Shell pages define entry routes
- Shell pages → Demo runtime: boots · Pages initialize the demo runtime
- Demo runtime → MF loader: loads · Runtime delegates remote loading
- Demo runtime → MF runtime: uses · Runtime uses helper utilities
- MF loader → Synced remotes: serves · Loads synced remote bundles from shell public assets
- Sync remotes → Synced remotes: copies · Build script syncs remote outputs into the shell
- Demo runtime → React MF: mounts · Shell composes the React remote at runtime
- Demo runtime → Angular MF: mounts · Shell composes the Angular remote at runtime
- React MF → MF entry: exposes · Federation entrypoint for remote consumption
- React MF → React boundary: isolates · React remote wraps local failures
- Angular MF → Angular app: bootstraps · Angular app structure provides the remote UI
- Angular MF → Error handler: handles · Angular remote adds local error handling
- Astro shell → mf-shared: imports · Host consumes shared contracts and helpers
- React MF → mf-shared: imports · React remote depends on shared primitives
- Angular MF → mf-shared: imports · Angular remote depends on shared primitives
- mf-shared → Contracts: defines · Shared package publishes message and context types
- mf-shared → Bus + validation: implements · Shared package provides bus and validation logic
- Demo runtime → Bus + validation: coordinates · Shell centralizes event routing and validation
- React MF → Bus + validation: publishes · React remote emits events into the shared layer
- Angular MF → Bus + validation: publishes · Angular remote emits events into the shared layer