Skip to content

docs: update architecture, API reference, and tRPC integration documentation#1448

Merged
jaypatrick merged 4 commits intomainfrom
copilot/update-architecture-and-api-docs
Mar 29, 2026
Merged

docs: update architecture, API reference, and tRPC integration documentation#1448
jaypatrick merged 4 commits intomainfrom
copilot/update-architecture-and-api-docs

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 29, 2026

Description

Four documentation files were stale after the Clerk → Better Auth migration, the Hono routing refactor (Phase 4 domain route split), and the addition of the tRPC v11 API layer. This PR brings SYSTEM_ARCHITECTURE.md, hono-routing.md, api-reference.md, and trpc.md into sync with the current codebase, and registers trpc.md in docs/SUMMARY.md. Endpoint auth tier labels in api-reference.md have been corrected to match ROUTE_PERMISSION_REGISTRY, and import paths and procedure descriptions in trpc.md have been corrected based on review feedback.

Changes

  • docs/architecture/SYSTEM_ARCHITECTURE.md

    • STATIC_ASSETSASSETS binding (matches wrangler.toml / worker/types.ts)
    • Removed Clerk from ExternalServices; added BetterAuth node inside MonolithWorker and APIWorker subgraphs with auth class styling
    • FrontendAPI edge: dashed "not yet wired" → solid arrow reflecting env.API.fetch() now live in frontend/server.ts
    • Updated both summary paragraphs: Better Auth runs in-Worker backed by Neon via Hyperdrive; no external auth service
  • docs/architecture/hono-routing.md

    • Replaced stale 16-node middleware flowchart with accurate 11-step diagram matching actual hono-app.ts order:
      timing → X-API-Version → metadata → SSR detection → Better Auth handler → agent router → PoC/pre-auth shortcuts → unified auth → CORS → secure-headers → prettyJSON → routes sub-app
    • Added isSSR to the Context Variables table
    • Added explanatory note: Better Auth mounts before unified auth so sign-in/sign-up flows aren't intercepted
    • Updated tRPC section description to reference Better Auth
  • docs/api-reference.md

    • Replaced JSDoc-only stub with a full REST + library reference:
      • Auth section: Better Auth session tokens and API keys; Clerk JWT marked deprecated
      • Rate-limit tier table (anonymous / free / pro / admin)
      • ~60-row endpoint summary table across all domains (compile, queue, config, rules, monitoring, keys, workflows, admin, tRPC)
      • curl examples for sync compile, sign-in, health check, and async queue polling
      • TypeScript Library API section retained; Further Reading links added
    • Corrected auth tier labels to match ROUTE_PERMISSION_REGISTRY:
      • /api/compile/async and /api/compile/batch/async: Free+Pro+
      • /api/queue/stats: NoFree+
      • /api/configuration/validate and /api/configuration/resolve: NoFree+
      • /api/metrics/prometheus: NoAdmin
      • /api/workflow/compile and /api/workflow/:id: Free+Pro+
    • Added Pro-tier callout to the async compile curl example
  • docs/architecture/trpc.md

    • Added file layout section documenting the complete worker/trpc/ directory structure
    • Added TrpcContext interface documentation (env, authContext, requestId, ip, analytics)
    • Added procedure builder table (publicProcedure / protectedProcedure / adminProcedure) with auth requirements and error codes
    • Updated mount-point flowchart: added rateLimitMiddleware and ZTA gate (checkUserApiAccess + trackApiUsage) nodes before handleTrpcRequest, matching hono-app.ts lines 575–600
    • Added Client section: httpBatchLink batching behaviour, AppRouter type import, createTrpcClient usage examples
    • Added "Adding a new procedure" walkthrough with skeleton code and v1/index.ts registration
    • Added Testing section: createCallerFactory pattern for unit tests without HTTP overhead
    • Corrected v1.compile.json description: now reads "user session or API key" instead of implying session-only access
    • Fixed bare specifier imports in Testing section → relative paths (./init.ts, ./router.ts, ./context.ts)
    • Fixed import path depth in createTrpcClient and AppRouter examples to 4 levels with a comment noting the depth depends on the calling file's location
  • docs/SUMMARY.md

    • Registered trpc.md under the Architecture section so it appears in the mdBook navigation

