Skip to content

Backend Architecture

Backend Architecture

All server-side logic runs inside Next.js App Router API routes (app/api/). There are no separate microservices. Three service libraries — text filtering, reputation scoring, and anonymous fingerprinting — are shared across both API routes and edge middleware. PostgreSQL is accessed through a single connection-pool client (lib/db/client.ts). Rate limiting is currently in-memory (broken on serverless) and must be migrated to Upstash Redis before launch.

graph TD subgraph "Edge (middleware.ts)" MW["Middleware\n(rate limit · security headers)"] end subgraph "API Routes (app/api/)" PR["profiles/\nGET list · POST create\nGET [alias]"] RV["reviews/\nPOST submit\nPATCH [id]/moderate"] RP["removal/\nPOST removal request"] AB["reports/\nPOST abuse report"] end subgraph "Service Libraries (lib/)" TF["moderation/textFilter.ts\n(regex · PII · threats)"] FL["moderation/flagging.ts\n(risk score)"] RS["reputation/scorer.ts\n(weighted avg · recency decay)"] FP["anonymity/fingerprint.ts\n(hash-based reviewer ID)"] DB["db/client.ts\n(pg connection pool)"] end subgraph "Database" PG[(PostgreSQL)] end subgraph "External Services" Redis["Upstash Redis\n(rate limiting — ❌ not yet)"] HC["hCaptcha\n(CAPTCHA — ❌ not yet)"] end MW --> PR & RV & RP & AB RV --> TF --> FL RV --> FP RV --> RS PR & RV & RP & AB --> DB --> PG MW -.-> Redis RV -.-> HC

API Surface

RouteMethodDescription
/api/profilesGETList profiles (search, pagination)
/api/profilesPOSTCreate profile (admin)
/api/profiles/[alias]GETSingle profile + reviews
/api/reviewsPOSTSubmit anonymous review
/api/reviews/[id]/moderatePATCHApprove / reject / quarantine
/api/removalPOSTRemoval request submission
/api/reportsPOSTAbuse report submission

Known Issues

IssueImpactFix
Rate limiting uses in-memory MapBroken on serverless/Edge — resets per instanceMigrate to Upstash Redis
Moderation dashboard auth fails openAnyone can access without ADMIN_SECRETImplement session-based admin auth
Respect dimension missing from scorerReputation score understates respectAdd 0 % weight redistribution in scorer