Skip to content

Architecture · CI/CD

One Codebase, 22 Sites: A Variant Map and a CI Check

22 sites of an education product run from the same Nuxt codebase. Modules got copied and drifted apart over time. Instead of force-merging the copies I built a generated map that gives each one an identity, plus a check that keeps it from going stale in CI.

01. The problem: copies that drift silently

Each site type (speed reading, law, doctor, bank…) takes its game modules from its own folder, and from a shared one when missing. Over time a module got copied to another folder whenever it was needed. The result: 367 module files but only 127 unique component names. A module exists three times on average and the copies have drifted apart.

Merging everything into one file would be the cleanest end state, but you cannot do it without changing some site's behavior. Each copy's small difference is tied to somebody's screen.

02. The fix: do not merge, give identities

The generator (gen-module-variants.ts) scans all module files and takes a SHA-256 digest of each. Byte-identical copies collapse into one variant; the other folders sharing it are recorded as aliases. The result: 127 components, 269 variants. Each variant gets an id like BlokOkuma@abc or BlokOkuma@hizli_okuma.

The map also records the folder order in which each site type resolves a component name: the site's own override folder first, then the shared base. That order was extracted one-to-one from the project's import.meta.glob chain.

        // site_type -> folder resolution order (override first, then base)
const SITE_RESOLUTION: Record<string, string[]> = {
  soho:     ['soho', 'hizli_okuma'],
  hukuk:    ['hukuk', 'hizli_okuma'],
  disleksi: ['disleksi', 'abc'],
  y360:     ['yonerge360', 'purdikkat'],
  // ...
}
      

"Which file is the BlokOkuma on the soho site, really?" now has exactly one answer. That also makes opening a module on another site (cross-open) safe.

03. Keeping the map from going stale

The map is a generated file committed to the repo. The weak spot of that design is staleness: if someone touches a .vue file and forgets to run the generator, the map stays old and both builds still pass. The worst case: a module later gets a route or its own API call, the "site-coupled" flag stays wrong in the map, and the module's result is written to the wrong app.

To keep that from being silent the generator has a --check mode: it compares the generated output with the committed file without writing, and exits 1 if they differ. The check runs in make check and as a CI job before the build matrix. No image is built from a stale map.

        # local
npm run gen:variants        # regenerate the map
npm run check:variants      # exit 1 if it is stale

# CI: before the build matrix
#   check -> build-and-push (needs: check)
      

The rule is simple: if a generated artifact is committed, CI needs a gate that verifies it is fresh. Otherwise "generated" gets mistaken for "up to date".

If you're looking for a developer, have a question, or just want to connect, feel free to reach out to me.

You can also find me on these platforms!

© 2026 · Designed and coded by Ahmet Ali Gül