Skip to content

Build a new client ​

How to scaffold, configure, and deploy a new standalone client in clients/. A "client" is anything that consumes Luna's APIs and renders a UI — a frontend. This guide walks through the files a new client needs, grounded in marketing-consent, a standalone React + Vite client, with and-service referenced where it differs (plain JS instead of TypeScript).

If your client will be federated into the main app instead of standing alone, see Micro front ends — overview instead — this guide is for standalone apps with their own domain.

Node version ​

CI runs clients on Node >=24. Set up your local environment to match.

Directory structure ​

A client lives in its own folder under clients/, named descriptively in kebab-case:

  • client-feedback — GOOD
  • marketing-consent — GOOD
  • front-end — BAD
  • kudos-app — BAD

A typical standalone client (marketing-consent) looks like this:

clients/
  | - marketing-consent/
    | - lefthook.yml          // git hooks (pre-commit lint, pre-push audit)
    | - public/                // static assets
    | - src/                   // app source (main.tsx, App.tsx, pages, components, ...)
    | - index.html              // Vite entry point
    | - vite.config.ts          // Vite (+ Vitest) config
    | - .env-cmdrc              // per-environment env config
    | - .eslintrc.cjs           // linting
    | - .npmrc                  // private package registry auth
    | - application.yml         // CloudFormation infrastructure
    | - parameters/              // per-environment deploy parameters
    | | - <env>.parameters.json   // e.g. polaris.parameters.json, production.parameters.json
    | - ci.yml                   // GitLab CI definition
    | - package.json             // dependencies and scripts
    | - tsconfig.json            // TypeScript clients only
    | - README.md                // docs about the client

Scaffold the app ​

Before wiring up config and CI, the client needs an actual app to build: a Vite entry point, a bootstrap file, and a root component. marketing-consent's:

html
<!-- index.html -->
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Your client name</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.tsx"></script>
  </body>
</html>
tsx
// src/main.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);
tsx
// src/App.tsx
import { ThemeProvider } from '@mui/material';
import { Router } from '@reach/router';
import { theme } from './styles';
import { HomePage, NotFound } from './pages';

const App = () => {
  return (
    <ThemeProvider theme={theme}>
      <Router>
        <NotFound path='/' />
        <HomePage path='/:id' />
      </Router>
    </ThemeProvider>
  );
};

export default App;

and-service (JS) follows the same shape with react-router-dom instead of @reach/router — main.jsx wraps <App /> in a <BrowserRouter> rather than routing inside App.jsx. Either routing library is fine; match whichever the rest of the client's ecosystem uses (see clients/CLAUDE.md's client flavours for what neighbouring clients use).

Files ​

lefthook.yml ​

This file defines the Lefthook git hooks for this client. The root lefthook.yml picks it up. yarn run lint runs on commit when files under this client's folder are staged, and yarn run audit runs on push when the push changes files in this folder. A failed audit blocks the push and shows the /fix-audit command to run. Without this file, lint and audit are only enforced in CI, not locally. root must be the client's path from the repo root, with a trailing slash, and job names must be unique in the repo.

For clients/marketing-consent:

yaml
pre-commit:
  jobs:
    - name: clients/marketing-consent lint
      root: clients/marketing-consent/
      run: yarn run lint

pre-push:
  jobs:
    - name: clients/marketing-consent audit
      root: clients/marketing-consent/
      run: yarn run audit
      env:
        AUDIT_REGISTRY_ERROR: warn
      fail_text: 'Fix it before you push: claude "/fix-audit clients/marketing-consent", then commit and push again.'

.eslintrc.cjs ​

Every client extends the shared base and client lint configs from platform/config/lint/:

js
const baseEslintConfig = require('../../platform/config/lint/base.eslint.js');
const clientEslintConfig = require('../../platform/config/lint/client.eslint.js');

module.exports = {
  ...clientEslintConfig,
  root: true,
  rules: {
    ...baseEslintConfig.rules,
    ...clientEslintConfig.rules,
  },
}

