The Atlas MikeAzureDev's documentation, bound to its code
140 documents

Keeping the fork publishable

The discipline that lets a private Azure fork ship AGPL source without leaking deployment IP: the three-repo, three-tier model, the upstream PRs, and the leakage gates.

Tier A — upstream PR plan

The upstream Mike repository is the AGPL source we cloned from. We want to submit changes back so that we can keep merging future upstream releases without re-resolving the same provider-boundary conflicts every time.

This document covers only the Tier A changes — the provider-boundary refactors that contain zero Azure dependency. Tier B (Azure adapters) and Tier C (deployment IP) are covered elsewhere.

Strategy

  • Granularity: one PR per boundary. Reviewers can accept storage independently of auth; bundling them creates a "block" problem where one nit holds up both.
  • Commit shape: a single commit per PR. Each PR is a refactor-without-behaviour-change. A single commit is easier to review; the upstream maintainer can squash-merge cleanly.
  • No Azure imports anywhere in any A-tier diff. If a file imports @azure/*, it is Tier B and does not appear in the A-tier extraction. The storage.ts and middleware/auth.ts extractions must therefore be partial-file patches that include only the provider-neutral portions.
  • Behaviour parity for the existing default. With AUTH_PROVIDER unset (or set to supabase), the post-PR middleware must behave identically to the upstream baseline. Ditto for the storage path with R2 env vars set.

Pre-existing design docs

Two of these PRs have already been thought through in detail:

The agent should treat those documents as the spec for the PR descriptions; they list the exact interface, the exact acceptance criteria, and the explicit "what stays in the fork" exclusions.

PR 1 — Storage provider interface

Branch name: feat/storage-provider-interface Single commit message: refactor(storage): extract StorageProvider interface and R2Provider

Files in the PR:

What MUST NOT appear in the PR:

  • The import { BlobServiceClient, ContainerClient } from "@azure/storage-blob"; and import { DefaultAzureCredential } from "@azure/identity"; lines.
  • The AzureBlobProvider class.
  • The Azure branch in createProvider().
  • The "Azure Blob Storage requires AZURE_STORAGE_…" error message in the factory's "no provider" exception text.

Extraction approach (for the agent):

  1. Start from the upstream baseline b780a4b:backend/src/lib/storage.ts.
  2. Apply only:
    • The StorageProvider interface.
    • The R2Provider class (lifted-and-shifted from the existing module-level functions, no behaviour change).
    • The createProvider() factory containing only the R2 branch and the "no provider configured" final throw.
    • The singleton initialization with _provider / _initError / requireProvider.
    • The four public functions delegating to the singleton.
    • The storageEnabled export derived from _provider !== null.
  3. Keep the existing storageKey, pdfStorageKey, generatedDocKey, versionStorageKey, storageExtension, normalizeDownloadFilename, sanitizeDispositionFilename, encodeRFC5987, buildContentDisposition helpers (unchanged from upstream).

Acceptance: with R2_ENDPOINT_URL + R2_ACCESS_KEY_ID + R2_SECRET_ACCESS_KEY set, every call site behaves identically to upstream. With those env vars unset, the server starts (no provider) and read operations return null while writes throw a clear error.

PR description: lift the rationale + acceptance bullets from docs/issues/azure-migration/006.1-storage-provider-interface.md.

PR 2 — Auth provider interface

Branch name: feat/auth-provider-interface Single commit message: refactor(auth): extract AuthProvider interface and Supabase provider

Files in the PR:

  • backend/src/lib/auth/types.ts — new file, exports AuthPrincipal and AuthValidationResult. Includes the displayName field — keep this generic enough that other IdPs (Auth0, Clerk, custom JWT) can populate it.
  • backend/src/lib/auth/providers/supabase.ts — new file, validateSupabaseToken lifted from the upstream middleware.
  • backend/src/middleware/auth.ts — replaces inline Supabase validation with provider dispatch on process.env.AUTH_PROVIDER, defaulting to "supabase". Unknown values throw 500 — the agent must not include Entra/local branches in the upstream PR.
  • res.locals.principal becomes the canonical surface; existing res.locals.userId and res.locals.userEmail continue to be set for callers that haven't migrated.

What MUST NOT appear in the PR:

Extraction approach (for the agent):

  1. Start from upstream baseline b780a4b:backend/src/middleware/auth.ts.
  2. Diff that against our claude/agpl-compliance-analysis-VSy2J:HEAD to see the full delta.
  3. Apply only:
    • The new auth/types.ts file.
    • The new auth/providers/supabase.ts file (a lift-and-shift of the existing inline validation, plus the principal-shaped return).
    • In middleware/auth.ts: replace the inline Supabase validation with a switch on process.env.AUTH_PROVIDER ?? "supabase", calling validateSupabaseToken for the supabase branch and returning 500 for any other value.
    • Set res.locals.principal from the validation result, in addition to the existing userId / userEmail / token.

Acceptance: with AUTH_PROVIDER unset (or supabase), every upstream route behaves identically. With AUTH_PROVIDER=anything-else, the middleware returns 500 with a clear message.

PR description: lift from 006.2-auth-provider-interface.md.

PR 3 — (Optional, deferred) JSONB shared-with fix

backend/src/lib/access.ts and backend/src/routes/projects.ts contain a real bug fix: passing a JS array to PostgREST's .contains() on a JSONB column emits Postgres array-literal syntax, which Postgres rejects. The fix passes a JSON-stringified array instead.

This is a clean upstream bug-fix PR, no Azure involvement. We are deferring it — it is included in the Tier B publication and we will revisit upstreaming after PR 1 and PR 2 land. Listed here so we don't forget it.

Branch name (when we get to it): fix(projects): JSONB containment for shared_with

PR 4 — (Optional, deferred) OpenAI provider adapter

backend/src/lib/llm/openai.ts adds plain OpenAI alongside the existing Claude/Gemini adapters. The shape mirrors the upstream adapter contract exactly. Could be a clean upstream addition.

Why deferred: ships in Tier B as part of the AOAI work. No Azure dependency in this file specifically, but the model-routing in models.ts interleaves OpenAI + AOAI tiers and would need splitting out for a clean PR. Not worth the work right now.

Submission order

  1. PR 1 (storage) and PR 2 (auth) can be opened simultaneously — they touch disjoint files.
  2. Wait for both to merge before publishing the Tier B fork. The public fork's first commit will then be a clean rebase against the post-merge upstream HEAD, and our published delta becomes smaller and easier for outside reviewers to read.
  3. If upstream rejects either PR (or sits on it for >30 days), proceed with the public fork publication anyway. The provider abstractions ship in Tier B regardless; upstream merging them is a "future merges are easier" benefit, not a blocker for the AGPL §13 obligation.

Per-PR self-test the agent must run before opening

For each PR, on a fresh checkout of upstream + the PR branch:

  1. npm install --prefix backend
  2. npm run build --prefix backend
  3. With R2_ENDPOINT_URL/R2_ACCESS_KEY_ID/R2_SECRET_ACCESS_KEY exported (any non-empty values are fine for this test — the provider construction is lazy enough that no real R2 call is made at startup), node dist/index.js must boot without error.
  4. With those env vars cleared and SUPABASE_URL / SUPABASE_SECRET_KEY set, node dist/index.js must boot. (The server must not require storage to start.)

For PR 2 specifically, after step 4, curl -i -H 'Authorization: Bearer totally-invalid' http://localhost:3001/health must return 200 (no auth required for /health), and any authenticated route must return 401. With AUTH_PROVIDER=anything-bogus, the same authenticated route must return 500 with a clear message.