The Modular Architecture Essentials project provides a set of modular libraries designed for building scalable micro-frontend applications. The libraries are split into three focused packages, each serving a specific purpose in the modular architecture ecosystem:
mod-arch-core
: Core functionality, API utilities, context providers, and hooksmod-arch-shared
: Shared UI components and utilities for upstream applicationsmod-arch-kubeflow
: Kubeflow-specific themes, styling, and integration utilities
This modular approach ensures better separation of concerns, improved maintainability, and allows applications to only import what they need.
Install the packages you need based on your application requirements:
npm install mod-arch-core
npm install mod-arch-shared sass sass-loader
npm install mod-arch-kubeflow @mui/material sass sass-loader
The libraries require certain peer dependencies:
- React (
react
,react-dom
) - Required for all packages - MUI dependencies (
@mui/material
,@mui/icons-material
,@mui/types
) - Required for shared components and theming - SASS dependencies (
sass
,sass-loader
) - Required for processing SCSS files
This library contains SCSS files that need to be processed by your application's build system. You must:
-
Install the required dependencies:
npm install sass sass-loader
-
Configure your webpack to handle SCSS files by adding this rule to your webpack configuration:
{ test: /\.s[ac]ss$/i, use: [ // Creates `style` nodes from JS strings 'style-loader', // Translates CSS into CommonJS 'css-loader', // Compiles Sass to CSS 'sass-loader', ], }
If you're using Create React App, Vite, or similar build tools, SCSS support is typically included by default when you install the sass
package.
The core package provides essential functionality for modular architecture applications:
- API utilities: HTTP clients, error handling, and API state management
- Context providers: Core context providers for configuration, notifications, and browser storage
- Hooks: React hooks for namespaces, settings, and API state management
- Utilities: Common utility functions, fetch state management, and Kubeflow integration helpers
- Types: Core TypeScript type definitions
import {
ModularArchContextProvider,
BrowserStorageContextProvider,
NotificationContextProvider,
useModularArchContext,
useNamespaces,
DeploymentMode,
type ModularArchConfig
} from 'mod-arch-core';
The shared package provides reusable UI components and utilities for upstream applications:
- Components: Common UI components like search fields, modals, tables, and form elements
- Utilities: Shared utility functions for UI interactions
- Images: Common image assets and icons
- Types: Shared TypeScript type definitions
import {
DashboardSearchField,
DashboardModalFooter,
SimpleSelect,
MarkdownView,
images
} from 'mod-arch-shared';
The Kubeflow package provides theme and styling integration for Kubeflow environments:
- Context providers: Theme context provider for Kubeflow styling
- Hooks: Theme management hooks
- Styles: Kubeflow-specific SCSS and CSS files
- Images: Kubeflow branding assets (logos, icons)
- Utilities: Kubeflow-specific constants and helpers
import {
ThemeProvider,
useThemeContext,
style,
images
} from 'mod-arch-kubeflow';
Import components and utilities from the appropriate packages:
// Core functionality
import {
ModularArchContextProvider,
BrowserStorageContextProvider,
NotificationContextProvider,
useNamespaces,
DeploymentMode
} from 'mod-arch-core';
// Shared components
import {
DashboardSearchField,
SimpleSelect,
images as sharedImages
} from 'mod-arch-shared';
// Kubeflow theming
import {
ThemeProvider,
images as kubeflowImages
} from 'mod-arch-kubeflow';
const MyComponent = () => {
const { namespaces, loading } = useNamespaces();
return (
<>
<DashboardSearchField onChange={handleSearch} />
<SimpleSelect options={namespaces} />
<img src={kubeflowImages.logoKubeflowLightTheme} alt="Kubeflow" />
</>
);
};
Each package exports styles and images that can be imported and used in your application.
// Import Kubeflow-specific styles
import { style } from 'mod-arch-kubeflow';
// Or import specific style files directly
import 'mod-arch-kubeflow/dist/style/MUI-theme.scss';
// Import from shared package
import { images as sharedImages } from 'mod-arch-shared';
// Import from Kubeflow package
import { images as kubeflowImages } from 'mod-arch-kubeflow';
// Use them in your components
<img src={kubeflowImages.logoKubeflowLightTheme} alt="Kubeflow Light" />
<img src={kubeflowImages.logoKubeflowDarkTheme} alt="Kubeflow Dark" />
<img src={sharedImages.emptyStateNotebooks} alt="Empty state" />
The repository is organized into three main packages:
- api/: API utilities for making service calls and handling errors
- context/: Core context providers (ModularArchContext, BrowserStorageContext, NotificationContext)
- hooks/: React hooks for namespaces, settings, and state management
- types/: Core TypeScript type definitions
- utilities/: Core utility functions and constants
- components/: Reusable UI components for upstream applications
- images/: Common image assets and icons
- types/: Shared TypeScript type definitions
- utilities/: Shared utility functions
- context/: Theme context provider for Kubeflow styling
- hooks/: Theme management hooks
- images/: Kubeflow branding assets (logos, icons)
- style/: Kubeflow-specific SCSS and MUI theme files
- utilities/: Kubeflow-specific constants and helpers
The Modular Architecture libraries require proper context setup to function correctly. The libraries provide several essential providers that must be configured at the root of your application.
The ModularArchContextProvider
is mandatory for using these libraries. It provides essential configuration and state management for:
- Deployment mode configuration (Standalone, Federated, or Kubeflow)
- Namespace management and selection
- API endpoint configuration
- Script loading state for Kubeflow integration
- Mandatory namespace enforcement when required
Provides browser storage management for persisting user preferences and application state.
Handles application-wide notifications and toast messages.
The ThemeProvider
from mod-arch-kubeflow
manages UI theming for Kubeflow environments and supports:
- Material-UI theme with Kubeflow branding
- CSS variables support for dynamic theming
- Light and dark theme variants
Here's how to properly set up your application root with all providers:
import React from 'react';
import { createRoot } from 'react-dom/client';
import { BrowserRouter as Router } from 'react-router-dom';
import {
ModularArchContextProvider,
BrowserStorageContextProvider,
NotificationContextProvider,
DeploymentMode,
type ModularArchConfig
} from 'mod-arch-core';
import { ThemeProvider, Theme } from 'mod-arch-kubeflow';
import App from './App';
// Define your configuration
const modularArchConfig: ModularArchConfig = {
deploymentMode: DeploymentMode.Standalone, // or Federated, Kubeflow
URL_PREFIX: '/api',
BFF_API_VERSION: 'v1',
// Optional: Force a specific namespace
// mandatoryNamespace: 'production'
};
const container = document.getElementById('root');
const root = createRoot(container!);
root.render(
<React.StrictMode>
<Router>
<ModularArchContextProvider config={modularArchConfig}>
<ThemeProvider theme={Theme.MUI}>
<BrowserStorageContextProvider>
<NotificationContextProvider>
<App />
</NotificationContextProvider>
</BrowserStorageContextProvider>
</ThemeProvider>
</ModularArchContextProvider>
</Router>
</React.StrictMode>,
);
DeploymentMode.Standalone
: For single-application deploymentsDeploymentMode.Federated
: For micro-frontend architecturesDeploymentMode.Kubeflow
: For integration with Kubeflow environments
When using mod-arch-kubeflow
, the ThemeProvider supports Material-UI themes optimized for Kubeflow environments with proper branding and styling.
Once providers are set up, you can access the configuration and state throughout your application:
import { useModularArchContext } from 'mod-arch-core';
import { useThemeContext } from 'mod-arch-kubeflow';
const MyComponent = () => {
const {
config,
namespaces,
preferredNamespace,
updatePreferredNamespace
} = useModularArchContext();
const { theme } = useThemeContext();
return (
<div>
<p>Current deployment mode: {config.deploymentMode}</p>
<p>Available namespaces: {namespaces.length}</p>
<p>Current theme: {theme}</p>
</div>
);
};
The core library supports various configuration options through the ModularArchConfig
interface:
interface ModularArchConfig {
deploymentMode: DeploymentMode;
URL_PREFIX: string;
BFF_API_VERSION: string;
mandatoryNamespace?: string; // Optional: Force a specific namespace
}
The mandatoryNamespace
option allows you to enforce a specific namespace throughout the application:
const config = {
deploymentMode: DeploymentMode.Standalone,
URL_PREFIX: '/api',
BFF_API_VERSION: 'v1',
mandatoryNamespace: 'production' // Force the use of 'production' namespace
};
When mandatoryNamespace
is set:
- The namespace selector in the UI will be disabled
- All API calls will be restricted to the specified namespace
- Users cannot switch to different namespaces
- The
useNamespaces
hook will only return the mandatory namespace
This is useful for production environments or when you want to restrict users to a specific namespace.
- Node.js >= 20.0
- npm >= 10.8
git clone <repository-url>
cd modular-architecture-essentials
npm install
Each package can be built independently:
# Build core package
cd mod-arch-core
npm run build
# Build shared package
cd mod-arch-shared
npm run build
# Build kubeflow package
cd mod-arch-kubeflow
npm run build
Run tests for individual packages:
# Test core package
cd mod-arch-core
npm test
# Test shared package
cd mod-arch-shared
npm test
# Test kubeflow package (type checking only)
cd mod-arch-kubeflow
npm run test:type-check
# Lint core package
cd mod-arch-core
npm run test:lint
# Lint shared package
cd mod-arch-shared
npm run test:lint
If you're migrating from the previous single-package structure, here's how to update your imports:
import {
ModularArchContextProvider,
ThemeProvider,
BrowserStorageContextProvider,
NotificationContextProvider,
DashboardSearchField,
useNamespaces,
DeploymentMode,
Theme
} from 'mod-arch-shared';
// Core functionality
import {
ModularArchContextProvider,
BrowserStorageContextProvider,
NotificationContextProvider,
useNamespaces,
DeploymentMode,
type ModularArchConfig
} from 'mod-arch-core';
// Shared components
import {
DashboardSearchField
} from 'mod-arch-shared';
// Kubeflow theming
import {
ThemeProvider
} from 'mod-arch-kubeflow';
Before:
npm install mod-arch-shared
After:
npm install mod-arch-core mod-arch-shared mod-arch-kubeflow
We welcome contributions to the project. Please see the CONTRIBUTING.md file for more information.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.