Testing

  • Unit tests added/updated
  • Manual testing performed — all updated Mermaid diagrams validated and rendered successfully; all tier corrections verified against worker/utils/route-permissions.ts
  • CI passes

Zero Trust Architecture Checklist

This PR does not touch worker/ or frontend/ — ZTA checklist not required.

Original prompt

The repository's Architecture and API Documentation are outdated and need revisions to reflect recent changes in the system. The updates will target the following areas:\n\n1. Architecture Documentation:\n - Update the docs/architecture directory files to reflect the current state of the system's design, components, and workflows.\n - Modify or replace diagrams, descriptions, and technical workflows to align with recent architectural updates in the repository.\n\n2. API Documentation:\n - Revise the docs/api-reference.md file to include accurate endpoint definitions, request/response parameters, and any new APIs.\n - Add or update examples for API usage, noting deprecated or removed APIs.\n - Incorporate details from the docs/api folder into the api-reference.md file if necessary to ensure comprehensiveness.\n\nThese updates will ensure the documentation aligns with the current codebase and project requirements, providing clear and accurate information to both contributors and users.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Lots of our /docs are out of date. How to upgrade the content with burning through a lot of tokens?

Assistant: To update your /docs content efficiently without burning a lot of tokens, here's a step-by-step plan:

1. Audit Existing /docs

  • Start by listing all files currently in the /docs directory. Tools like ls (locally) or GitHub's file browser can help you see what’s present.
  • Review the overall structure and identify key outdated documents.
  • Summarize which docs are outdated, need minor revisions, or are missing entirely.

Token Efficiency Tip: Extract file lists and top-level information without opening or processing entire files at once.

2. Refine and Prioritize Scope

  • Break the task into smaller, focused updates. Prioritize critical documents first (like READMEs, installation guides, or feature specs).
  • If some docs are frequently referenced or require immediate corrections, tackle these first.

3. Use Code Search for Relevant Content

  • Use keyword-based code search to find sections where files are explicitly mentioned (e.g., referenced in README files, scripts, or online guides).
  • For documents with unclear sourcing, search related terms in the repo.

Example Code Search:

path:/docs/ content:<keyword>

4. GitHub Tools to Minimize Manual Work

  • Use GitHub's semantic search tools when rewriting content to find code and context referred to in the docs.
  • Search for APIs or utilities mentioned in the docs to ensure references are accurate and weed out obsolete code snippets.

Example semantic queries:

  • "How is logging implemented in the repo?"
  • "Where does the configuration file belong?"

5. Leverage Contributors or Reviews

  • If your repository is public, consider opening an issue or pull request asking for community help.
  • Mention which documents specifically need updating and encourage contributors to tackle these as smaller pull requests.

6. Batch Questions and Tools Usage

  • Generate a replacement for one doc at a time, and only if changes are major.
  • For smaller tweaks, edit file-by-file locally, run diff checks, and make commit-based updates.

7. Update and Test Incrementally

  • Push incremental changes instead of oversaturating updates in a single PR. This makes reviews easier and ensures minimal rewrites.
  • Use branch protection rules and request code-owner approvals to verify doc integrity.

Let me know if you’d like help auditing, searching related content, or generating updated templates!

User: Auditing and updating docs

Assistant: To effectively audit and update the /docs content in your jaypatrick/adblock-compiler repository, follow this structured approach:


1. Audit Existing Documentation

a. Inventory the /docs Directory

  • Use GitHub to list all files in the /docs directory.
  • Identify the key files, such as guides, tutorials, READMEs, or API references.
  • Determine if there’s an overarching structure or table of contents that ties the docs together.

