{
  "schema_version": 1,
  "diagram_type": "architecture",
  "meta": {
    "title": "Ordermatic Infrastructure & Observability",
    "output": "ordermatic-infrastructure-observability.architecture.html",
    "quality_profile": "showcase",
    "viewBox": [1200, 645],
    "views": [
      {
        "id": "deployment",
        "label": "Deployment flow",
        "focus": ["developers", "github", "cloudbuild", "registry", "compute"],
        "note": "From push to built images and deployed compute."
      },
      {
        "id": "runtime",
        "label": "App runtime",
        "focus": ["compute", "neon", "upstash", "edge"],
        "note": "Compute reads Neon Postgres, Upstash Redis, and Cloudflare R2 / Workers."
      },
      {
        "id": "data",
        "label": "Data services",
        "focus": ["compute", "neon", "upstash"],
        "note": "Neon for app-layer Postgres, Upstash for cache and rate limiting."
      },
      {
        "id": "control",
        "label": "Control plane",
        "focus": ["control", "compute", "github"],
        "note": "Infisical secrets, Flagsmith feature flags, and CI gates."
      },
      {
        "id": "observe",
        "label": "Observability",
        "focus": ["compute", "observe"],
        "note": "OpenTelemetry, Pino, Better Stack, Langfuse, and PostHog."
      }
    ]
  },
  "components": [
    {
      "id": "developers",
      "type": "external",
      "label": "Developers",
      "sublabel": "push code",
      "pos": [40, 120],
      "size": [120, 55]
    },
    {
      "id": "github",
      "type": "cloud",
      "label": "GitHub Actions",
      "sublabel": "CI / PR gates",
      "pos": [200, 120],
      "size": [140, 55]
    },
    {
      "id": "cloudbuild",
      "type": "cloud",
      "label": "Cloud Build",
      "sublabel": "image builds",
      "pos": [400, 120],
      "size": [140, 55]
    },
    {
      "id": "registry",
      "type": "backend",
      "label": "Artifact Registry",
      "sublabel": "docker images",
      "pos": [620, 120],
      "size": [140, 55]
    },
    {
      "id": "compute",
      "type": "backend",
      "label": "Cloud Run & GCE",
      "sublabel": "webapp / workers",
      "pos": [240, 300],
      "size": [160, 55]
    },
    {
      "id": "neon",
      "type": "database",
      "label": "Neon",
      "sublabel": "Postgres",
      "pos": [460, 300],
      "size": [120, 55]
    },
    {
      "id": "upstash",
      "type": "database",
      "label": "Upstash",
      "sublabel": "cache / rate limits",
      "pos": [630, 300],
      "size": [130, 55]
    },
    {
      "id": "edge",
      "type": "cloud",
      "label": "Cloudflare",
      "sublabel": "Workers + R2",
      "pos": [250, 500],
      "size": [140, 55]
    },
    {
      "id": "control",
      "type": "security",
      "label": "Infisical + Flagsmith",
      "sublabel": "secrets / flags",
      "pos": [460, 500],
      "size": [160, 55]
    },
    {
      "id": "observe",
      "type": "database",
      "label": "Observability",
      "sublabel": "Better Stack + Langfuse + PostHog",
      "pos": [690, 500],
      "size": [220, 55]
    }
  ],
  "boundaries": [
    {
      "kind": "region",
      "label": "Ordermatic platform",
      "wraps": [
        "github",
        "cloudbuild",
        "registry",
        "compute",
        "neon",
        "upstash",
        "edge",
        "control",
        "observe"
      ]
    }
  ],
  "connections": [
    { "id": "dev-push", "from": "developers", "to": "github", "label": "push" },
    { "id": "gh-build", "from": "github", "to": "cloudbuild", "label": "trigger" },
    { "id": "build-registry", "from": "cloudbuild", "to": "registry", "label": "push image" },
    {
      "id": "deploy",
      "from": "cloudbuild",
      "to": "compute",
      "label": "deploy",
      "fromSide": "bottom",
      "toSide": "top"
    },
    {
      "id": "secrets-flags",
      "from": "control",
      "to": "compute",
      "label": "secrets + flags",
      "fromSide": "top",
      "toSide": "bottom"
    },
    {
      "id": "compute-to-neon",
      "from": "compute",
      "to": "neon",
      "label": "SQL + Drizzle",
      "fromSide": "right",
      "toSide": "left",
      "labelAt": [430, 370]
    },
    {
      "id": "compute-to-upstash",
      "from": "compute",
      "to": "upstash",
      "label": "cache",
      "fromSide": "top",
      "toSide": "top",
      "labelAt": [500, 250]
    },
    {
      "id": "compute-to-edge",
      "from": "compute",
      "to": "edge",
      "label": "R2",
      "fromSide": "bottom",
      "toSide": "top",
      "labelAt": [390, 450]
    },
    {
      "id": "compute-observe",
      "from": "compute",
      "to": "observe",
      "label": "telemetry",
      "fromSide": "bottom",
      "toSide": "top"
    }
  ],
  "cards": [
    {
      "dot": "cyan",
      "title": "Deployment",
      "items": [
        "GitHub Actions orchestrate validate, detect-versions, and Cloud Build",
        "Cloud Build pushes Docker images to Artifact Registry and deploys Cloud Run services and GCE VMs"
      ]
    },
    {
      "dot": "amber",
      "title": "Data services",
      "items": [
        "Neon Postgres is the app-layer database used by the webapp and workers via Drizzle",
        "Upstash Redis powers caching and rate limiting across services"
      ]
    },
    {
      "dot": "violet",
      "title": "Observability & control",
      "items": [
        "OpenTelemetry and Pino ship traces, logs, and metrics to Better Stack, Grafana, and PostHog",
        "Infisical injects secrets, Flagsmith evaluates feature flags, and Langfuse tracks LLM calls"
      ]
    }
  ]
}
