Skip to main content

Infrastructure Dashboard

The Infrastructure Dashboard is an admin page at /admin/infrastructure that provides a live health view of the platform’s GCP resources. It auto-detects the current environment and polls GCP APIs every 60 seconds. For background on the underlying infrastructure, see Infrastructure Overview.

At a Glance

All sections degrade gracefully — a failed GCP API call returns null for that section only; other sections continue to render.

Architecture

Environment detection

The page detects which GCP environment it is serving by reading NEXT_PUBLIC_FIREBASE_DATABASE_ID at request time (Server Component): The environment label is displayed in the EnvironmentBanner component at the top of the page.

API route authentication

GET /api/infrastructure/status authenticates to GCP using the GOOGLE_FIREBASE_ADMIN_KEY service account JSON (also used for Firebase Admin SDK operations). It falls back to GOOGLE_SERVICE_ACCOUNT_KEY when the Firebase admin key is absent (local dev). The Firebase Admin SA requires three additional IAM roles beyond its Firebase permissions: These roles are granted by terraform/platform/modules/iam/main.tf and applied as part of the dev-shared, staging, and production Terraform environments.

GCS Infrastructure Manifest

Every Terraform environment root writes an infra-manifest/{key}.json file to gs://shokunin-480309-tfstate/ on every apply. The dashboard reads this file to populate the “declared” side of each section — the intended resource configuration before live status is overlaid.
The GcpInfraManifest TypeScript type in domains/infrastructure/types.ts defines an array-based schema (cloudRunServices[], gkeClusters[], queues[], serviceAccounts[]). The Terraform manifest files currently write a flat nested structure — aligning them to the typed schema is in progress. Until then, declared-resource sections fall back to empty arrays and the dashboard displays live GCP API data only.

Dashboard Components

All components live in app/(platform)/admin/infrastructure/components/.

Health states

All live GCP resources report one of four health states:

Domain Layer

The Infrastructure Domain (domains/infrastructure/) provides the data layer for the dashboard.

GcpStatusRepository

Provider-agnostic interface (repositories/gcp-status-repository.ts):
The HTTP implementation (repositories/http/gcp-status-repository.ts) calls GET /api/infrastructure/status from the browser. Follow the factory function pattern established in domains/workshop/repositories/ when adding new implementations.

useInfrastructureStatus

Fetches on mount, auto-refreshes every 60 seconds, clears the interval on unmount. Manages loading and error state separately so the dashboard can show stale data alongside an error banner.

resolveEnvironment

Pure function (utils/environment-resolver.ts) — accepts a process.env snapshot and returns EnvironmentContext. Fully unit-tested via environment-resolver.test.ts.

manifest-parser.ts

Pure stateless utility functions for querying a GcpInfraManifestgetCloudRunDeclarations, getServiceAccounts, etc. No I/O, no side effects, fully unit-testable.

Adding a New Dashboard Section

  1. Add a new declaration type to domains/infrastructure/types.ts
  2. Add the live status type to the same file
  3. Add the declaration to GcpInfraManifest and the status to InfrastructureStatus
  4. Add a fetch function in app/api/infrastructure/status/route.ts (follow the per-source try/catch pattern)
  5. Add the Terraform manifest field in all three environment manifest.tf files
  6. Create a new card component in app/(platform)/admin/infrastructure/components/
  7. Wire it into InfrastructureDashboard

For the GCP resource provisioning flow (how workshop containers are created), see Infrastructure Overview — Workshop provisioning flow. For IAM and secrets, see Secrets & Identity Management.