b. Categorize Documents

  • Categorize files into the following:
    • Accurate & Current: No updates needed.
    • Minor Edits Required: If parts of the document are outdated or unclear.
    • Major Rewrite Needed: If the information is largely obsolete.
    • Missing Documents: Identify topics that should exist but don’t.

c. Highlight Critical Docs

  • Focus on onboarding-critical docs, such as the main README and beginner guides.

Token Efficiency Tip: Use GitHub’s ls-tree or API to extract the directory structure and file metadata without loading file contents directly.


2. Updating the Content

a. Evaluate Language Composition

  • Since the ...

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@jaypatrick jaypatrick added the documentation Improvements or additions to documentation label Mar 29, 2026
@jaypatrick jaypatrick added this to the beta milestone Mar 29, 2026
@jaypatrick
Copy link
Copy Markdown
Owner

@copilot Don't forget to document the new Trpc integration

- SYSTEM_ARCHITECTURE.md: replace STATIC_ASSETS→ASSETS binding, remove
  deprecated Clerk node, add BetterAuth inside MonolithWorker/APIWorker
  subgraphs, mark FrontendAPI service binding as wired, update summaries

- hono-routing.md: replace stale middleware pipeline flowchart with
  accurate 11-step diagram (timing, X-API-Version, metadata, SSR
  detection, Better Auth handler, agent router, POC/pre-auth paths,
  unified auth, CORS, secure headers, prettyJSON, routes sub-app);
  add isSSR to context variable table; update tRPC description

- api-reference.md: replace JSDoc-only stub with comprehensive REST +
  library reference including auth methods, rate-limit tiers, ~60-row
  endpoint summary table, curl examples, and further-reading links

Agent-Logs-Url: https://github.com/jaypatrick/adblock-compiler/sessions/80a9ff5c-00a8-4f68-9bdf-12a409f10bec

Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
Copilot AI changed the title [WIP] Update architecture and API documentation to reflect recent changes docs: update architecture and API reference to reflect Better Auth migration and current middleware pipeline Mar 29, 2026
Copilot AI requested a review from jaypatrick March 29, 2026 08:20
- Add file layout section (worker/trpc/ directory tree)
- Add TrpcContext interface documentation
- Add procedure builder table (public/protected/admin)
- Update mount-point flowchart: add rateLimitMiddleware and ZTA gate
  nodes before handleTrpcRequest (matching hono-app.ts lines 575-600)
- Add Client section: httpBatchLink batching, AppRouter type import,
  createTrpcClient usage examples
- Add 'Adding a new procedure' skeleton with v1/index.ts registration
- Add Testing section: createCallerFactory pattern (no HTTP overhead)
- Register trpc.md in docs/SUMMARY.md under Architecture section

Agent-Logs-Url: https://github.com/jaypatrick/adblock-compiler/sessions/84a21688-845f-4605-ac25-734497977a29

Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 29, 2026

@copilot Don't forget to document the new Trpc integration

Done in f347054. docs/architecture/trpc.md now covers the full integration:

  • File layout — complete worker/trpc/ directory tree with role of each file
  • TrpcContext interfaceenv, authContext, requestId, ip, analytics
  • Procedure builders tablepublicProcedure / protectedProcedure / adminProcedure with auth requirements and error codes
  • Updated mount-point flowchart — now shows the rateLimitMiddleware and ZTA gate (checkUserApiAccess + trackApiUsage) that run before handleTrpcRequest
  • Client sectionhttpBatchLink batching behaviour, AppRouter type import, createTrpcClient usage examples
  • Adding a new procedure — skeleton code + v1/index.ts registration
  • TestingcreateCallerFactory pattern for unit tests without HTTP overhead

Also added trpc.md to docs/SUMMARY.md so it appears in the mdBook navigation under Architecture.

Copilot AI changed the title docs: update architecture and API reference to reflect Better Auth migration and current middleware pipeline docs: update architecture, API reference, and tRPC integration documentation Mar 29, 2026
@jaypatrick jaypatrick requested review from Copilot and removed request for jaypatrick March 29, 2026 08:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the project’s documentation to reflect the current post–Clerk migration architecture (Better Auth), the Phase 4 Hono routing refactor, and the tRPC v11 API layer, keeping mdBook navigation in sync.

