Micro front ends — overview
How Luna's Module Federation setup works: the host, the remotes it federates in, and how to wire up a new microfrontend (MFE). The source of truth for the exact configuration is always clients/luna-front-end/vite.config.js (the host) and the MFE's own vite.config.js — this page explains the shape so you can read those files with context.
Module Federation (@module-federation/vite) lets independently built and deployed apps share code and dependencies at runtime. Luna uses it to run a micro frontend architecture: one host app plus several independently developed and deployed microfrontends that are federated into it in the browser.
Host and remotes
- Host app —
luna-front-end, the Module Federation host namedlunaCore. It's the entry point users land on and it federates in every MFE. - Remote apps (MFEs) — independent clients that expose components to the host. Folder names end
-mfa(e.g.kudos-mfa,admin-mfa,stable-apps-mfa,my-growth-mfa) — this suffix is required for the CI/CD tooling to detect them (see below).
Host configuration
The host declares itself, what it exposes, and which remotes it consumes, via the federation() plugin in clients/luna-front-end/vite.config.js:
import { federation } from '@module-federation/vite';
federation({
name: 'lunaCore',
filename: 'remoteEntry.js',
runtimePlugins: ['./src/utils/mfe/ensureRemotesPlugin.js'],
exposes: {
'./store': './src/store',
'./authProvider': './src/providers/HostAuthProvider',
'./kudosApi': './src/utils/api/kudos.api',
'./directoryApi': './src/utils/api/directory.api',
'./LayoutPortal': './src/components/Layout/LayoutPortalProvider',
'./userRolesApi': './src/utils/api/userRoles.api',
'./skillsApi': './src/utils/api/skills.api',
'./auditLogApi': './src/utils/api/audit.api',
'./schedulerApi': './src/utils/api/scheduler.api',
'./exchangeRatesApi': './src/utils/api/exchangeRates.api',
'./configApi': './src/utils/api/config.api',
'./performanceReviewApi': './src/utils/api/performanceReview.api',
'./BusinessUnitSelector': './src/components/BusinessUnitSelector/BusinessUnitSelector',
},
remotes: {
kudosApp: { type: 'module', entry: '.../remoteEntry.js', name: 'kudosApp', entryGlobalName: 'kudosApp', shareScope: 'default' },
stableApps: { /* ... same shape */ },
adminApp: { /* ... same shape */ },
myGrowthApp: { /* ... same shape */ },
},
shared: ['react', 'react-dom'],
})The exposed modules are the host's integration contract: the Redux store, the auth provider, a set of API clients, the layout portal, and shared components like BusinessUnitSelector. Don't add new shared singletons unless genuinely needed — they can cause version-mismatch issues between the host and MFEs.
Remote (MFE) configuration
Each MFE's own vite.config.js mirrors this shape in reverse: it exposes its own components, and declares the host as its one remote (named host), for example kudos-mfa:
import { federation } from '@module-federation/vite';
federation({
name: 'kudosApp',
filename: 'remoteEntry.js',
exposes: {
'./GiveKudos': './src/components/GiveKudos/GiveKudos',
'./Kudos': './src/components/Kudos/Kudos',
'./RedeemKudos': './src/components/RedeemKudos/RedeemKudos',
'./RedemptionApproval': './src/components/RedemptionApproval/RedemptionApproval',
},
remotes: {
host: {
type: 'module',
entry: `${env.VITE_APP_PROTOCOL}://${env.VITE_APP_HOST_DOMAIN}/remoteEntry.js`,
name: 'host',
entryGlobalName: 'host',
shareScope: 'default',
},
},
shared: ['react', 'react-dom'],
})Consuming exposed modules
The host lazily loads each remote's exposed components, keyed by the remote name declared above (clients/luna-front-end/src/routes/Routes.jsx):
const Kudos = React.lazy(() => import('kudosApp/Kudos'));
const AdminUserRoles = React.lazy(() => import('adminApp/UserRoles'));
const PerformanceReviews = React.lazy(() => import('myGrowthApp/PerformanceReviews'));An MFE consumes the host's exposed state, auth, and APIs the same way, importing from host/*:
import { store } from 'host/store';
import { HostAuthProvider } from 'host/authProvider';
import { fetchKudos } from 'host/kudosApi';This is the host/remote contract described in clients/CLAUDE.md: an MFE relies on the host for cross-app state, auth, layout, and data access, and only owns its own feature UI. See Micro front ends — auth for wiring up HostAuthProvider in a new MFE, and Micro front ends — state (Redux Toolkit) for how an MFE should structure its own state alongside this host contract.
Runtime resolution
Remotes resolve their remoteEntry.js at runtime, not at build time:
- In a deployed environment, from the MFE's own domain — the host reads
VITE_APP_<NAME>_DOMAINenv vars (e.g.VITE_APP_KUDOS_DOMAIN) to build the URL. - Locally, falling back to
http://localhost:<port>(each MFE has a fixed dev port —kudos-mfais3001,admin-mfa3003,stable-apps-mfa3002,my-growth-mfa3004). - A runtime plugin,
src/utils/mfe/ensureRemotesPlugin.js, guards against Vite dev-mode dropping remotes.
remoteEntry.js and index.html are not content-hashed, so a cached copy still describes the previous deploy. platform/scripts/s3-upload-client-build.sh uploads every other file first, then those two with Cache-Control: no-cache, so a browser never receives a new entry before its chunks exist. CloudFront's minimum TTL is 0 on every client behaviour and on the 403 custom error response, so it forwards that origin header and does not cache the objects. That covers every client's index.html, every MFE remoteEntry.js (including ones added later, such as mcp), and deep links rewritten to index.html. Do not add a CloudFront behaviour per remote entry. A response headers policy cannot change edge caching, and a behaviour can carry only one policy, so each path would need its own copy of the security headers.
An MFE can also run fully standalone (STANDALONE=true), without the host's store, auth, or config, for isolated development — see Micro front ends — auth.
The preferred way to run everything together locally is the luna CLI: luna mfa install then luna mfa dev, which starts the host and every MFE together at localhost:3000 with hot reloading across both.
Wire up a new MFE (host side)
Once your MFE's own vite.config.js exposes its components (see "Remote (MFE) configuration" above), the host needs to know about it. All of this is in clients/luna-front-end/vite.config.js and clients/luna-front-end/src/routes/Routes.jsx:
- Pick a dev port. Each MFE has a fixed local port —
kudos-mfais3001,stable-apps-mfa3002,admin-mfa3003,my-growth-mfa3004. Take the next free number and set it as your MFE's ownserver.portin itsvite.config.js. - Register the remote in the host. Add an entry to the
remotesobject inclients/luna-front-end/vite.config.js, following the existing shape:jsyourApp: { type: 'module', entry: getRemoteUrl('VITE_APP_YOUR_APP_DOMAIN', 3005), // your port from step 1 name: 'yourApp', entryGlobalName: 'yourApp', shareScope: 'default', },getRemoteUrlresolves toVITE_APP_YOUR_APP_DOMAINin a deployed environment, falling back tohttp://localhost:3005locally. - Wire the lazy import in
Routes.jsx. Lazy-load the component(s) your MFE exposes, keyed by the remote name from step 2:jsxThen add it to the rightconst YourComponent = React.lazy(() => import('yourApp/YourComponent'));<Gateway path='/your-route'>as a<TitledRoute>. If your component needs host context passed in as props (as the existing kudos/admin routes do), pass it as an element rather than a bare reference:jsx<TitledRoute mfa component={<YourComponent authUser={authUser} theme={theme} />} path='/' title='Your Feature' /> - Name the folder with the
-mfasuffix (e.g.reports-mfa) — required for the CI/CD tooling in the next section to detect it automatically. - Add the domain env var (
VITE_APP_YOUR_APP_DOMAIN) to whichever.env-cmdrcblocks need it, matching the name used in step 2.
CI/CD pipeline setup for review environments
When creating a new microfrontend, also update the CI/CD pipeline configuration so review environments work correctly. Review environments give developers isolated, temporary deployments to test changes in before merging to main.
Required pipeline updates
1. Update route mapping
File: clients/luna-front-end/scripts/create-review-pipelines.js
Add your new microfrontend to the mfaRouteMaps object:
const mfaRouteMaps = {
'admin-mfa': 'admin',
'kudos-mfa': 'kudos',
'stable-apps-mfa': 'stable-apps',
'your-new-mfa': 'your-route-path', // Add your new microfrontend here
};This mapping tells the review pipeline how to route requests to your microfrontend. For example, if you create reports-mfa, requests to /reports will be routed to your microfrontend.
2. Add a domain variable to the luna-front-end build
In the createLunaFrontEndJobs function, add your microfrontend's domain variable:
script: [
'TICKET_NUMBER=$(echo "$CI_COMMIT_REF_NAME" | grep -o \'[A-Z]\\+-[0-9]\\+\' | tr \'[:upper:]\' \'[:lower:]\' || echo "no-ticket")',
'PORTAL_DOMAIN=review-$TICKET_NUMBER-$CI_MERGE_REQUEST_IID-${ENVIRONMENT:0:3}.dev.luna.and.sh',
'KUDOS_DOMAIN=$PORTAL_DOMAIN/kudos',
'ADMIN_DOMAIN=$PORTAL_DOMAIN/admin',
'STABLE_APPS_DOMAIN=$PORTAL_DOMAIN/stable-apps',
'YOUR_NEW_DOMAIN=$PORTAL_DOMAIN/your-route-path', // Add this line
// ... rest of script
],3. Update environment configuration
Add your domain variable to the jq command that updates .env-cmdrc:
'TEMP_FILE=$(mktemp) && jq --arg env_name "$ENVIRONMENT" --arg portal_domain "$PORTAL_DOMAIN" --arg kudos_domain "$KUDOS_DOMAIN" --arg admin_domain "$ADMIN_DOMAIN" --arg stable_apps_domain "$STABLE_APPS_DOMAIN" --arg your_new_domain "$YOUR_NEW_DOMAIN" \'.[$env_name].VITE_APP_CUSTOM_NODE_ENV = "review" | .[$env_name].VITE_APP_PORTAL_DOMAIN = $portal_domain | .[$env_name].VITE_APP_KUDOS_DOMAIN = $kudos_domain | .[$env_name].VITE_APP_ADMIN_DOMAIN = $admin_domain | .[$env_name].VITE_APP_STABLE_APPS_DOMAIN = $stable_apps_domain | .[$env_name].VITE_APP_YOUR_NEW_DOMAIN = $your_new_domain\' "$ENV_FILE_PATH" > "$TEMP_FILE" && mv "$TEMP_FILE" "$ENV_FILE_PATH"'WARNING
Add your new domain variable assignment to the end of this long jq command: | .[$env_name].VITE_APP_YOUR_NEW_DOMAIN = $your_new_domain
Why these updates are required
Dynamic routing — review environments create unique URLs for each merge request. The
mfaRouteMapsensures your microfrontend is accessible at the correct path.Environment variables — the host application (luna-front-end) needs to know where to find your microfrontend in the review environment. These domain variables are injected into the build process.
Module Federation — the host app's Module Federation configuration uses these environment variables to dynamically load your microfrontend from the correct URL.
Review environment URL structure
Review environments generate URLs like:
- Main portal:
review-{ticket}-{mr-id}-{env}.dev.luna.and.sh - Your microfrontend:
review-{ticket}-{mr-id}-{env}.dev.luna.and.sh/your-route-path
For example:
- Main:
review-li-1234-456-pol.dev.luna.and.sh - Reports MFA:
review-li-1234-456-pol.dev.luna.and.sh/reports
Naming conventions
WARNING
All microfrontend folder names must end with the -mfa suffix (e.g., reports-mfa, admin-mfa) for the CI/CD scripts to automatically detect and include them in the build pipeline.
- Folder name:
{name}-mfa(e.g.,reports-mfa) - Route path: Usually matches the microfrontend purpose (e.g.,
reports) - Environment variable:
VITE_APP_{NAME}_DOMAIN(e.g.,VITE_APP_REPORTS_DOMAIN) - Domain variable:
{NAME}_DOMAIN(e.g.,REPORTS_DOMAIN)
Testing your pipeline changes
- Create a merge request with your microfrontend and pipeline updates.
- Run the review pipeline to create the review environment — this is a manual process that generates the review deployment.
- Once the pipeline completes, it will have built your microfrontend with the correct domain configuration, deployed it to a unique review environment, and configured the host app to load your microfrontend from the review URL.
- Verify your microfrontend is accessible at the expected route.
TIP
These pipeline updates are essential for review environments to function — without them, the host application won't know how to locate and load your microfrontend in review deployments.
Summary
- Module Federation (
@module-federation/vite) lets Luna dynamically share code and dependencies between independently deployed apps at runtime. - The host (
lunaCore) exposes shared state, auth, layout, and API clients; MFEs consume them fromhost/*and expose their own feature components in return. - Remotes resolve their
remoteEntry.jsat runtime from an environment-specific domain, orlocalhostlocally. - CI/CD pipeline updates are required for new microfrontends to work in review environments, including route mapping and domain configuration.
