Architecture — Tenant Master: Configuration Wizard, Logo Pipeline, and Aggregated Tenant-Info Read Path

By Engineering Team•October 9, 2026•6 min read
Metadata Details
System tenant-service — Tenant Master
Document ID ARCH-2026-TEN-001
Author Engineering Team
Status Approved

Implements SR-025, per the schema decision in ADR-00039.


Components

Component Language/Runtime Role
TenantConfigPage.tsx / TenantConfigController.ts React (admin UI) 7-step wizard shell — dirty tracking, lazy per-step load, step navigation
TenantRepository.ts React/Axios (admin UI) Sole apiClient consumer for this feature
ImageUploader (shared organism) + react-easy-crop React (admin UI) Logo crop/zoom/rotate/flip, used only by the Theme step
transport/api/tenant/ Go (Echo REST) tenant-service’s admin + client controllers
service/tenantconfig/, service/tenantcontact/, service/tenantaddress/, service/tenanttheme/, service/tenantpolicy/ Go One service per wizard section; tenantpolicy handles all three PolicyType values
repository/tenantconfig/, .../tenantcontact/, .../tenantaddress/, .../tenanttheme/, .../tenantpolicy/ Go (PostgreSQL) Per-table persistence — tenant_configs, tenant_contacts, tenant_addresses, tenant_theme_styles, tenant_policies
service/tenantaggregate/ (AggregatorService.Aggregate) Go (errgroup) Concurrent fan-out read across Config/Contact/Address/Policies/ApplicationConfig for the client-facing aggregate endpoints
content-processor (async, via Pub/Sub) Go Transcodes/stores the uploaded logo under transaction tenant_logo
message_receiver/tenantlogo_receiver.go (ITenantLogoUpdateEventService.HandleImageProcessed) Go Consumes content-processor’s completion event, writes the final appLogoUrl into tenant_theme_styles
transport/grpc/tenant/ (TenantService/GetTenantCode) Go (gRPC server) Read-only tenant-code lookup, consumed by order-service

End-to-end flow (A) — Per-step independent save

  1. Admin opens a step; TenantConfigController.ts calls that step’s GET only if loadedStepsRef has no entry for it yet (SR-025 FR-02).
  2. On “Save & Next,” the controller checks the step’s own dirty flag; if clean, it advances with no network call.
  3. If dirty, TenantRepository.ts calls that section’s PUT /admin/api/v1/tenant/config/{basic|theme|contact|address} (SR-025 FR-04–FR-08).
  4. transport/api/tenant/ maps the request and calls the matching service/tenant<section>/Upsert, which validates via that section’s own domain/<feature>_validation.go and writes through its own repository — tenant_id/updated_user_id/updated_at from AuthClaims, never the body.
  5. A 404 from the preceding GET (section never saved before) is treated by the controller as an empty form, not an error (SR-025 FR-12).

End-to-end flow (B) — Logo upload and asynchronous completion

  1. On the Theme step, the admin picks/crops/rotates the logo through the shared ImageUploader + react-easy-crop.
  2. The crop is uploaded into content-processor’s pipeline under transaction name tenant_logo, keyed deterministically by the tenant’s own ID — a tenant has exactly one logo slot, so a re-upload overwrites the same object rather than creating a new one (SR-025 FR-06).
  3. The wizard shows a presigned display URL immediately for on-screen preview; this URL is never written into appLogoUrl directly — the Theme step’s own PUT (flow A) persists every other theme field in the same request, but appLogoUrl stays whatever it already was until step 4.
  4. Once content-processor finishes transcoding, it publishes a completion event; tenant-service’s message_receiver/tenantlogo_receiver.go consumes it and calls service/tenanttheme/UpdateLogoUrl, which writes the final appLogoUrl into tenant_theme_styles — a second, independent write from the admin’s own PUT, arriving asynchronously.

End-to-end flow (C) — Policy save with auto-versioning

  1. Admin edits policyContent for Terms, Privacy, or Returns, optionally inserting a placeholder token (store name, address line, phone, support email, etc.) from the quick-insert list (SR-025 FR-11).
  2. PUT /admin/api/v1/tenant/config/{terms|privacy|returns} carries only policyContent — the request never includes version.
  3. service/tenantpolicy/UpsertPolicy(policyType, ...) reads the existing row (if any) for (tenant_id, policy_type), computes the next version (v1 if none exists, else increment), and writes both policyContent and the new version (SR-025 FR-10) through repository/tenantpolicy/.
  4. The response echoes the new version, which the Terms/Privacy/Returns step renders as a read-only chip.

End-to-end flow (D) — Downstream aggregate reads and gRPC identity lookup

  1. GET /client/api/v1/tenant-info calls AggregatorService.Aggregate, which fans out concurrently (errgroup) across the Config/Contact/Address/Policies/ApplicationConfig repositories, flattens the results into one response, and resolves every placeholder token in policyContent against the freshly-read Basic/Address/Contact values before returning — gated to Status = ACTIVE and a non-blank FirebaseTenantID (SR-025 FR-13).
  2. GET /client/api/v1/policies runs the same aggregation and placeholder-resolution path, scoped to just the three policies, reachable without an authenticated session for pre-login policy display.
  3. order-service calls TenantService/GetTenantCode over gRPC (identity only, no config fan-out) when formatting an order code (SR-025 FR-14).
  4. The mobile app’s own TenantInfoService is the other side of step 1 — it performs exactly this tenant-info read on behalf of the Settings area’s About, Help & Support, Terms, Privacy, and Returns screens, so this flow’s output is what a shopper actually sees on-device. See Architecture — Customer Settings, Flow (G) for that consuming side.

Why this is simple, and what it does not yet guarantee

Splitting each wizard section into its own table and repository means every independent-save step (SR-025 FR-01) is a single-table, single-transaction write with no cross-section locking — the same shape Package Master’s single-service flow has, just across five tables instead of one. The policy-type discriminator means a fourth policy type, if ever added, is a new policy_type value and a new quick-insert-token mapping, not a new table or service.

This flow does not yet guarantee: (a) that a field the admin UI requires client-side (several Theme/Address/Contact fields, per SR-025’s Validation Parity note) is actually enforced server-side — a write that bypasses the admin form could persist a blank or malformed value; (b) that a failed logo-processing completion event is retried or surfaced to the admin — flow (B) step 4 is a fire-and-forget consumer with no compensating UI feedback if it never arrives; (c) that the wizard’s step-indicator navigation matches the admin app’s own documented non-interactive step-indicator convention. All three are tracked in Technical Debt — TD-00019.