If your client is TypeScript (like marketing-consent), also extend plugin:@typescript-eslint/recommended:

js
module.exports = {
  ...clientEslintConfig,
  root: true,
  rules: {
    ...baseEslintConfig.rules,
    ...clientEslintConfig.rules,
  },
  extends: [
    ...clientEslintConfig.extends,
    'plugin:@typescript-eslint/recommended',
  ],
}

.npmrc ​

Points the client at Luna's private GitLab package registry, so it can install packages like @bhag-business-platform/luna-strings:

@bhag-business-platform:registry=https://gitlab.com/api/v4/projects/71835281/packages/npm/
//gitlab.com/api/v4/projects/71835281/packages/npm/:_authToken=${LUNA_PACKAGE_REGISTRY_PAT}

.env-cmdrc ​

Environment config is driven by env-cmd, not Vite's built-in .env.<mode> files — this keeps per-environment values (API domains, etc.) out of source and keyed explicitly by the ENVIRONMENT variable the CI passes in.

Don't commit a .env file: git ignores .env, and Claude Code's sandbox can't read one at module level. Put local-only values in .env.local.

.env-cmdrc has one block per environment, keyed by environment name. For marketing-consent it looks like this:

json
{
  "polaris": {
    "VITE_APP_CUSTOM_NODE_ENV": "polaris",
    "VITE_APP_API_PROTOCOL": "https",
    "VITE_APP_API_DOMAIN": "marketing-consent.v2.polaris.dev.data-protection.and.sh"
  },
  "sol": { "...": "..." },
  "pulsar": { "...": "..." },
  "development": { "...": "..." },
  "staging": { "...": "..." },
  "production": {
    "VITE_APP_CUSTOM_NODE_ENV": "production",
    "VITE_APP_API_PROTOCOL": "https",
    "VITE_APP_API_DOMAIN": "marketing-consent.v2.data-protection.and-digital.com"
  }
}

Keep every var prefixed VITE_ — the .env-cmdrc keys above all are — but how you read it in source depends on the client's vite.config, covered next.

vite.config.ts (or .js) ​

A standalone client's Vite config wires up the React plugin, path aliasing, and a build/ output folder (the anchors expect the built site there). marketing-consent's config:

ts
import { ConfigEnv, defineConfig, loadEnv } from 'vite';
import react from '@vitejs/plugin-react';
import vitejsconfigPaths from 'vite-jsconfig-paths';

export default defineConfig(({ mode }: ConfigEnv) => {
  const env = loadEnv(mode, process.cwd());

  return {
    plugins: [react(), vitejsconfigPaths()],
    define: {
      'process.env': env,
    },
    build: {
      outDir: 'build',
      target: 'esnext',
    },
    server: {
      open: true,
      port: 3000,
    },
  };
});

Vitest config for tests can live in the same file behind a mode === 'test' branch (as marketing-consent does), or in a separate vitest.config.ts — either is fine as long as yarn run test runs it.

Reading env vars in source — marketing-consent's define: { 'process.env': env } block replaces every process.env reference with the .env-cmdrc values at build time, so its source reads them as process.env.VITE_APP_API_DOMAIN (see src/api/config.ts), not Vite's usual import.meta.env. and-service has no such define block, so it reads Vite's default import.meta.env.VITE_* instead (see src/hooks/useFetch.js). Either is valid — pick one and be consistent within the client. Default to import.meta.env.VITE_* (Vite's standard, no extra config needed) unless you have a reason to match marketing-consent's process.env style.

package.json ​

The CI anchors call four scripts on every client — keep these names and outputs:

  • lint — runs linting.
  • build — produces a build/ folder with an index.html at its root.
  • test — runs unit tests.
  • audit — runs the shared dependency audit script.

For marketing-consent:

