Create Platforms

Platforms are a composition of Bit Apps. Use them to stitch micro-services and micro-frontends into a unified platforms. 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-platform
CopiedCopy

Run the platform:

bit run my-platform
CopiedCopy

Your platform will be orchestrated at the right order, on the selected port ranges, and the listening port would be shown on the output.

Platform composition

Platforms are used to compose a service-architecture into a unified platforms. 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
    ]
  },
});
CopiedCopy

You can learn on the different options supported by the PlatformOptions and PlatformLayer docs.

External services

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',
      }]
    ]
  },
});
CopiedCopy

You can learn on the different options supported for ServiceOptions in the component docs.

Build

You can 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: [],
    };
});
CopiedCopy

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-platform
CopiedCopy

Path to build results will be shown in the output of the command. To persist the artifacts and create new versions use bit snap or tag.

Deploy

Platforms can be deployed on the platform build to ensure deployment atomicity, safety and timing:

import { exec } from 'node:child_process';

export function deploy(context: PlatformBuildContext): Promise<AppBuildResult> {  
  const response = exec(`s3-upload ${context}`);
}
CopiedCopy

Keep in mind you can deploy at the service level as well. Learn more on deploying apps.

Learn more