Codebase Audit Report

Generated: 2025-12-27 | Environment: preview

Executive Summary

The codebase implements a Cloudflare Workers API with Neon PostgreSQL. Authentication (Google OAuth + Turnstile) is designed but not yet implemented. Core infrastructure is operational.

ComponentStatus
Worker Entry PointOK
DB Abstraction (pg/Neon)OK
Dev Environment ProtectionOK
Webhook Deploy PipelineOK
Google OAuthMissing
Turnstile Bot ProtectionMissing
Session ManagementMissing
Database SchemaMissing
Metering SystemMissing

Key Questions Answered

Q1: Which user actions trigger a database request?

Current state: Only GET /health triggers a DB query.

RouteDB QueryFile:Line
GET /healthSELECT NOW()src/index.js:40
GET /Nonesrc/index.js:48

Grep pattern: rg "query\(env," src/

Q2: Which user actions should be metered?

Current state: No metering annotations exist. Recommended metered actions:

Implementation needed: Add @metered JSDoc tags to controllers.

Grep pattern: rg "@metered" src/

Q3: How do we track metered usage in serverless?

Recommended pattern:

  1. Each @metered endpoint emits UsageEvent to Cloudflare Queue
  2. Queue consumer aggregates by user_id + action
  3. Store aggregates in Neon with batch writes (reduce compute)
  4. Query aggregates for billing/limits

Not blocking request path - fire-and-forget to queue.

Architecture Compliance

SOLID Principles

PrincipleStatusNotes
Single Responsibility OK src/index.js = routing only, src/db/ = data access
Open/Closed Warn Need controller pattern - currently inline handlers
Liskov Substitution N/A No inheritance hierarchy yet
Interface Segregation OK Minimal query() interface
Dependency Inversion OK DB driver abstraction hides pg vs Neon

Rule Compliance

RuleStatusEvidence
No fallback env vars Warn src/db/index.js:27-31 uses fallbacks for local dev
No speculative code Warn items table in init.sql is placeholder
File naming convention Missing No controllers yet - will need get-*.controller.js
Git worktrees OK Rule documented, agents can follow
Never commit to main OK Webhook enforces PR workflow

Security Review

CheckStatusDetails
SQL Injection OK Parameterized queries via query(env, sql, params)
Env Protection (Non-Prod) OK X-Dev-Token required before any DB call
Secrets in Code OK All secrets via wrangler secret put
Auth on Protected Routes Missing No auth middleware implemented yet
HTTPS OK Enforced by Cloudflare edge

Critical: Local DB Fallbacks

src/db/index.js:27-31 uses hardcoded fallbacks for local testing. These violate the strict-env-config rule. Recommend: separate test config file or explicit test environment detection.

File Inventory

Source Files

FilePurposeDB Access
src/index.jsWorker entry, routingYes (health)
src/db/index.jsDB abstraction layerCore
webhook/server.jsGitHub webhook handlerNo

Configuration

FilePurpose
wrangler.tomlCloudflare Workers config (3 envs)
docker-compose.ymlLocal Postgres for tests
vitest.config.jsTest runner config

Documentation

7 rule files in .claude/rules/, 9 docs in docs/:

Admin Docs Architecture

Documentation is served via Worker at /docs, protected by auth. Pages projects are private storage backends.

EnvironmentDocs URLAuth
Production/docsAdmin session (TODO)
Staging/docsX-Dev-Token
Dev/docsX-Dev-Token
Preview/docsX-Dev-Token

Access: curl -H "X-Dev-Token: $TOKEN" https://app-api-preview.../docs

Full docs: See docs/08-admin-docs.md

Recommended Next Steps

  1. Fix env fallbacks - Remove hardcoded values in src/db/index.js
  2. Remove placeholder code - Delete init.sql items table
  3. Implement auth flow - Per docs/03-setup.md gap analysis
  4. Add metering annotations - @metered tags on DB-hitting routes
  5. Set up Cloudflare Queue - For async usage tracking

Grep Cheat Sheet

QuestionCommand
DB queriesrg "query\(env," src/
Metered endpointsrg "@metered" src/
All controllersrg -g "*.controller.js" ""
Env var usagerg "env\.\w+" src/
Error throwsrg "throw new Error" src/

End of Report