json
{
  "name": "marketing-consent",
  "private": true,
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "tsc && env-cmd -e $ENVIRONMENT vite build",
    "lint": "eslint './src/**/*.{js,jsx}'",
    "test": "vitest run --mode test",
    "preview": "vite preview",
    "audit": "../../platform/scripts/run-node-audit.sh",
    "audit:ignore": "yarn audit --json > .yarn-audit.ignore"
  },
  "dependencies": {
    "@emotion/react": "^11.11.4",
    "@emotion/styled": "^11.11.5",
    "@mui/material": "^5.15.15",
    "@reach/router": "^1.3.4",
    "axios": "^1.16.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@types/react": "^18.2.66",
    "@vitejs/plugin-react": "^5.1.4",
    "env-cmd": "^10.1.0",
    "typescript": "^5.2.2",
    "vite": "^6.4.3",
    "vite-jsconfig-paths": "^2.0.1",
    "vitest": "^3.2.6"
  }
}

Add libraries with yarn add <package> (or yarn add -D <package> for dev-only tooling) from inside the client's folder — dependencies aren't hoisted from anywhere else in the repo (see "How the monorepo fits together" in the root CLAUDE.md). Follow the styling hierarchy in .claude/rules/engineering/clients.md: reach for @bhag-business-platform/luna-components first, then MUI, before adding a new styling dependency.

A JS (non-TypeScript) client, like and-service, drops the tsc && prefix from build:

json
"build": "env-cmd -e ${ENVIRONMENT:-development} vite build",

env-cmd -e $ENVIRONMENT picks the matching block out of .env-cmdrc; the CI anchors set ENVIRONMENT per job (see ci.yml below).

tsconfig.json (TypeScript clients only) ​

A TypeScript client needs a tsconfig.json alongside tsconfig.node.json (for the Vite config file itself). marketing-consent's is the standard Vite + React + TS config — target: ES2020, jsx: react-jsx, moduleResolution: node, strict: true — reuse it as-is for a new TypeScript client. A JS client (and-service) has no tsconfig.json at all.

ci.yml ​

Extends the shared client anchors in platform/ci/clients/anchors.yml so you get install/audit/build/test/lint/deploy without redefining stages. For marketing-consent:

yml
client-marketing-consent:install:
  extends:
    - .luna-client-install-template
  variables:
    CLIENT_DIR: marketing-consent

client-marketing-consent:audit:
  extends:
    - .luna-client-audit-template
  variables:
    CLIENT_DIR: marketing-consent

client-marketing-consent:build:
  extends:
    - .luna-client-build-template
    - .luna-client-merge-request-rules
  variables:
    CLIENT_DIR: marketing-consent
    ENVIRONMENT: development

client-marketing-consent:build:lower-environment:
  extends:
    - .luna-client-build-template
    - .luna-client-environment-deploy-rules
  variables:
    CLIENT_DIR: marketing-consent
    ENVIRONMENT: '$CI_COMMIT_REF_NAME'
  before_script:
    - export ENVIRONMENT=${CI_COMMIT_REF_NAME:4}

client-marketing-consent:build:staging:
  extends:
    - .luna-client-build-template
    - .luna-client-main-deploy-rules
  variables:
    CLIENT_DIR: marketing-consent
    ENVIRONMENT: staging

client-marketing-consent:build:production:
  extends:
    - .luna-client-build-template
    - .luna-client-main-deploy-rules
  variables:
    CLIENT_DIR: marketing-consent
    ENVIRONMENT: production

client-marketing-consent:test:
  extends:
    - .luna-client-test-template
  variables:
    CLIENT_DIR: marketing-consent

client-marketing-consent:lint:
  extends:
    - .luna-client-lint-template
  variables:
    CLIENT_DIR: marketing-consent

client-marketing-consent:cfn-lint:
  extends:
    - .luna-client-cfn-linter-template
  variables:
    CLIENT_DIR: marketing-consent

