A production-ready enterprise application built with Angular 20, Nx monorepo, Module Federation, NgRx state management, and Angular Material, demonstrating best practices for micro-frontend architecture.
- Overview
- Architecture
- Prerequisites
- Quick Start
- Project Structure
- Applications
- Development
- Testing
- Building for Production
- Mock Server
- Improvement Notes
This project demonstrates a scalable micro-frontend architecture using Angular Module Federation. Each micro-frontend operates independently while sharing common libraries and maintaining a unified user experience through a shell application.
- Micro-Frontend Architecture: Independent deployable modules using Module Federation
- Modern Angular Stack: Angular 20 with standalone components and signals
- State Management: NgRx Store with effects for predictable state
- Design System: Angular Material for consistent UI/UX
- Monorepo Management: Nx workspace for efficient development
- Type Safety: TypeScript with strict mode enabled
- Testing: Comprehensive unit tests (Jest) and E2E tests (Playwright)
- Mock Server: MSW (Mock Service Worker) for API mocking during development
- Framework: Angular 20.3.0
- Build Tool: Nx 21.1.0
- State Management: NgRx Store & Effects
- UI Library: Angular Material 20.2.2
- Testing: Jest (unit), Playwright (E2E)
- Mocking: Mock Service Worker (MSW) 2.12.2
- Module Federation: Webpack Module Federation Plugin
The application follows a micro-frontend architecture with these key components:
- Main container application running on port 4200
- Provides navigation, authentication, and layout
- Dynamically loads remote micro-frontends
- Manages shared state and routing
- Dashboard (Port 4201) - Overview and analytics
- Assets (Port 4202) - Asset management with list and detail views
- Findings (Port 4203) - Security findings management
- Users (Port 4204) - User administration
- Settings (Port 4205) - Application configuration
- @angular-micro-frontend/shared: Common models, types, and utilities
- @angular-micro-frontend/auth: Authentication services and guards
- @angular-micro-frontend/api: API client and services
- @angular-micro-frontend/interceptors: HTTP interceptors
Each micro-frontend maintains its own NgRx store slice:
- Actions for all user interactions
- Reducers for immutable state updates
- Effects for side effects (API calls)
- Selectors for efficient data access
Store Structure:
├── shell (navigation, user)
├── assets (asset list, detail)
├── findings (findings list)
├── users (users list)
└── settings (app settings)
- Node.js >= 18.x
- npm >= 9.x
- Git
# Clone the repository
git clone <repository-url>
cd angular-micro-frontend
# Install dependencies
npm installRun all applications with mock API data:
npm startThis starts:
- Shell (http://localhost:4200)
- Dashboard (http://localhost:4201)
- Assets (http://localhost:4202)
- Findings (http://localhost:4203)
- Users (http://localhost:4204)
- Settings (http://localhost:4205)
Accessing the Application:
To enable Mock Service Worker, add the ?mock=true query parameter:
http://localhost:4200?mock=true
Important: Without the ?mock=true parameter, the application will attempt to connect to a real backend API and will not work without proper API configuration.
The Mock Service Worker automatically intercepts API calls and returns mock data when the query parameter is present, allowing you to develop and test without a backend.
To develop against a real backend API:
# Start individual applications
npx nx serve shell
npx nx serve dashboard
npx nx serve assets
npx nx serve findings
npx nx serve users
npx nx serve settingsConfigure API endpoints in apps/*/src/environments/environment.ts
Open http://localhost:4200 in your browser to access the shell application, which will load all micro-frontends.
angular-micro-frontend/
├── apps/
│ ├── shell/ # Main shell application
│ ├── dashboard/ # Dashboard micro-frontend
│ ├── assets/ # Assets micro-frontend
│ │ ├── src/
│ │ │ ├── app/
│ │ │ │ ├── pages/ # Feature pages
│ │ │ │ ├── state/ # NgRx store
│ │ │ │ └── helpers/ # Utilities
│ │ │ └── public/ # Static assets (MSW worker)
│ ├── findings/ # Findings micro-frontend
│ ├── users/ # Users micro-frontend
│ ├── settings/ # Settings micro-frontend
│ └── assets-e2e/ # E2E tests for assets
├── libs/
│ ├── shared/ # Shared models and utilities
│ ├── auth/ # Authentication library
│ ├── api/ # API client library
│ └── interceptors/ # HTTP interceptors
├── tools/
│ └── mock-server/ # MSW mock server configuration
├── nx.json # Nx workspace configuration
├── package.json # Dependencies and scripts
└── tsconfig.base.json # TypeScript configuration
The main container that hosts all micro-frontends.
Features:
- Top navigation bar with routing
- Authentication flow
- Lazy loading of remote modules
- Shared layout and styling
Routes:
/- Redirects to dashboard/dashboard- Dashboard module/assets- Assets module/findings- Findings module/users- Users module/settings- Settings module
Overview and analytics dashboard.
Features:
- Widget-based layout
- Real-time statistics
- Quick access to other modules
Asset management with comprehensive CRUD operations.
Features:
- Asset list with filtering and pagination
- Asset detail view with vulnerabilities
- Status management (active, inactive, maintenance)
- Search and filter capabilities
Routes:
/assets- Assets list/assets/:id- Asset detail
State Management:
Assets Store:
├── State: { assets: Asset[], loading: boolean, error: string | null }
├── Actions: loadAssets, loadAssetDetail, updateAssetStatus
├── Effects: API calls for CRUD operations
└── Selectors: selectAllAssets, selectAssetById, selectAssetsLoadingSecurity findings and vulnerability management.
Features:
- Security findings list
- Severity filtering
- Finding resolution workflow
- Detailed finding information
User administration and management.
Features:
- User list with role information
- User creation and deletion
- Role management
- Email and status display
Application configuration and preferences.
Features:
- Application settings
- User preferences
- Theme configuration
# Run shell application only
npx nx serve shell
# Run assets micro-frontend only
npx nx serve assets
# Run with production configuration
npx nx serve shell --configuration=production# Generate a new component
npx nx g @nx/angular:component --project=assets
# Generate a new service
npx nx g @nx/angular:service --project=shared
# Generate a new library
npx nx g @nx/angular:library my-lib# Lint all projects
npm run lint
# Lint and fix
npm run lint:fix
# Lint specific project
npx nx lint assets# View project dependency graph
npx nx graphUnit tests are written with Jest and test individual components, services, and state management logic.
# Run all unit tests
npm test
# Run tests for specific project
npx nx test assets
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverageTest Coverage:
- Assets: 87 tests passing
- Findings: 50 tests passing
- Users: 42 tests passing
Testing Patterns:
- Component testing with mocked dependencies
- NgRx store testing with mock store
- Service testing with HTTP mocking
- Signal and computed value testing
E2E tests are written with Playwright and test complete user workflows.
# Run E2E tests
npm run e2e
# Run E2E tests for specific project
npx nx e2e assets-e2e
# Run E2E tests in headed mode
npx nx e2e assets-e2e --headed
# Debug E2E tests
npx nx e2e assets-e2e --debugE2E Test Coverage:
- Assets navigation: List to detail page flow
- Cross-browser testing (Chromium, Firefox, WebKit)
E2E Test Features:
- Mock Service Worker integration for consistent test data
- Page Object Model pattern
- Automated screenshot capture on failure
- Parallel test execution
Testing Strategy:
├── Unit Tests (Jest)
│ ├── Components: UI logic and rendering
│ ├── Services: Business logic
│ ├── Store: State management (actions, reducers, effects)
│ └── Helpers: Utility functions
├── Integration Tests
│ └── NgRx Store: Complete state flow
└── E2E Tests (Playwright)
└── User workflows: End-to-end scenarios
# Build all applications for production
npm run build
# Build specific application
npx nx build assets --configuration=production
# Build with stats
npx nx build shell --configuration=production --stats-jsonProduction builds are output to dist/ directory:
dist/
├── apps/
│ ├── shell/
│ ├── dashboard/
│ ├── assets/
│ ├── findings/
│ ├── users/
│ └── settings/
- Independent Deployment: Each micro-frontend can be deployed separately
- Version Management: Use semantic versioning for shared libraries
- Module Federation: Ensure remote entry points are accessible
- Environment Variables: Configure API endpoints per environment
- CDN: Host static assets on CDN for better performance
- Tree-shaking for smaller bundle sizes
- Lazy loading for faster initial load
- Ahead-of-Time (AOT) compilation
- Production mode optimizations
- Source map generation for debugging
The project uses Mock Service Worker (MSW) for API mocking during development and testing.
Mock handlers are defined in tools/mock-server/handlers.ts:
Mock Endpoints:
├── GET /api/assets - List all assets
├── GET /api/assets/:id - Get asset by ID
├── GET /api/findings - List all findings
├── POST /api/findings/:id/resolve - Resolve finding
├── GET /api/users - List all users
├── DELETE /api/users/:id - Delete user
└── GET /api/settings - Get settingsIn Development:
npm start # Mock server automatically enabledIn Tests: Mock server is automatically configured in test setup files.
In E2E Tests:
Enable mock mode by adding ?mock=true query parameter:
await page.goto('/?mock=true');Mock data is generated using helper functions in tools/mock-server/data-generators.ts:
- Realistic data generation
- Consistent IDs for testing
- Configurable data sets
To add or modify mock responses:
- Edit
tools/mock-server/handlers.ts - Add new handlers using MSW syntax
- Restart development server
Example:
http.get('/api/new-endpoint', () => {
return HttpResponse.json({ data: 'mock response' });
})-
Migration to Angular 20
- Updated to latest Angular version with standalone components
- Implemented signal-based state management
- Removed NgModule dependencies
-
State Management Refactoring
- Migrated from component state to NgRx Store
- Implemented effects for async operations
- Added selectors for optimal performance
-
Component Architecture
- Separated templates from components for better maintainability
- Implemented helper classes for business logic
- Added computed signals for derived state
-
Testing Infrastructure
- Fixed all unit tests (179 tests passing)
- Implemented E2E tests with Playwright
- Added MSW for consistent test data
-
Navigation Improvements
- Fixed routing to work in both standalone and federated contexts
- Implemented relative navigation for flexibility
- Added proper route guards and lazy loading
- Implement virtual scrolling for large lists
- Add bundle size monitoring and optimization
- Implement service workers for offline capability
- Add compression for static assets
- Optimize initial bundle size with better code splitting
- Implement micro-frontend communication via custom events
- Add shared component library for consistent UI
- Implement centralized error handling and logging
- Add analytics and monitoring integration
- Create a design system documentation
- Add real-time updates using WebSockets
- Implement advanced filtering and sorting
- Add export functionality (CSV, PDF)
- Implement user preferences persistence
- Add multi-language support (i18n)
- Increase test coverage to >90%
- Add visual regression testing
- Implement performance testing
- Add accessibility testing (a11y)
- Create E2E tests for all user workflows
- Set up CI/CD pipeline
- Add automated deployment
- Implement feature flags
- Add container support (Docker)
- Create Kubernetes deployment configurations
- Add Storybook for component development
- Create developer documentation
- Add commit hooks for code quality
- Implement automatic changelog generation
- Add code scaffolding templates
- Implement proper authentication (OAuth2/OIDC)
- Add authorization and role-based access control
- Implement security headers
- Add CSRF protection
- Regular security audits and dependency updates
- Build Warning: Unused nx-welcome.ts file in assets app (can be safely removed)
- Port Management: Running multiple development servers requires all ports to be free
- Module Federation: Remote entry points must be built before shell can load them
When contributing to this project:
- Follow the existing code style and patterns
- Write unit tests for new features
- Update documentation as needed
- Use conventional commits for commit messages
- Ensure all tests pass before submitting PR
- Use TypeScript strict mode
- Follow Angular style guide
- Use signals for reactive state
- Implement proper error handling
- Write self-documenting code with clear naming
MIT
For questions or issues, please open an issue in the repository.






