I. Codebase

One codebase tracked in revision control, many deploys

“A twelve-factor app is always tracked in a version control system, such as Git, Mercurial, or Subversion.” – 12factor.net

When to use

Always. This is the definition of a modern app.

Why it matters

  • Consistency: ensures that the same code is deployed to all environments.
  • Collaboration: enables multiple developers to work on the same app.

Signs of Violation

  • Multiple apps sharing the same repo references (Monorepo is fine, but “one repo = multiple separate apps” is nuanced).
  • Code is shared by copy-pasting code into another repo.
  • “Production” code version is not in Git, but was edited on the server.

Explanation

Problem

If you have multiple codebases for one app (e.g., api-v1 repo and api-v2 repo for the same running service), or if you lack version control, you lose track of what is running where.

Solution

One repo maps to one app. That app may be deployed 10 times (staging, prod-us, prod-eu), but the code comes from one place.

Real world analogy

A car model design document. The “2024 Honda Civic” design (Codebase) is stored in one master file. From that file, factories build thousands of actual cars (Deploys). You don’t redraw the blueprints for every single car.

Pros and Cons

Pros Cons
  • Single Source of Truth
  • Traceability
  • None (Git is standard)
  • Comparison

    • Monorepo: 12-Factor originally frowned on Monorepos, but modern interpretation accepts them if each “App” inside the monorepo is treated as a distinct build artifact.

    Code example

    Typescript

    Bad (Violation)

    Good (Adherence)

    PHP

    Bad (Violation)

    Good (Adherence)