client-marketing-consent:deploy:lower-environment:
  extends:
    - .luna-client-environment-deploy-template
  variables:
    DOT_ENV_FILE: marketing-consent-deploy.env
    DOMAIN_URL: dev.data-protection.and.sh
    CLIENT_DIR: marketing-consent
    STACK_NAME: marketing-consent-client
  environment:
    name: $CI_COMMIT_REF_SLUG/marketing-consent-client
    url: $DYNAMIC_ENVIRONMENT_URL
  dependencies:
    - client-marketing-consent:build:lower-environment

client-marketing-consent:deploy:staging:
  extends:
    - .luna-client-staging-deploy-template
  variables:
    CLIENT_DIR: marketing-consent
    STACK_NAME: marketing-consent-client
  environment:
    name: staging/marketing-consent-client
    url: https://staging.data-protection.and.sh
  dependencies:
    - client-marketing-consent:build:staging

client-marketing-consent:deploy:production:
  extends:
    - .luna-client-production-deploy-template
  variables:
    CLIENT_DIR: marketing-consent
    STACK_NAME: marketing-consent-client
  environment:
    name: production/marketing-consent-client
    url: https://data-protection.and-digital.com
  dependencies:
    - client-marketing-consent:build:production

A production deploy job typically also carries DOMAIN_NAME_CERTIFICATE_ARN, DOMAIN_HOSTED_ZONE_ID, and DOMAIN_NAME variables (see client-feedback's ci.yml for an example) — where your client is set up this way instead depends on how its application.yml takes its parameters (see Infrastructure below).

The environment:name for each deploy job should be <environment>/<client-name>-client so GitLab groups deployments correctly and can skip outdated ones.

Include your ci.yml in .gitlab-ci.yml ​

yml
include:
  - 'clients/luna-front-end/ci.yml'
  - 'clients/marketing-consent/ci.yml'

README.md ​

Documents the client — what it's for, and how to run it locally (usually yarn dev).

Infrastructure — application.yml ​

Standalone clients deploy as a static SPA: S3 → CloudFront → Route53, via CloudFormation (not SAM) — that's why clients carry a parameters/ folder rather than a samconfig.toml.

Naming ​

A static-SPA client only ever provisions three resource kinds — an S3 bucket, a CloudFront distribution, and a Route53 record set — no Lambdas, queues, or tables:

  • S3 bucket — physical name ${Environment}-<client-name>-and-digital-luna-bucket (the same bucket-naming rule every module follows — see .claude/rules/engineering/infrastructure.md).
  • CloudFront / Route53 — named after the domain (Aliases / Name come from the DomainName parameter), not the naming convention above.
  • Logical IDs — PascalCase, prefixed with the client name (MarketingConsentS3Bucket, not S3Bucket).

Example ​

marketing-consent's application.yml:

yml
AWSTemplateFormatVersion: '2010-09-09'
Description: Client for the Marketing Consent App

Parameters:
  DomainName:
    Type: String
  DomainNameCertificateArn:
    Type: String
  DomainHostedZoneId:
    Type: String
  Environment:
    Type: String

Resources:
  MarketingConsentS3Bucket:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName: !Sub ${Environment}-marketing-consent-and-digital-luna-bucket
      AccessControl: Private

  MarketingConsentS3BucketPolicy:
    Type: 'AWS::S3::BucketPolicy'
    Properties:
      Bucket: !Ref MarketingConsentS3Bucket
      PolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Action: s3:GetObject
            Resource: !Sub "${MarketingConsentS3Bucket.Arn}/*"
            Principal:
              AWS: !Sub "arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity ${MarketingConsentCloudFrontOAI}"

  MarketingConsentCloudFrontOAI:
    Type: AWS::CloudFront::CloudFrontOriginAccessIdentity
    Properties:
      CloudFrontOriginAccessIdentityConfig:
        Comment: !Sub "access-identity-${DomainName}.s3.amazonaws.com"

  MarketingConsentCloudFrontDistribution:
    Type: AWS::CloudFront::Distribution
    Properties:
      DistributionConfig:
        Aliases:
          - !Ref DomainName
        DefaultCacheBehavior:
          AllowedMethods:
            - GET
            - HEAD
          Compress: false
          TargetOriginId: 's3-cloudfront'
          ViewerProtocolPolicy: 'redirect-to-https'
          DefaultTTL: 60
          MaxTTL: 31536000
          MinTTL: 0
          ForwardedValues:
            QueryString: false
          SmoothStreaming: false
        DefaultRootObject: 'index.html'
        IPV6Enabled: true
        Enabled: true
        HttpVersion: 'http2'
        CustomErrorResponses:
          - ErrorCode: '403'
            ResponsePagePath: "/index.html"
            ResponseCode: '200'
            ErrorCachingMinTTL: 0
        PriceClass: PriceClass_100
        Origins:
          - DomainName: !GetAtt MarketingConsentS3Bucket.RegionalDomainName
            Id: 's3-cloudfront'
            S3OriginConfig:
              OriginAccessIdentity: !Sub "origin-access-identity/cloudfront/${MarketingConsentCloudFrontOAI}"
        ViewerCertificate:
          AcmCertificateArn: !Ref DomainNameCertificateArn
          MinimumProtocolVersion: 'TLSv1.2_2021'
          SslSupportMethod: 'sni-only'

  MarketingConsentRoute53Records:
    Type: AWS::Route53::RecordSetGroup
    Properties:
      HostedZoneId: !Ref DomainHostedZoneId
      RecordSets:
        - AliasTarget:
            DNSName: !GetAtt MarketingConsentCloudFrontDistribution.DomainName
            HostedZoneId: 'Z2FDTNDATAQYW2'
          Name: !Ref DomainName
          Type: A

Most of this can be reused for a new client by renaming the logical resource IDs.

parameters/<env>.parameters.json ​

application.yml's Parameters (Environment, DomainNameCertificateArn, DomainHostedZoneId, DomainName, and where used, BucketName) are supplied per environment via a parameters/<env>.parameters.json file rather than hardcoded in ci.yml. For marketing-consent, parameters/production.parameters.json:

json
[
  "Environment=production",
  "DomainNameCertificateArn=arn:aws:acm:us-east-1:666243557741:certificate/77fa9119-9dec-4511-9eb8-cf3a34b78d7f",
  "DomainHostedZoneId=Z0649863WKPCYTYSUI6D",
  "DomainName=data-protection.and-digital.com",
  "BucketName=marketing-consent-and-digital-luna-bucket"
]

You need one of these per environment you deploy to (polaris, sol, pulsar, staging, production — plus development if your client uses that as its default build environment).

Stack naming ​

Name your CloudFormation stack CLIENT-client-name in the ci.yml STACK_NAME variable — the anchors prepend the environment for you, so don't include it yourself.

Domain, certificates, and hosted zone ​

To make your client reachable at a domain (and its lower-environment subdomains), you need a certificate and hosted zone set up once — these are created via Terraform; speak to a tech lead for how to do this. Once you have an issued certificate and hosted zone, use their IDs in your ci.yml / parameters/ files and you're ready to deploy.

Domain naming conventions ​

Domains should be specific to the client and dash-delimited:

  • marketing-consent.luna.and-digital.com — GOOD
  • frontend.luna.and-digital.com — BAD
  • client.feedback.luna.and-digital.com — BAD

Available domains ​

  • luna.and-digital.com — production.
  • luna.and.sh — non-production.

Some clients (e.g. marketing-consent) instead sit on a domain scoped to their own product area (data-protection.and-digital.com / .and.sh) — check with a tech lead which applies to yours.

Subdomains for lower environments ​

Non-production environments are subdomains of your client's non-production domain, e.g.:

polaris.client-feedback.luna.and.sh
dev.client-feedback.luna.and.sh
staging.client-feedback.luna.and.sh

Made with ❤️ by the Luna team