Platforms are a composition of Bit Apps. Use them to stitch micro-services and micro-frontends into a unified platform. Platforms are used for easy development, testing, and recomposition of service-oriented platforms.
You can create a new platform composing Bit apps by running the following command:
bit create platform my-platformRun the platform:
bit run my-platformYour platform will be orchestrated in the right order, on the selected port ranges, and the listening port will be shown in the output.
Platforms are used to compose a service-oriented architecture into a unified platform. You can compose the backends:
import { Platform } from '@bitdev/platforms.platform';
const AcmeWeb = import.meta.resolve('@bitdev/platforms.examples.acme-web');
const PlatformGateway = import.meta.resolve('@bitdev/symphony.backends.gateway-server');
// user service to include in the platform.
const UserService = import.meta.resolve('@bitdev/node.examples.user-server');
export const AcmePlatform = Platform.from({
name: 'acme-platform',
frontends: {
main: AcmeWeb,
services: []
},
backends: {
// port range for the gateway
mainPortRange: [5001, 5010],
main: PlatformGateway,
// port range for the services.
portRange: [5100, 5200],
services: [
UserService
]
},
});You can learn about the different options supported by the PlatformOptions and PlatformLayer docs.
You can configure services used in the platform composition, using a tuple instead of service value:
export const AcmePlatform = Platform.from({
name: 'acme-platform',
frontends: {
main: AcmeWeb,
services: []
},
backends: {
main: PlatformGateway,
services: [
[UserService, {
// configure a remote url to use if the service is not on the workspace
remoteUrl: 'http://acme.com:8080',
}]
]
},
});You can learn about the different options supported for ServiceOptions in the component docs.
You can add a build task for your platform by passing a function to the platform build option:
import { build } from 'esbuild';
export const AcmePlatform = Platform.from({
name: 'acme-platform',
frontends: {
main: AcmeWeb,
},
backends: {
main: PlatformGateway,
services: [
UserService
]
},
build: (context: PlatformBuildContext) => {
const platformComponents = context.platformComponents;
console.log(context.platformComponents); // echo the components composed in the platform.
return {
errors: [],
artifacts: [],
};
},
});You can find more information on the PlatformBuildContext at the component docs.
Once done, you can test the build of your platforms:
bit build my-platformThe path to the build results will be shown in the output of the command. To persist the artifacts and create new versions, use bit snap or bit tag.
Platforms can be deployed on the platform build to ensure deployment atomicity, safety and timing:
import { execSync } from 'node:child_process';
export async function deploy(context: PlatformBuildContext): Promise<AppBuildResult> {
execSync(`s3-upload ${context.platformComponents}`);
return {
artifacts: [],
};
}Keep in mind you can deploy at the service level as well. Learn more about deploying apps.