Changes:

  • Refreshed architecture diagrams and routing/middleware ordering docs to match worker/hono-app.ts.
  • Expanded the API reference into a REST + library guide with auth/rate-limit tiers, endpoint summaries, and usage examples.
  • Added/expanded tRPC documentation (layout, context, builders, mount-point flow, client usage, and testing guidance) and linked it in docs/SUMMARY.md.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
docs/architecture/trpc.md Adds comprehensive tRPC layer documentation (structure, context, client/testing, mount-point flow).
docs/architecture/hono-routing.md Updates the middleware/routing diagram and context vars to match current Hono app ordering.
docs/architecture/SYSTEM_ARCHITECTURE.md Updates architecture diagrams/summary for Better Auth + ASSETS binding + SSR worker → API service binding wiring.
docs/api-reference.md Replaces stub with full REST endpoint summary, auth/rate-limit tiers, examples, and links to deeper docs.
docs/SUMMARY.md Registers the new tRPC documentation page in mdBook navigation.

@jaypatrick
Copy link
Copy Markdown
Owner

@copilot apply changes based on the comments in this thread

@jaypatrick jaypatrick marked this pull request as ready for review March 29, 2026 08:38
trpc.md:
- v1.compile.json: "user session or API key" (not session-only)
- Testing imports: bare specifiers → relative paths (./init.ts, etc.)
- createTrpcClient example: use 4-level relative path with depth note
- AppRouter example: use 4-level relative path with depth note

api-reference.md:
- /compile/async + /compile/batch/async: Free+ → Pro+
- /queue/stats: No → Free+
- /configuration/validate + /configuration/resolve: No → Free+
- /metrics/prometheus: No → Admin
- /workflow/compile + /workflow/:id: Free+ → Pro+
- Async compile curl example: add Pro-tier required note

Agent-Logs-Url: https://github.com/jaypatrick/adblock-compiler/sessions/0b13188b-ffcd-4cef-b808-f3537d7ec35f

Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 29, 2026

@copilot apply changes based on the comments in this thread

All 10 review comments addressed in 5070221:

docs/architecture/trpc.md

  • v1.compile.json description now reads "Requires an authenticated context (protectedProcedure; user session or API key)" — no longer implies session-only
  • Testing section bare specifiers (worker/trpc/init.ts, etc.) replaced with relative paths (./init.ts, ./router.ts, ./context.ts)
  • createTrpcClient and AppRouter import examples updated to use 4-level relative paths with a comment explaining depth depends on calling file location

docs/api-reference.md — all tiers corrected per ROUTE_PERMISSION_REGISTRY:

  • /compile/async + /compile/batch/async: Free+Pro+
  • /queue/stats: NoFree+
  • /configuration/validate + /configuration/resolve: NoFree+
  • /metrics/prometheus: NoAdmin
  • /workflow/compile + /workflow/:id: Free+Pro+
  • Async compile curl example annotated with "Requires Pro tier" note

Copilot AI requested a review from jaypatrick March 29, 2026 08:41
@jaypatrick jaypatrick closed this Mar 29, 2026
@github-actions github-actions bot deleted the copilot/update-architecture-and-api-docs branch March 29, 2026 08:59
@jaypatrick jaypatrick restored the copilot/update-architecture-and-api-docs branch March 29, 2026 09:00
@jaypatrick jaypatrick reopened this Mar 29, 2026
@jaypatrick
Copy link
Copy Markdown
Owner

@copilot finish your work

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 29, 2026

@copilot finish your work

All work is complete. All 10 automated review comments were addressed in 5070221, CodeQL passed, and CI is green for the docs-only changes. The PR is ready for merge.

@jaypatrick jaypatrick merged commit 6f7f5f0 into main Mar 29, 2026
53 checks passed
@jaypatrick jaypatrick deleted the copilot/update-architecture-and-api-docs branch March 29, 2026 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants