-1

I’m working on a telco project that will be deployed across eight different regions.
Each region will have:

  • Different color branding

  • Possibly some UI component variations

However, all API integrations, logic, and features remain the same across regions.

I want to maintain a single centralized repository, instead of creating eight separate repos.
The challenge is: if I keep all regions in one codebase, it may lead to multiple if/else checks, which will increase code complexity and reduce maintainability.

Project stack: Next.js (App Router)

1 Answer 1

2

Define region config like this :


// src/config/regions.ts
export const regions = {
  eu: {
    theme: {
      primaryColor: '#0044cc',
      secondaryColor: '#ffcc00',
    },
    logo: '/assets/eu-logo.png',
    components: {
      Header: () => import('../components/regions/eu/Header'),
    },
  },
  us: {
    theme: {
      primaryColor: '#cc0000',
      secondaryColor: '#00ccff',
    },
    logo: '/assets/us-logo.png',
    components: {
      Header: () => import('../components/regions/us/Header'),
    },
  },
  // ... other regions
};

and after detect region dynamically in middleware, you can apply theme in main layout.


// layout.tsx
import { regions } from '../config/regions';

export default function RootLayout({ children }) {
  const region = getRegionFromRequest(); // from middleware or cookies
  const theme = regions[region].theme;

  return (
    <html style={{ '--primary-color': theme.primaryColor }}>
      <body>{children}</body>
    </html>
  );
}

or If you change components based on region, you can use dynamic import based on config.

Also you can use Tailwind CSS with theme.extend and CSS variables for dynamic colors.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.