{
  "services": [
    {
      "id": "papermark-web",
      "name": "Papermark web app",
      "kind": "web",
      "framework": "next",
      "entrypoint": "next.config.mjs",
      "evidence": [
        {
          "file": "package.json",
          "lines": "120-135",
          "note": "Next 14 app with pages and app routers"
        },
        {
          "file": "middleware.ts",
          "lines": "53-110",
          "note": "Edge middleware for hosts, domains, auth"
        }
      ]
    },
    {
      "id": "trigger-workers",
      "name": "Trigger.dev background workers",
      "kind": "worker",
      "framework": "trigger.dev v4",
      "entrypoint": "trigger.config.ts",
      "evidence": [
        {
          "file": "trigger.config.ts",
          "lines": "1-32",
          "note": "Task dirs, ffmpeg and python, no max duration"
        },
        {
          "file": "lib/trigger/queues.ts",
          "lines": "1-40",
          "note": "Named queues with concurrency limits"
        }
      ]
    }
  ],
  "routes": [
    {
      "id": "post-mupdf-convert-page",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/mupdf/convert-page",
      "kind": "api",
      "auth": "authenticated",
      "reads": [],
      "writes": [
        {
          "dataStoreId": "postgres"
        },
        {
          "dataStoreId": "blob-storage"
        }
      ],
      "externalCallIds": [
        "vercel-edge-config"
      ],
      "work": "cpu",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/mupdf/convert-page.ts",
          "lines": "13-200",
          "note": "Internal key auth; refetches whole PDF, renders one page via mupdf"
        },
        {
          "file": "vercel.json",
          "lines": "2-5",
          "note": "2048MB memory"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "post-mupdf-annotate-document",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/mupdf/annotate-document",
      "kind": "api",
      "auth": "authenticated",
      "reads": [],
      "writes": [],
      "externalCallIds": [],
      "work": "cpu",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/mupdf/annotate-document.ts",
          "lines": "11-200",
          "note": "Internal key; fetches file, builds watermarked PDF, up to 1000 pages"
        },
        {
          "file": "vercel.json",
          "lines": "5-7",
          "note": "2048MB memory, maxDuration 300"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "all-middleware",
      "serviceId": "papermark-web",
      "method": "ALL",
      "path": "*",
      "kind": "middleware",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "redis",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "posthog"
      ],
      "work": "light",
      "trafficHint": "hot",
      "evidence": [
        {
          "file": "middleware.ts",
          "lines": "53-110",
          "note": "Host routing, JWT check, PostHog proxy"
        },
        {
          "file": "lib/middleware/domain.ts",
          "lines": "8-22",
          "note": "Redis lookup only for custom-domain root path"
        },
        {
          "file": "lib/middleware/posthog.ts",
          "lines": "1-63",
          "note": "Proxies /ingest to PostHog"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "all-auth-nextauth",
      "serviceId": "papermark-web",
      "method": "ALL",
      "path": "/api/auth/[...nextauth]",
      "kind": "api",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        },
        {
          "dataStoreId": "redis",
          "pattern": "point"
        }
      ],
      "writes": [
        {
          "dataStoreId": "postgres"
        }
      ],
      "externalCallIds": [
        "oauth-providers",
        "resend",
        "dub"
      ],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/auth/[...nextauth].ts",
          "lines": "22-200",
          "note": "NextAuth with SAML checks, rate limit, signIn events"
        },
        {
          "file": "lib/auth/auth-options.ts",
          "lines": "26-130",
          "note": "Google, LinkedIn, email, passkey, SAML providers"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "post-ai-chat-messages",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/ai/chat/[chatId]/messages",
      "kind": "api",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        },
        {
          "dataStoreId": "postgres",
          "pattern": "list"
        }
      ],
      "writes": [
        {
          "dataStoreId": "postgres"
        }
      ],
      "externalCallIds": [
        "openai"
      ],
      "work": "llm",
      "llmCalls": [
        {
          "externalCallId": "openai",
          "kind": "chat",
          "model": "gpt-4o-mini",
          "modelSource": "hardcoded",
          "callsPerRequest": 1,
          "maxOutputTokens": 420,
          "inputSize": "medium",
          "streaming": true,
          "keySource": "platform",
          "evidence": [
            {
              "file": "ee/features/ai/lib/chat/send-message.ts",
              "lines": "563-575",
              "note": "Responses API with file_search; 220 first reply, 420 later"
            }
          ]
        },
        {
          "externalCallId": "openai",
          "kind": "chat",
          "model": "gpt-4o-mini",
          "modelSource": "hardcoded",
          "callsPerRequest": 1,
          "maxOutputTokens": 200,
          "inputSize": "small",
          "streaming": false,
          "keySource": "platform",
          "evidence": [
            {
              "file": "ee/features/ai/lib/chat/send-message.ts",
              "lines": "382-410",
              "note": "Follow-up questions generated in onFinish every message"
            }
          ]
        },
        {
          "externalCallId": "openai",
          "kind": "chat",
          "model": "gpt-4o-mini",
          "modelSource": "hardcoded",
          "callsPerRequest": 1,
          "maxOutputTokens": 20,
          "inputSize": "small",
          "streaming": false,
          "frequency": "sometimes",
          "keySource": "platform",
          "evidence": [
            {
              "file": "ee/features/ai/lib/chat/generate-chat-title.ts",
              "lines": "13-25",
              "note": "Title only for first message; cap sits in providerOptions"
            }
          ]
        }
      ],
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "app/(ee)/api/ai/chat/[chatId]/messages/route.ts",
          "lines": "16-120",
          "note": "Access check, feature flag, vector store, streaming reply"
        },
        {
          "file": "ee/features/ai/lib/chat/send-message.ts",
          "lines": "437-575",
          "note": "History take 10, saves user message, streams"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "post-auth-verify-code",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/auth/verify-code",
      "kind": "api",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "redis",
          "pattern": "point"
        }
      ],
      "writes": [
        {
          "dataStoreId": "redis"
        }
      ],
      "externalCallIds": [],
      "work": "light",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "app/api/auth/verify-code/route.ts",
          "lines": "14-90",
          "note": "Rate limits by email and IP, atomic fetch-and-delete"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "post-cron-dataroom-digest-daily",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/cron/dataroom-digest/daily",
      "kind": "webhook",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "redis",
          "pattern": "list"
        },
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "qstash",
        "resend"
      ],
      "work": "long-running",
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "app/api/cron/dataroom-digest/daily/route.ts",
          "lines": "7-34",
          "note": "QStash signature checked only when VERCEL=1; 300s"
        },
        {
          "file": "lib/emails/process-dataroom-digest.ts",
          "lines": "9-31",
          "note": "Sequential per-batch queries and emails"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "post-csp-report",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/csp-report",
      "kind": "api",
      "auth": "public",
      "reads": [],
      "writes": [],
      "externalCallIds": [],
      "work": "light",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "app/api/csp-report/route.ts",
          "lines": "3-14",
          "note": "Parses report and discards it"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "get-feature-flags",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/feature-flags",
      "kind": "api",
      "auth": "public",
      "reads": [],
      "writes": [],
      "externalCallIds": [],
      "work": "light",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "app/api/feature-flags/route.ts",
          "lines": "5-22",
          "note": "Edge runtime; flag lookup helper not shown"
        }
      ],
      "confidence": "low"
    },
    {
      "id": "get-help",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/help",
      "kind": "api",
      "auth": "public",
      "reads": [],
      "writes": [],
      "externalCallIds": [
        "marketing-site"
      ],
      "work": "light",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "app/api/help/route.ts",
          "lines": "3-45",
          "note": "Fetches all articles upstream per request, filters locally"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "get-slack-oauth-authorize",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/integrations/slack/oauth/authorize",
      "kind": "api",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "app/api/integrations/slack/oauth/authorize/route.ts",
          "lines": "15-52",
          "note": "Session and team membership check, builds install URL"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "get-verify-login-link",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/verify/login-link",
      "kind": "api",
      "auth": "public",
      "reads": [],
      "writes": [],
      "externalCallIds": [],
      "work": "light",
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "app/api/verify/login-link/route.ts",
          "lines": "4-6",
          "note": "Legacy redirect to /auth/email"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "post-views-pages",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/views/pages",
      "kind": "api",
      "auth": "unknown",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        },
        {
          "dataStoreId": "redis",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "hot",
      "evidence": [
        {
          "file": "app/api/views/pages/route.ts",
          "lines": "38-120",
          "note": "Up to 15 pages per call; preview path needs session"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "post-views-dataroom",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/views-dataroom",
      "kind": "api",
      "auth": "unknown",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        },
        {
          "dataStoreId": "postgres",
          "pattern": "list"
        },
        {
          "dataStoreId": "redis",
          "pattern": "point"
        }
      ],
      "writes": [
        {
          "dataStoreId": "postgres"
        },
        {
          "dataStoreId": "redis"
        }
      ],
      "externalCallIds": [
        "resend",
        "slack",
        "tinybird"
      ],
      "work": "db-bound",
      "trafficHint": "hot",
      "evidence": [
        {
          "file": "app/api/views-dataroom/route.ts",
          "lines": "1-120",
          "note": "Viewer access: OTP email, sessions, view recording, Slack"
        }
      ],
      "confidence": "low"
    },
    {
      "id": "patch-account",
      "serviceId": "papermark-web",
      "method": "PATCH",
      "path": "/api/account",
      "kind": "api",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [
        {
          "dataStoreId": "postgres"
        },
        {
          "dataStoreId": "redis"
        }
      ],
      "externalCallIds": [
        "resend"
      ],
      "work": "db-bound",
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "pages/api/account/index.ts",
          "lines": "25-110",
          "note": "Profile update; email change sends verification via waitUntil"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "get-agreement-signing-download",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/agreements/signing/[agreementResponseId]/download",
      "kind": "api",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        },
        {
          "dataStoreId": "redis",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "documenso"
      ],
      "work": "db-bound",
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "pages/api/agreements/signing/[agreementResponseId]/download.ts",
          "lines": "31-120",
          "note": "Cookie proof required; streams signed PDF, 50MB clamp"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "get-analytics",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/analytics",
      "kind": "api",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "tinybird"
      ],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/analytics/index.ts",
          "lines": "33-110",
          "note": "Team check, then Tinybird pipe queries"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "all-conversations",
      "serviceId": "papermark-web",
      "method": "ALL",
      "path": "/api/conversations/[[...conversations]]",
      "kind": "api",
      "auth": "unknown",
      "reads": [],
      "writes": [],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/conversations/[[...conversations]].ts",
          "lines": "5-10",
          "note": "Delegates to ee handler not shown"
        }
      ],
      "confidence": "low"
    },
    {
      "id": "post-feedback",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/feedback",
      "kind": "api",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [
        {
          "dataStoreId": "postgres"
        }
      ],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/feedback/index.ts",
          "lines": "5-65",
          "note": "Unauthenticated; validates feedbackId and viewId"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "post-file-image-upload",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/file/image-upload",
      "kind": "api",
      "auth": "authenticated",
      "reads": [],
      "writes": [
        {
          "dataStoreId": "blob-storage"
        }
      ],
      "externalCallIds": [],
      "work": "light",
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "pages/api/file/image-upload.ts",
          "lines": "28-90",
          "note": "Issues Vercel Blob client upload token after session check"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "get-health",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/health",
      "kind": "api",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/health.ts",
          "lines": "5-26",
          "note": "SELECT 1 liveness probe"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "all-internal-billing-automatic-unpause",
      "serviceId": "papermark-web",
      "method": "ALL",
      "path": "/api/internal/billing/automatic-unpause",
      "kind": "api",
      "auth": "unknown",
      "reads": [],
      "writes": [],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "pages/api/internal/billing/automatic-unpause.ts",
          "lines": "5-17",
          "note": "Delegates to ee handler; waitUntil streaming enabled"
        }
      ],
      "confidence": "low"
    },
    {
      "id": "get-jobs-get-thumbnail",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/jobs/get-thumbnail",
      "kind": "api",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        },
        {
          "dataStoreId": "redis",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/jobs/get-thumbnail.ts",
          "lines": "11-56",
          "note": "Rate limited 150/min per user; resolves page image URL"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "get-links-annotations",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/api/links/[id]/annotations",
      "kind": "api",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/api/links/[id]/annotations.ts",
          "lines": "10-95",
          "note": "Gated only by viewId under 23h old"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "post-generate-ai-structure",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/teams/[teamId]/datarooms/generate-ai-structure",
      "kind": "api",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "openai"
      ],
      "work": "llm",
      "llmCalls": [
        {
          "externalCallId": "openai",
          "kind": "chat",
          "model": "gpt-4o-mini",
          "modelSource": "hardcoded",
          "callsPerRequest": 1,
          "maxOutputTokens": 600,
          "inputSize": "small",
          "streaming": false,
          "keySource": "platform",
          "evidence": [
            {
              "file": "pages/api/teams/[teamId]/datarooms/generate-ai-structure.ts",
              "lines": "105-118",
              "note": "generateObject; cap set inside providerOptions"
            }
          ]
        }
      ],
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "pages/api/teams/[teamId]/datarooms/generate-ai-structure.ts",
          "lines": "42-190",
          "note": "Team check, pause check, description max 2000 chars"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "post-webhooks-signing",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/webhooks/signing",
      "kind": "webhook",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [
        {
          "dataStoreId": "postgres"
        }
      ],
      "externalCallIds": [
        "documenso"
      ],
      "work": "db-bound",
      "trafficHint": "rare",
      "evidence": [
        {
          "file": "app/api/webhooks/signing/route.ts",
          "lines": "28-112",
          "note": "Shared-secret header; storage mirror via waitUntil"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "post-webhooks-callback",
      "serviceId": "papermark-web",
      "method": "POST",
      "path": "/api/webhooks/callback",
      "kind": "webhook",
      "auth": "authenticated",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "qstash",
        "tinybird"
      ],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "app/api/webhooks/callback/route.ts",
          "lines": "19-60",
          "note": "QStash signature verified; logs delivery result to Tinybird"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "get-page-view-link",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/view/[linkId]",
      "kind": "page",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "notion"
      ],
      "work": "db-bound",
      "trafficHint": "hot",
      "evidence": [
        {
          "file": "pages/view/[linkId]/index.tsx",
          "lines": "85-200",
          "note": "ISR revalidate 60s; Notion fetch only for notion docs"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "get-page-view-link-embed",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/view/[linkId]/embed",
      "kind": "page",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "notion"
      ],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/view/[linkId]/embed.tsx",
          "lines": "14-16",
          "note": "Reuses getStaticProps from index page"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "get-page-view-link-downloads",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/view/[linkId]/downloads",
      "kind": "page",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/view/[linkId]/downloads.tsx",
          "lines": "15-50",
          "note": "getServerSideProps looks up dataroom brand language"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "get-page-view-link-document",
      "serviceId": "papermark-web",
      "method": "GET",
      "path": "/view/[linkId]/d/[documentId]",
      "kind": "page",
      "auth": "public",
      "reads": [
        {
          "dataStoreId": "postgres",
          "pattern": "point"
        }
      ],
      "writes": [],
      "externalCallIds": [
        "notion"
      ],
      "work": "db-bound",
      "trafficHint": "normal",
      "evidence": [
        {
          "file": "pages/view/[linkId]/d/[documentId].tsx",
          "lines": "1-40",
          "note": "Static props imports link-data and Notion helpers; body truncated"
        }
      ],
      "confidence": "low"
    }
  ],
  "dataStores": [
    {
      "id": "postgres",
      "kind": "postgres",
      "provider": "Postgres via pooled URL",
      "orm": "prisma",
      "tableCount": 78,
      "connection": "pool",
      "evidence": [
        {
          "file": "prisma/schema/schema.prisma",
          "lines": "1-6",
          "note": "POSTGRES_PRISMA_URL pooled, direct URL for migrations"
        },
        {
          "file": "lib/prisma.ts",
          "lines": "1-10",
          "note": "Single PrismaClient"
        }
      ]
    },
    {
      "id": "redis",
      "kind": "redis",
      "provider": "Upstash",
      "connection": "http-api",
      "evidence": [
        {
          "file": "lib/redis.ts",
          "lines": "1-30",
          "note": "Upstash REST clients plus sliding-window rate limiter"
        },
        {
          "file": "lib/auth/link-session.ts",
          "lines": "90-103",
          "note": "Viewer sessions stored in Redis"
        }
      ]
    },
    {
      "id": "blob-storage",
      "kind": "object-storage",
      "provider": "S3 and Vercel Blob",
      "connection": "unknown",
      "evidence": [
        {
          "file": "prisma/schema/document.prisma",
          "lines": "8",
          "note": "storageType VERCEL_BLOB or S3 per document"
        },
        {
          "file": "lib/trigger/export-visits.ts",
          "lines": "2",
          "note": "Vercel Blob put for exports"
        },
        {
          "file": "lib/trigger/bulk-download.ts",
          "lines": "8-14",
          "note": "S3 and Lambda for ZIP generation"
        }
      ]
    }
  ],
  "jobs": [
    {
      "id": "inline-email-change-verification",
      "trigger": "inline",
      "description": "Email-change verification email sent via waitUntil after the response.",
      "lossImpact": "high",
      "evidence": [
        {
          "file": "pages/api/account/index.ts",
          "lines": "81-87",
          "note": "waitUntil around verification email send"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "inline-signed-agreement-mirror",
      "trigger": "inline",
      "description": "Mirrors signed agreement PDF to storage via waitUntil after the signing webhook.",
      "lossImpact": "low",
      "evidence": [
        {
          "file": "app/api/webhooks/signing/route.ts",
          "lines": "92-101",
          "note": "waitUntil mirror; download route has fallback path"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "inline-blocked-document-log",
      "trigger": "inline",
      "description": "Blocked-keyword alert logged via waitUntil in PDF page conversion.",
      "lossImpact": "low",
      "evidence": [
        {
          "file": "pages/api/mupdf/convert-page.ts",
          "lines": "186-193",
          "note": "waitUntil around log call"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "cron-dataroom-digest-daily",
      "trigger": "cron",
      "schedule": "0 9 * * *",
      "queueProvider": "qstash",
      "description": "Daily dataroom change digest emails, 300s function.",
      "evidence": [
        {
          "file": "app/api/cron/dataroom-digest/daily/route.ts",
          "lines": "7-24",
          "note": "Schedule in comment; QStash signature"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "cron-cleanup-expired-exports",
      "trigger": "cron",
      "schedule": "0 2 * * *",
      "queueProvider": "trigger.dev",
      "description": "Deletes expired export blobs tracked in Redis.",
      "evidence": [
        {
          "file": "lib/trigger/cleanup-expired-exports.ts",
          "lines": "5-10",
          "note": "schedules.task daily at 2 AM UTC"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "queue-pdf-to-image-conversion",
      "trigger": "queue",
      "queueProvider": "trigger.dev",
      "description": "Converts PDFs to page images, directly or via the mupdf route.",
      "evidence": [
        {
          "file": "lib/trigger/pdf-to-image-route.ts",
          "lines": "22-45",
          "note": "Task fetches document version, large-file threshold"
        },
        {
          "file": "lib/trigger/convert-pdf-direct.ts",
          "lines": "1-45",
          "note": "Direct mupdf rendering task"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "queue-ai-document-indexing",
      "trigger": "queue",
      "queueProvider": "trigger.dev",
      "description": "Indexes documents for AI chat: Gemini vision for images, OpenAI Files upload, vector store.",
      "evidence": [
        {
          "file": "ee/features/ai/lib/trigger/process-image-for-ai.ts",
          "lines": "91-165",
          "note": "Gemini Flash analysis then OpenAI file upload"
        },
        {
          "file": "ee/features/ai/lib/trigger/index.ts",
          "lines": "1-6",
          "note": "PDF, Excel, image and vector store tasks"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "queue-dataroom-bulk-download",
      "trigger": "queue",
      "queueProvider": "trigger.dev",
      "description": "Builds dataroom ZIPs via AWS Lambda, tracks progress in Redis, emails link.",
      "evidence": [
        {
          "file": "lib/trigger/bulk-download.ts",
          "lines": "1-40",
          "note": "Lambda invoke, 500MB ZIP parts"
        },
        {
          "file": "lib/redis-download-job-store.ts",
          "lines": "60-110",
          "note": "Job state in Redis, 3-day TTL"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "queue-export-visits",
      "trigger": "queue",
      "queueProvider": "trigger.dev",
      "description": "Exports visit CSVs from Tinybird to Vercel Blob, emails when ready.",
      "evidence": [
        {
          "file": "lib/trigger/export-visits.ts",
          "lines": "1-40",
          "note": "Bottleneck-throttled Tinybird queries"
        }
      ],
      "confidence": "high"
    },
    {
      "id": "queue-dataroom-notifications",
      "trigger": "queue",
      "queueProvider": "trigger.dev",
      "description": "Sends dataroom change and upload notifications to viewers.",
      "evidence": [
        {
          "file": "lib/trigger/dataroom-change-notification.ts",
          "lines": "1-40",
          "note": "Per-viewer notification task"
        },
        {
          "file": "lib/trigger/dataroom-upload-notification.ts",
          "lines": "1-40",
          "note": "Upload notification task"
        }
      ],
      "confidence": "medium"
    },
    {
      "id": "queue-video-optimization",
      "trigger": "queue",
      "queueProvider": "trigger.dev",
      "description": "ffmpeg video probing and optimization, plus length backfill.",
      "evidence": [
        {
          "file": "lib/trigger/optimize-video-files.ts",
          "lines": "1-40",
          "note": "fluent-ffmpeg, 500MB optimization cap"
        },
        {
          "file": "lib/trigger/backfill-video-lengths.ts",
          "lines": "1-40",
          "note": "Paged backfill"
        }
      ],
      "confidence": "medium"
    }
  ],
  "externals": [
    {
      "id": "openai",
      "category": "llm",
      "provider": "OpenAI",
      "blocking": true,
      "evidence": [
        {
          "file": "ee/features/ai/lib/chat/send-message.ts",
          "lines": "1-2",
          "note": "AI SDK OpenAI provider, file_search tool"
        },
        {
          "file": "ee/features/ai/lib/models/openai.ts",
          "lines": "1-5",
          "note": "OpenAI SDK client for files and vector stores"
        }
      ]
    },
    {
      "id": "google-vertex",
      "category": "llm",
      "provider": "Google Vertex AI (Gemini)",
      "blocking": false,
      "evidence": [
        {
          "file": "ee/features/ai/lib/trigger/process-image-for-ai.ts",
          "lines": "91-93",
          "note": "Gemini vision inside background task"
        }
      ]
    },
    {
      "id": "stripe",
      "category": "payments",
      "provider": "Stripe",
      "blocking": true,
      "evidence": [
        {
          "file": "ee/stripe/index.ts",
          "lines": "1-30",
          "note": "Old and new Stripe accounts"
        }
      ]
    },
    {
      "id": "resend",
      "category": "email",
      "provider": "Resend",
      "blocking": true,
      "evidence": [
        {
          "file": "lib/emails/send-custom-domain-setup.ts",
          "lines": "3-24",
          "note": "sendEmail from lib/resend"
        }
      ]
    },
    {
      "id": "qstash",
      "category": "other",
      "provider": "Upstash QStash",
      "blocking": false,
      "evidence": [
        {
          "file": "app/api/webhooks/callback/route.ts",
          "lines": "1-25",
          "note": "Signature verification of QStash callbacks"
        },
        {
          "file": "app/api/cron/dataroom-digest/daily/route.ts",
          "lines": "3",
          "note": "Cron receiver"
        }
      ]
    },
    {
      "id": "trigger-dev",
      "category": "other",
      "provider": "Trigger.dev",
      "blocking": false,
      "evidence": [
        {
          "file": "trigger.config.ts",
          "lines": "1-10",
          "note": "Project and task directories"
        }
      ]
    },
    {
      "id": "documenso",
      "category": "other",
      "provider": "Documenso e-signature",
      "blocking": true,
      "evidence": [
        {
          "file": "app/api/webhooks/signing/route.ts",
          "lines": "28-35",
          "note": "Documenso webhook secret"
        }
      ]
    },
    {
      "id": "tinybird",
      "category": "analytics",
      "provider": "Tinybird",
      "blocking": true,
      "evidence": [
        {
          "file": "pages/api/analytics/index.ts",
          "lines": "9-17",
          "note": "Duration pipes"
        },
        {
          "file": "app/api/webhooks/callback/route.ts",
          "lines": "4",
          "note": "recordWebhookEvent"
        }
      ]
    },
    {
      "id": "vercel-edge-config",
      "category": "other",
      "provider": "Vercel Edge Config",
      "blocking": true,
      "evidence": [
        {
          "file": "pages/api/mupdf/convert-page.ts",
          "lines": "174-176",
          "note": "Blocked keywords read per page"
        }
      ]
    },
    {
      "id": "notion",
      "category": "other",
      "provider": "Notion",
      "blocking": true,
      "evidence": [
        {
          "file": "pages/view/[linkId]/index.tsx",
          "lines": "171-182",
          "note": "notion.getPage during static regeneration"
        }
      ]
    },
    {
      "id": "slack",
      "category": "other",
      "provider": "Slack",
      "blocking": false,
      "evidence": [
        {
          "file": "app/api/views-dataroom/route.ts",
          "lines": "24-27",
          "note": "notifyDataroomAccess and notifyDocumentView"
        }
      ]
    },
    {
      "id": "posthog",
      "category": "analytics",
      "provider": "PostHog",
      "blocking": false,
      "evidence": [
        {
          "file": "lib/middleware/posthog.ts",
          "lines": "1-63",
          "note": "Reverse proxy to PostHog EU"
        }
      ]
    },
    {
      "id": "dub",
      "category": "analytics",
      "provider": "Dub",
      "blocking": true,
      "evidence": [
        {
          "file": "pages/api/auth/[...nextauth].ts",
          "lines": "190-200",
          "note": "Sign-up lead tracking"
        }
      ]
    },
    {
      "id": "oauth-providers",
      "category": "auth",
      "provider": "Google and LinkedIn OAuth",
      "blocking": true,
      "evidence": [
        {
          "file": "lib/auth/auth-options.ts",
          "lines": "30-57",
          "note": "OAuth provider config"
        }
      ]
    },
    {
      "id": "marketing-site",
      "category": "other",
      "provider": "Papermark marketing site",
      "blocking": true,
      "evidence": [
        {
          "file": "app/api/help/route.ts",
          "lines": "7-10",
          "note": "Fetches help articles upstream"
        }
      ]
    }
  ],
  "realtime": [
    {
      "kind": "sse",
      "provider": "Trigger.dev realtime",
      "evidence": [
        {
          "file": "package.json",
          "lines": "86",
          "note": "@trigger.dev/react-hooks for run progress"
        },
        {
          "file": "prisma/schema/redaction.prisma",
          "lines": "12-15",
          "note": "Run ids stored so the UI can resubscribe"
        }
      ]
    }
  ],
  "warnings": [
    "Truncated sources: views-dataroom (120 of 1545 lines), chat messages route (120 of 190), convert-page (200 of 369). Reads, writes, waitUntil jobs and title generation beyond those lines are unverified.",
    "maxOutputTokens for gpt-4o-mini sits in providerOptions.openai in generate-ai-structure and generate-chat-title. These caps may not be applied, so output could effectively be uncapped.",
    "The chat stream's onFinish makes an extra gpt-4o-mini call for suggested questions on every message. It sits on top of the file_search call, which has its own OpenAI cost.",
    "Many handlers were not shown, including the weekly digest, domains, welcome-user and year-in-review crons, /api/views, links, and most team routes. They are not emitted as routes.",
    "The daily digest cron verifies the QStash signature only when VERCEL=1.",
    "convert-page fetches the entire PDF on every page call, so conversion cost scales with pages times file size.",
    "The ee conversations and automatic-unpause handlers are delegated and were not shown, so their auth and work are unknown."
  ],
  "schemaVersion": 1,
  "meta": {
    "source": "github",
    "repo": "https://github.com/mfts/papermark",
    "analyzedAt": "2026-10-28T00:16:47.204Z",
    "fileCount": 1807,
    "extractorModel": "anthropic/claude-sonnet-5.5",
    "skeramVersion": "0.0.1",
    "commit": "ed19717ec02a",
    "framework": "next",
    "deployHint": "vercel"
  }
}