YOU MUST LOCATE A REFERENCE BEFORE YOU BUILD. NO EXCEPTIONS.
Reference Engine: The Universal Reference-First System
Overview
Every domain has thousands of hours of professional engineering already completed. APIs have been designed, schemas have been refined, pipelines have been battle-tested, patterns have been hardened. Leveraging them as your reference is not laziness — it is engineering intelligence.
Core principle: Before building ANYTHING, locate the best existing reference. Extract its patterns. Build on proven foundations, not assumptions.
No exceptions. No workarounds. No shortcuts.
The Prime Directive
NO BUILDING WITHOUT A REFERENCE
If you have not searched for proven references in the domain you are working in, you are disregarding thousands of hours of professional engineering. A payment API should resemble Stripe's API patterns, not a generic AI-generated endpoint.
When to Use
Always. This protocol is the router. It determines WHICH reference system to engage based on what is being built.
digraph reference_router {
rankdir=TB;
node [shape=box style=filled];
task [label="Task Received" fillcolor=lightyellow shape=doublecircle];
classify [label="Classify Task Domain" fillcolor=lightyellow];
ui [label="UI / Frontend?\n-> ux-patterns\n-> ui-engineering\n-> design-integration" fillcolor="#e8f5e9"];
website [label="Website Design?\n-> design-research\n-> ux-patterns" fillcolor="#e8f5e9"];
code [label="Code / Library?\n-> github-search (external)\n-> codebase-research (internal)\n-> pattern-matching" fillcolor="#e8f5e9"];
api [label="API Design?\n-> API References\n(this protocol)" fillcolor="#fff3e0"];
database [label="Database / Schema?\n-> Schema References\n(this protocol)" fillcolor="#fff3e0"];
testing [label="Testing Strategy?\n-> Testing References\n(this protocol)" fillcolor="#fff3e0"];
devops [label="CI/CD / DevOps?\n-> DevOps References\n(this protocol)" fillcolor="#fff3e0"];
arch [label="Architecture?\n-> system-design\n-> Architecture References\n(this protocol)" fillcolor="#fff3e0"];
quality [label="Code Quality?\n-> quality-enforcement\n-> Quality References\n(this protocol)" fillcolor="#fff3e0"];
perf [label="Performance?\n-> performance-tuning\n-> Perf References\n(this protocol)" fillcolor="#fff3e0"];
security [label="Security?\n-> security-protocol\n-> Security References\n(this protocol)" fillcolor="#fff3e0"];
other [label="Other Domain?\n-> Research + Build Reference\n(this protocol)" fillcolor="#fce4ec"];
task -> classify;
classify -> ui;
classify -> website;
classify -> code;
classify -> api;
classify -> database;
classify -> testing;
classify -> devops;
classify -> arch;
classify -> quality;
classify -> perf;
classify -> security;
classify -> other;
}
Green nodes = dedicated protocol exists, invoke it.
Orange nodes = use reference libraries from THIS protocol.
Red nodes = no reference exists yet — research first, then build.
The Entry Protocol
BEFORE building anything:
1. CLASSIFY: What domain is this task in?
2. ROUTE: Does a dedicated reference protocol exist? (ux-patterns, design-research, github-search, codebase-research, etc.)
-> YES: Invoke that protocol
-> NO: Continue to step 3
3. SEARCH: Locate reference implementations for this domain
- External: Use github-search for open-source repos, libraries, and patterns
- Internal: Use codebase-research for existing conventions and similar code
- GitHub: Search for gold-standard implementations
- Documentation: Find official best practices (RFC specs, framework docs, cloud provider guides)
- Industry leaders: What do Stripe, GitHub, Vercel, AWS do for this?
4. EXTRACT: Isolate the patterns that make these references excellent
5. PRESENT: Show the user your references and recommended approach
6. BUILD: Implement using the reference
Skip any step = building from assumptions instead of knowledge
The Reference Philosophy
"Accumulated Expertise" Principle:
Every professional implementation represents:
- Months of design iteration
- Thousands of users providing feedback
- Production incidents that drove improvements
- Security audits that uncovered vulnerabilities
- Performance tuning under real load
When you generate from scratch, you inherit NONE of this.
When you use a reference, you inherit ALL of it.
Domain Reference Libraries
API Design References
Gold-standard implementations to study:
| API Style |
Reference |
Study For |
| REST |
Stripe API |
Resource naming, versioning, error format, pagination, idempotency |
| REST |
GitHub API v3 |
Hypermedia, conditional requests, rate limiting headers |
| REST |
Twilio API |
Nested resources, webhooks, status callbacks |
| GraphQL |
GitHub API v4 |
Schema design, pagination (connections), error handling |
| GraphQL |
Shopify Storefront |
Query complexity limits, versioning strategy |
| RPC/gRPC |
Google Cloud APIs |
Proto design, error model, long-running operations |
| Webhooks |
Stripe Webhooks |
Event types, signing, retry policy, idempotency |
| Real-time |
Discord Gateway |
WebSocket lifecycle, heartbeats, reconnection, intents |
API Reference Checklist:
BEFORE designing any API:
1. Resource naming: Use nouns, plural, lowercase
Reference: Stripe -> /v1/customers, /v1/payment_intents
2. Error format: Consistent error object
Reference: Stripe -> { error: { type, code, message, param } }
3. Pagination: Cursor-based for real-time data, offset for static
Reference: GitHub -> Link headers + per_page + page params
Reference: Stripe -> has_more + starting_after cursor
4. Versioning: URL path or header
Reference: Stripe -> /v1/ prefix
Reference: GitHub -> Accept header with version
5. Auth: API keys for server, OAuth for users
Reference: Stripe -> Bearer token in Authorization header
6. Rate limiting: Return limits in headers
Reference: GitHub -> X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset
7. Idempotency: Idempotency keys for mutations
Reference: Stripe -> Idempotency-Key header
8. Filtering/sorting: Consistent query parameter patterns
Reference: Stripe -> created[gte]=timestamp, status=active
Database Schema References
Reference patterns by domain:
| Domain |
Schema Pattern |
Source |
| Users & Auth |
Users -> Roles -> Permissions (RBAC) |
Auth0, Supabase auth schema |
| E-commerce |
Products -> Variants -> Orders -> LineItems |
Shopify schema, Medusa.js |
| Multi-tenant SaaS |
Organizations -> Members -> Resources |
Clerk, WorkOS patterns |
| CMS |
Content -> Versions -> Media -> Taxonomies |
Strapi, Payload CMS schema |
| Social |
Users -> Posts -> Comments -> Reactions -> Follows |
Mastodon, Lemmy schema |
| Messaging |
Conversations -> Participants -> Messages |
Matrix protocol, Slack data model |
| Scheduling |
Events -> Slots -> Bookings -> Availability |
Cal.com schema |
| Analytics |
Events -> Sessions -> Properties (star schema) |
PostHog, Plausible schema |
| Inventory |
Products -> Warehouses -> Stock -> Movements |
Odoo inventory module |
Schema Reference Checklist:
BEFORE designing any database schema:
1. Find the domain pattern above (or search GitHub for "[domain] database schema")
2. Study the reference implementation's:
- Table relationships and foreign keys
- Indexing strategy
- Soft delete approach (deleted_at vs status)
- Audit trail pattern (created_at, updated_at, created_by)
- Multi-tenancy approach (row-level vs schema-level)
3. Standard columns for EVERY table:
- id (UUID or ULID, not auto-increment for distributed systems)
- created_at (timestamp with timezone)
- updated_at (timestamp with timezone)
4. Naming convention: snake_case for tables and columns
5. Junction tables: {table_a}_{table_b} alphabetically
Testing Strategy References
Reference frameworks by project type:
| Project Type |
Testing Approach |
Tools |
| React/Vue/Svelte |
Component -> Integration -> E2E |
Testing Library + Vitest + Playwright |
| API/Backend |
Unit -> Integration -> Contract -> E2E |
Jest/Vitest + Supertest + Pact |
| CLI Tool |
Unit -> Integration -> Snapshot |
Jest + mock-stdin + snapshot testing |
| Library/Package |
Unit -> Property-based -> Compatibility |
Vitest + fast-check + matrix CI |
| Mobile |
Component -> Screen -> E2E |
Detox (RN), XCTest (iOS), Espresso (Android) |
| Data Pipeline |
Unit -> Integration -> Data quality |
Great Expectations, dbt tests |
| Infrastructure |
Plan -> Apply -> Verify |
Terratest, kitchen-terraform |
Testing Reference Checklist:
BEFORE writing tests:
1. Identify project type -> select testing approach above
2. Test pyramid for this project:
- Unit tests: 70% (fast, isolated, mock dependencies)
- Integration tests: 20% (real dependencies, test interactions)
- E2E tests: 10% (user flows, critical paths only)
3. What to test:
- Happy path (minimum viable test)
- Edge cases from spec (empty, null, max, concurrent)
- Error paths (invalid input, network failure, timeout)
- Security paths (injection, auth bypass, privilege escalation)
4. What NOT to test:
- Framework internals (React renders correctly)
- Third-party library behavior (axios sends requests)
- Implementation details (internal state shape)
5. Test naming: describe("[unit]", () => it("should [behavior] when [condition]"))
6. Test data: Use factories/fixtures, not inline magic values
CI/CD Pipeline References
Reference pipelines by platform:
| Platform |
Source |
Key Patterns |
| GitHub Actions |
github/starter-workflows |
Matrix builds, caching, artifact upload |
| GitHub Actions |
Vercel's Next.js workflow |
Preview deploys, environment protection |
| GitLab CI |
gitlab-org/gitlab |
Multi-stage, DAG pipelines, includes |
| CircleCI |
circleci/circleci-docs |
Orbs, workspace persistence |
| AWS |
aws-actions/* |
OIDC auth, CodeBuild, ECS deploy |
| GCP |
google-github-actions/* |
Workload Identity, Cloud Run deploy |
CI/CD Reference Checklist:
BEFORE setting up CI/CD:
1. Standard pipeline stages:
Install -> Lint -> Type Check -> Test -> Build -> Deploy
2. Caching strategy:
- Node: cache node_modules with package-lock.json hash
- Python: cache .venv with requirements.txt hash
- Go: cache go/pkg/mod with go.sum hash
- Rust: cache target/ with Cargo.lock hash
3. Required checks before merge:
- All tests pass
- Linting passes
- Type checking passes
- Build succeeds
- Security audit passes (npm audit, pip audit)
4. Deployment strategy:
- Preview deploys for PRs (Vercel, Netlify, or custom)
- Staging auto-deploy from main
- Production manual approval or tag-based
5. Secrets management:
- Use platform secret stores (GitHub Secrets, Vault)
- Never echo secrets in logs
- Rotate on compromise
Code Pattern References
Reference implementations by language/framework:
| Pattern |
Source |
When to Use |
| Error handling (TS) |
Effect-TS, neverthrow |
Typed errors, Result pattern |
| Error handling (Go) |
Standard library |
errors.Is/As, wrapping, sentinel errors |
| Error handling (Rust) |
thiserror + anyhow |
Custom error types + context |
| State machines |
XState, Robot |
Complex UI state, workflows |
| Event sourcing |
EventStoreDB examples |
Audit trails, temporal queries |
| CQRS |
Axon Framework examples |
Read/write separation at scale |
| Repository pattern |
Spring Data, TypeORM |
Data access abstraction |
| Middleware pattern |
Express, Koa, Hono |
Request pipeline, cross-cutting concerns |
| Plugin system |
Vite, ESLint, Webpack |
Extensibility, hooks |
| Queue/worker |
BullMQ, Celery |
Background jobs, async processing |
| Pub/sub |
Redis Streams, NATS |
Event-driven communication |
| Rate limiting |
Upstash ratelimit |
API protection, fair usage |
| Feature flags |
Unleash, LaunchDarkly SDK |
Progressive rollout, A/B testing |
| Caching |
Redis patterns, SWR |
Performance, stale-while-revalidate |
Code Pattern Reference Checklist:
BEFORE implementing a pattern:
1. Identify the pattern needed from the table above
2. Search GitHub for the reference implementation
3. Study HOW it implements the pattern:
- What's the public API? (how do consumers use it?)
- What's the internal structure? (how is it organized?)
- How does it handle errors?
- How does it handle edge cases?
4. Extract the minimal pattern for your use case
5. Implement following the reference structure
Architecture References
Reference architectures by scale:
| Scale |
Architecture |
Source |
| Solo/MVP |
Monolith + managed DB |
Rails, Django, Next.js full-stack |
| Small team |
Modular monolith |
Shopify's approach (components), Laravel modules |
| Growing |
Monolith -> extract services |
Segment's centrifuge pattern |
| Scale |
Microservices + event bus |
Netflix OSS, Uber's domain-oriented |
| Serverless |
Functions + managed services |
SST (sst.dev) patterns, Vercel's architecture |
| Edge |
Edge compute + CDN |
Cloudflare Workers patterns, Deno Deploy |
Security References
Reference implementations by concern:
| Concern |
Source |
Key Patterns |
| Authentication |
Auth.js (NextAuth) |
Session strategy, provider pattern, CSRF protection |
| Authorization |
CASL, Casbin |
ABAC/RBAC policies, permission checking |
| Input validation |
Zod, Valibot |
Schema validation at boundaries |
| Rate limiting |
Upstash ratelimit |
Sliding window, token bucket |
| CORS |
Express CORS middleware |
Allowlist origins, credentials handling |
| CSP |
Helmet.js |
Content-Security-Policy headers |
| Secrets |
1Password CLI, Vault |
Secret rotation, zero-trust access |
| Encryption |
libsodium, Web Crypto |
Envelope encryption, key derivation |
DevOps / Infrastructure References
Reference patterns by provider:
| Provider |
Source |
Covers |
| AWS |
aws-samples/* |
VPC, ECS, Lambda, RDS, S3 patterns |
| GCP |
GoogleCloudPlatform/* |
Cloud Run, GKE, Pub/Sub, Firestore |
| Azure |
Azure-Samples/* |
App Service, Functions, Cosmos DB |
| Kubernetes |
kubernetes/examples |
Deployments, services, ingress, HPA |
| Terraform |
hashicorp/terraform-provider-* |
Module patterns, state management |
| Docker |
docker/awesome-compose |
Multi-service compose patterns |
| Monitoring |
grafana/grafana |
Dashboard templates, alert rules |
Documentation References
| Doc Type |
Source |
Study For |
| API docs |
Stripe docs |
Clear examples, language tabs, copy-paste ready |
| README |
Best-of-breed GitHub READMEs |
Badges, quick start, feature list, contributing |
| Architecture |
arc42, C4 model |
Decision records, context diagrams |
| Runbooks |
PagerDuty runbooks |
Incident response, escalation |
| Changelogs |
Keep a Changelog |
Versioning, categorization |
The Research Process
When no specific reference library above covers your domain:
1. GitHub Search:
- "[domain] [language] example" (e.g., "payment processing typescript example")
- "[domain] boilerplate" or "[domain] starter"
- Sort by stars, filter to recently updated
2. Official Documentation:
- Framework guides (Next.js docs, Django docs, Rails guides)
- Cloud provider best practices (AWS Well-Architected, GCP Architecture Center)
- RFC specifications (for protocols, standards)
3. Industry Leaders:
- What does Stripe do for payments?
- What does GitHub do for API design?
- What does Vercel do for deployment?
- What does Cloudflare do for edge computing?
4. Open Source Implementations:
- Search for mature, well-maintained projects in the same domain
- Examine how they structure their code
- Cherry-pick patterns from 3+ implementations
Multi-Reference Cherry-Picking
The best results come from combining references from multiple sources:
Example: Building a SaaS billing system
Reference 1 (Stripe API patterns):
-> Take: Resource naming, error format, idempotency
-> Take: Webhook event structure and signing
Reference 2 (Lago open-source billing):
-> Take: Usage-based metering data model
-> Take: Invoice generation pipeline
Reference 3 (Supabase auth schema):
-> Take: Multi-tenant organization structure
-> Take: Row-level security patterns
Reference 4 (Cal.com):
-> Take: Subscription lifecycle state machine
-> Take: Webhook delivery with retry logic
Result: A billing system built on patterns from 4 production-tested systems,
each designed by teams who spent months on exactly these problems.
Reference Quality Criteria
Not all references are equal. Evaluate by:
| Criterion |
Weight |
What to Check |
| Production usage |
High |
Is this deployed in production by real organizations? |
| Community size |
High |
Stars, contributors, download counts |
| Maintenance |
High |
Recent commits, responsive issue handling |
| Documentation |
Medium |
Are patterns documented and explained? |
| Test coverage |
Medium |
Does the reference have strong tests? |
| Security audited |
Medium |
Has it passed security review? |
| Simplicity |
Medium |
Is the pattern minimal and clear? |
| Portability |
Low |
Can the pattern be adapted to other stacks? |
Cognitive Traps
| Rationalization |
Truth |
| "I know how to build this" |
You know how to build A version. References give you the BEST version. |
| "This is too simple for a reference" |
Simple things done wrong compound. A bad schema pattern affects every query forever. |
| "I'll consult references later" |
Research FIRST. Structural decisions made early are hardest to reverse. |
| "The user didn't request research" |
They requested quality. References ARE how you deliver quality. |
| "There's no reference for this" |
There is always a reference. Adjacent domains, similar patterns, analogous systems. |
| "References slow me down" |
Building the wrong thing slows you down MORE. |
| "I can improve on the reference" |
Prove it. Show the reference first, then propose improvements. |
| "AI can generate strong patterns" |
AI generates plausible patterns. Plausible does not mean production-tested. |
Guardrails
Prohibited:
- Generating API designs without studying Stripe/GitHub/Twilio patterns
- Creating database schemas without locating domain-specific references
- Setting up CI/CD without examining starter workflows
- Implementing security without studying auth library patterns
- Writing tests without a testing strategy reference
- Choosing architecture without studying reference architectures
Mandatory:
- Locate at least 2 reference implementations before building
- Cherry-pick from 3+ sources for complex systems
- Present your references and approach to the user
- Explain WHY you chose specific patterns from specific references
- Update references when you discover superior ones
Integration
This protocol is the ROUTER. It invokes other protocols:
- godmode:ux-patterns — UI/UX references
- godmode:design-research — Website design references
- godmode:github-search — External code and library research (GitHub, package registries, open-source ecosystems)
- godmode:codebase-research — Internal codebase pattern matching (conventions, similar files, existing implementations)
- godmode:system-design — Architecture decision references
- godmode:quality-enforcement — Quality standard references
- godmode:security-protocol — Security pattern references
- godmode:performance-tuning — Performance references
- godmode:project-bootstrap — Project structure references
Invoked by:
- godmode:intent-discovery — During the "what exists?" phase
- godmode:specification-first — To inform specs with proven patterns
- godmode:task-planning — To ground plans in reality
The hierarchy:
reference-engine (this protocol - the universal router)
+-- ux-patterns (UI/UX domain)
+-- design-research (website design domain)
+-- github-search (external code research domain)
+-- codebase-research (internal code pattern domain)
+-- system-design (structural design domain)
+-- quality-enforcement (quality domain)
+-- security-protocol (security domain)
+-- performance-tuning (performance domain)
+-- project-bootstrap (structure domain)
+-- [this protocol's built-in libraries] (API, DB, testing, CI/CD, DevOps, docs)
1---2name: reference-engine3description: Use when building ANYTHING - the universal reference-first system that routes every task to proven reference implementations instead of generating from assumptions. Covers API design, database schemas, testing strategies, CI/CD pipelines, code patterns, DevOps, and any other domain where professional reference implementations exist4---56<EXTREMELY-IMPORTANT>7This is the meta-protocol that governs ALL reference-first behavior. If you are building something and no domain-specific reference protocol exists, this protocol IS your reference system.89YOU MUST LOCATE A REFERENCE BEFORE YOU BUILD. NO EXCEPTIONS.10</EXTREMELY-IMPORTANT>1112# Reference Engine: The Universal Reference-First System1314## Overview1516Every domain has thousands of hours of professional engineering already completed. APIs have been designed, schemas have been refined, pipelines have been battle-tested, patterns have been hardened. Leveraging them as your reference is not laziness — it is engineering intelligence.1718**Core principle:** Before building ANYTHING, locate the best existing reference. Extract its patterns. Build on proven foundations, not assumptions.1920**No exceptions. No workarounds. No shortcuts.**2122## The Prime Directive2324```25NO BUILDING WITHOUT A REFERENCE26```2728If you have not searched for proven references in the domain you are working in, you are disregarding thousands of hours of professional engineering. A payment API should resemble Stripe's API patterns, not a generic AI-generated endpoint.2930## When to Use3132**Always.** This protocol is the router. It determines WHICH reference system to engage based on what is being built.3334```dot35digraph reference_router {36 rankdir=TB;37 node [shape=box style=filled];3839 task [label="Task Received" fillcolor=lightyellow shape=doublecircle];4041 classify [label="Classify Task Domain" fillcolor=lightyellow];4243 ui [label="UI / Frontend?\n-> ux-patterns\n-> ui-engineering\n-> design-integration" fillcolor="#e8f5e9"];44 website [label="Website Design?\n-> design-research\n-> ux-patterns" fillcolor="#e8f5e9"];45 code [label="Code / Library?\n-> github-search (external)\n-> codebase-research (internal)\n-> pattern-matching" fillcolor="#e8f5e9"];46 api [label="API Design?\n-> API References\n(this protocol)" fillcolor="#fff3e0"];47 database [label="Database / Schema?\n-> Schema References\n(this protocol)" fillcolor="#fff3e0"];48 testing [label="Testing Strategy?\n-> Testing References\n(this protocol)" fillcolor="#fff3e0"];49 devops [label="CI/CD / DevOps?\n-> DevOps References\n(this protocol)" fillcolor="#fff3e0"];50 arch [label="Architecture?\n-> system-design\n-> Architecture References\n(this protocol)" fillcolor="#fff3e0"];51 quality [label="Code Quality?\n-> quality-enforcement\n-> Quality References\n(this protocol)" fillcolor="#fff3e0"];52 perf [label="Performance?\n-> performance-tuning\n-> Perf References\n(this protocol)" fillcolor="#fff3e0"];53 security [label="Security?\n-> security-protocol\n-> Security References\n(this protocol)" fillcolor="#fff3e0"];54 other [label="Other Domain?\n-> Research + Build Reference\n(this protocol)" fillcolor="#fce4ec"];5556 task -> classify;57 classify -> ui;58 classify -> website;59 classify -> code;60 classify -> api;61 classify -> database;62 classify -> testing;63 classify -> devops;64 classify -> arch;65 classify -> quality;66 classify -> perf;67 classify -> security;68 classify -> other;69}70```7172**Green nodes** = dedicated protocol exists, invoke it.73**Orange nodes** = use reference libraries from THIS protocol.74**Red nodes** = no reference exists yet — research first, then build.7576## The Entry Protocol7778```79BEFORE building anything:80811. CLASSIFY: What domain is this task in?822. ROUTE: Does a dedicated reference protocol exist? (ux-patterns, design-research, github-search, codebase-research, etc.)83 -> YES: Invoke that protocol84 -> NO: Continue to step 3853. SEARCH: Locate reference implementations for this domain86 - External: Use github-search for open-source repos, libraries, and patterns87 - Internal: Use codebase-research for existing conventions and similar code88 - GitHub: Search for gold-standard implementations89 - Documentation: Find official best practices (RFC specs, framework docs, cloud provider guides)90 - Industry leaders: What do Stripe, GitHub, Vercel, AWS do for this?914. EXTRACT: Isolate the patterns that make these references excellent925. PRESENT: Show the user your references and recommended approach936. BUILD: Implement using the reference9495Skip any step = building from assumptions instead of knowledge96```9798## The Reference Philosophy99100```101"Accumulated Expertise" Principle:102103Every professional implementation represents:104- Months of design iteration105- Thousands of users providing feedback106- Production incidents that drove improvements107- Security audits that uncovered vulnerabilities108- Performance tuning under real load109110When you generate from scratch, you inherit NONE of this.111When you use a reference, you inherit ALL of it.112```113114## Domain Reference Libraries115116### API Design References117118**Gold-standard implementations to study:**119120| API Style | Reference | Study For |121|-----------|-----------|-----------|122| REST | Stripe API | Resource naming, versioning, error format, pagination, idempotency |123| REST | GitHub API v3 | Hypermedia, conditional requests, rate limiting headers |124| REST | Twilio API | Nested resources, webhooks, status callbacks |125| GraphQL | GitHub API v4 | Schema design, pagination (connections), error handling |126| GraphQL | Shopify Storefront | Query complexity limits, versioning strategy |127| RPC/gRPC | Google Cloud APIs | Proto design, error model, long-running operations |128| Webhooks | Stripe Webhooks | Event types, signing, retry policy, idempotency |129| Real-time | Discord Gateway | WebSocket lifecycle, heartbeats, reconnection, intents |130131**API Reference Checklist:**132133```134BEFORE designing any API:1351361. Resource naming: Use nouns, plural, lowercase137 Reference: Stripe -> /v1/customers, /v1/payment_intents1381392. Error format: Consistent error object140 Reference: Stripe -> { error: { type, code, message, param } }1411423. Pagination: Cursor-based for real-time data, offset for static143 Reference: GitHub -> Link headers + per_page + page params144 Reference: Stripe -> has_more + starting_after cursor1451464. Versioning: URL path or header147 Reference: Stripe -> /v1/ prefix148 Reference: GitHub -> Accept header with version1491505. Auth: API keys for server, OAuth for users151 Reference: Stripe -> Bearer token in Authorization header1521536. Rate limiting: Return limits in headers154 Reference: GitHub -> X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset1551567. Idempotency: Idempotency keys for mutations157 Reference: Stripe -> Idempotency-Key header1581598. Filtering/sorting: Consistent query parameter patterns160 Reference: Stripe -> created[gte]=timestamp, status=active161```162163### Database Schema References164165**Reference patterns by domain:**166167| Domain | Schema Pattern | Source |168|--------|---------------|--------|169| Users & Auth | Users -> Roles -> Permissions (RBAC) | Auth0, Supabase auth schema |170| E-commerce | Products -> Variants -> Orders -> LineItems | Shopify schema, Medusa.js |171| Multi-tenant SaaS | Organizations -> Members -> Resources | Clerk, WorkOS patterns |172| CMS | Content -> Versions -> Media -> Taxonomies | Strapi, Payload CMS schema |173| Social | Users -> Posts -> Comments -> Reactions -> Follows | Mastodon, Lemmy schema |174| Messaging | Conversations -> Participants -> Messages | Matrix protocol, Slack data model |175| Scheduling | Events -> Slots -> Bookings -> Availability | Cal.com schema |176| Analytics | Events -> Sessions -> Properties (star schema) | PostHog, Plausible schema |177| Inventory | Products -> Warehouses -> Stock -> Movements | Odoo inventory module |178179**Schema Reference Checklist:**180181```182BEFORE designing any database schema:1831841. Find the domain pattern above (or search GitHub for "[domain] database schema")1852. Study the reference implementation's:186 - Table relationships and foreign keys187 - Indexing strategy188 - Soft delete approach (deleted_at vs status)189 - Audit trail pattern (created_at, updated_at, created_by)190 - Multi-tenancy approach (row-level vs schema-level)1913. Standard columns for EVERY table:192 - id (UUID or ULID, not auto-increment for distributed systems)193 - created_at (timestamp with timezone)194 - updated_at (timestamp with timezone)1954. Naming convention: snake_case for tables and columns1965. Junction tables: {table_a}_{table_b} alphabetically197```198199### Testing Strategy References200201**Reference frameworks by project type:**202203| Project Type | Testing Approach | Tools |204|-------------|------------------|-------|205| React/Vue/Svelte | Component -> Integration -> E2E | Testing Library + Vitest + Playwright |206| API/Backend | Unit -> Integration -> Contract -> E2E | Jest/Vitest + Supertest + Pact |207| CLI Tool | Unit -> Integration -> Snapshot | Jest + mock-stdin + snapshot testing |208| Library/Package | Unit -> Property-based -> Compatibility | Vitest + fast-check + matrix CI |209| Mobile | Component -> Screen -> E2E | Detox (RN), XCTest (iOS), Espresso (Android) |210| Data Pipeline | Unit -> Integration -> Data quality | Great Expectations, dbt tests |211| Infrastructure | Plan -> Apply -> Verify | Terratest, kitchen-terraform |212213**Testing Reference Checklist:**214215```216BEFORE writing tests:2172181. Identify project type -> select testing approach above2192. Test pyramid for this project:220 - Unit tests: 70% (fast, isolated, mock dependencies)221 - Integration tests: 20% (real dependencies, test interactions)222 - E2E tests: 10% (user flows, critical paths only)2233. What to test:224 - Happy path (minimum viable test)225 - Edge cases from spec (empty, null, max, concurrent)226 - Error paths (invalid input, network failure, timeout)227 - Security paths (injection, auth bypass, privilege escalation)2284. What NOT to test:229 - Framework internals (React renders correctly)230 - Third-party library behavior (axios sends requests)231 - Implementation details (internal state shape)2325. Test naming: describe("[unit]", () => it("should [behavior] when [condition]"))2336. Test data: Use factories/fixtures, not inline magic values234```235236### CI/CD Pipeline References237238**Reference pipelines by platform:**239240| Platform | Source | Key Patterns |241|----------|--------|--------------|242| GitHub Actions | github/starter-workflows | Matrix builds, caching, artifact upload |243| GitHub Actions | Vercel's Next.js workflow | Preview deploys, environment protection |244| GitLab CI | gitlab-org/gitlab | Multi-stage, DAG pipelines, includes |245| CircleCI | circleci/circleci-docs | Orbs, workspace persistence |246| AWS | aws-actions/* | OIDC auth, CodeBuild, ECS deploy |247| GCP | google-github-actions/* | Workload Identity, Cloud Run deploy |248249**CI/CD Reference Checklist:**250251```252BEFORE setting up CI/CD:2532541. Standard pipeline stages:255 Install -> Lint -> Type Check -> Test -> Build -> Deploy2562572. Caching strategy:258 - Node: cache node_modules with package-lock.json hash259 - Python: cache .venv with requirements.txt hash260 - Go: cache go/pkg/mod with go.sum hash261 - Rust: cache target/ with Cargo.lock hash2622633. Required checks before merge:264 - All tests pass265 - Linting passes266 - Type checking passes267 - Build succeeds268 - Security audit passes (npm audit, pip audit)2692704. Deployment strategy:271 - Preview deploys for PRs (Vercel, Netlify, or custom)272 - Staging auto-deploy from main273 - Production manual approval or tag-based2742755. Secrets management:276 - Use platform secret stores (GitHub Secrets, Vault)277 - Never echo secrets in logs278 - Rotate on compromise279```280281### Code Pattern References282283**Reference implementations by language/framework:**284285| Pattern | Source | When to Use |286|---------|--------|-------------|287| Error handling (TS) | Effect-TS, neverthrow | Typed errors, Result pattern |288| Error handling (Go) | Standard library | errors.Is/As, wrapping, sentinel errors |289| Error handling (Rust) | thiserror + anyhow | Custom error types + context |290| State machines | XState, Robot | Complex UI state, workflows |291| Event sourcing | EventStoreDB examples | Audit trails, temporal queries |292| CQRS | Axon Framework examples | Read/write separation at scale |293| Repository pattern | Spring Data, TypeORM | Data access abstraction |294| Middleware pattern | Express, Koa, Hono | Request pipeline, cross-cutting concerns |295| Plugin system | Vite, ESLint, Webpack | Extensibility, hooks |296| Queue/worker | BullMQ, Celery | Background jobs, async processing |297| Pub/sub | Redis Streams, NATS | Event-driven communication |298| Rate limiting | Upstash ratelimit | API protection, fair usage |299| Feature flags | Unleash, LaunchDarkly SDK | Progressive rollout, A/B testing |300| Caching | Redis patterns, SWR | Performance, stale-while-revalidate |301302**Code Pattern Reference Checklist:**303304```305BEFORE implementing a pattern:3063071. Identify the pattern needed from the table above3082. Search GitHub for the reference implementation3093. Study HOW it implements the pattern:310 - What's the public API? (how do consumers use it?)311 - What's the internal structure? (how is it organized?)312 - How does it handle errors?313 - How does it handle edge cases?3144. Extract the minimal pattern for your use case3155. Implement following the reference structure316```317318### Architecture References319320**Reference architectures by scale:**321322| Scale | Architecture | Source |323|-------|-------------|--------|324| Solo/MVP | Monolith + managed DB | Rails, Django, Next.js full-stack |325| Small team | Modular monolith | Shopify's approach (components), Laravel modules |326| Growing | Monolith -> extract services | Segment's centrifuge pattern |327| Scale | Microservices + event bus | Netflix OSS, Uber's domain-oriented |328| Serverless | Functions + managed services | SST (sst.dev) patterns, Vercel's architecture |329| Edge | Edge compute + CDN | Cloudflare Workers patterns, Deno Deploy |330331### Security References332333**Reference implementations by concern:**334335| Concern | Source | Key Patterns |336|---------|--------|--------------|337| Authentication | Auth.js (NextAuth) | Session strategy, provider pattern, CSRF protection |338| Authorization | CASL, Casbin | ABAC/RBAC policies, permission checking |339| Input validation | Zod, Valibot | Schema validation at boundaries |340| Rate limiting | Upstash ratelimit | Sliding window, token bucket |341| CORS | Express CORS middleware | Allowlist origins, credentials handling |342| CSP | Helmet.js | Content-Security-Policy headers |343| Secrets | 1Password CLI, Vault | Secret rotation, zero-trust access |344| Encryption | libsodium, Web Crypto | Envelope encryption, key derivation |345346### DevOps / Infrastructure References347348**Reference patterns by provider:**349350| Provider | Source | Covers |351|----------|--------|--------|352| AWS | aws-samples/* | VPC, ECS, Lambda, RDS, S3 patterns |353| GCP | GoogleCloudPlatform/* | Cloud Run, GKE, Pub/Sub, Firestore |354| Azure | Azure-Samples/* | App Service, Functions, Cosmos DB |355| Kubernetes | kubernetes/examples | Deployments, services, ingress, HPA |356| Terraform | hashicorp/terraform-provider-* | Module patterns, state management |357| Docker | docker/awesome-compose | Multi-service compose patterns |358| Monitoring | grafana/grafana | Dashboard templates, alert rules |359360### Documentation References361362| Doc Type | Source | Study For |363|----------|--------|-----------|364| API docs | Stripe docs | Clear examples, language tabs, copy-paste ready |365| README | Best-of-breed GitHub READMEs | Badges, quick start, feature list, contributing |366| Architecture | arc42, C4 model | Decision records, context diagrams |367| Runbooks | PagerDuty runbooks | Incident response, escalation |368| Changelogs | Keep a Changelog | Versioning, categorization |369370## The Research Process371372When no specific reference library above covers your domain:373374```3751. GitHub Search:376 - "[domain] [language] example" (e.g., "payment processing typescript example")377 - "[domain] boilerplate" or "[domain] starter"378 - Sort by stars, filter to recently updated3793802. Official Documentation:381 - Framework guides (Next.js docs, Django docs, Rails guides)382 - Cloud provider best practices (AWS Well-Architected, GCP Architecture Center)383 - RFC specifications (for protocols, standards)3843853. Industry Leaders:386 - What does Stripe do for payments?387 - What does GitHub do for API design?388 - What does Vercel do for deployment?389 - What does Cloudflare do for edge computing?3903914. Open Source Implementations:392 - Search for mature, well-maintained projects in the same domain393 - Examine how they structure their code394 - Cherry-pick patterns from 3+ implementations395```396397## Multi-Reference Cherry-Picking398399The best results come from combining references from multiple sources:400401```402Example: Building a SaaS billing system403404Reference 1 (Stripe API patterns):405 -> Take: Resource naming, error format, idempotency406 -> Take: Webhook event structure and signing407408Reference 2 (Lago open-source billing):409 -> Take: Usage-based metering data model410 -> Take: Invoice generation pipeline411412Reference 3 (Supabase auth schema):413 -> Take: Multi-tenant organization structure414 -> Take: Row-level security patterns415416Reference 4 (Cal.com):417 -> Take: Subscription lifecycle state machine418 -> Take: Webhook delivery with retry logic419420Result: A billing system built on patterns from 4 production-tested systems,421each designed by teams who spent months on exactly these problems.422```423424## Reference Quality Criteria425426Not all references are equal. Evaluate by:427428| Criterion | Weight | What to Check |429|-----------|--------|---------------|430| Production usage | High | Is this deployed in production by real organizations? |431| Community size | High | Stars, contributors, download counts |432| Maintenance | High | Recent commits, responsive issue handling |433| Documentation | Medium | Are patterns documented and explained? |434| Test coverage | Medium | Does the reference have strong tests? |435| Security audited | Medium | Has it passed security review? |436| Simplicity | Medium | Is the pattern minimal and clear? |437| Portability | Low | Can the pattern be adapted to other stacks? |438439## Cognitive Traps440441| Rationalization | Truth |442|-----------------|-------|443| "I know how to build this" | You know how to build A version. References give you the BEST version. |444| "This is too simple for a reference" | Simple things done wrong compound. A bad schema pattern affects every query forever. |445| "I'll consult references later" | Research FIRST. Structural decisions made early are hardest to reverse. |446| "The user didn't request research" | They requested quality. References ARE how you deliver quality. |447| "There's no reference for this" | There is always a reference. Adjacent domains, similar patterns, analogous systems. |448| "References slow me down" | Building the wrong thing slows you down MORE. |449| "I can improve on the reference" | Prove it. Show the reference first, then propose improvements. |450| "AI can generate strong patterns" | AI generates plausible patterns. Plausible does not mean production-tested. |451452## Guardrails453454**Prohibited:**455- Generating API designs without studying Stripe/GitHub/Twilio patterns456- Creating database schemas without locating domain-specific references457- Setting up CI/CD without examining starter workflows458- Implementing security without studying auth library patterns459- Writing tests without a testing strategy reference460- Choosing architecture without studying reference architectures461462**Mandatory:**463- Locate at least 2 reference implementations before building464- Cherry-pick from 3+ sources for complex systems465- Present your references and approach to the user466- Explain WHY you chose specific patterns from specific references467- Update references when you discover superior ones468469## Integration470471**This protocol is the ROUTER. It invokes other protocols:**472473- **godmode:ux-patterns** — UI/UX references474- **godmode:design-research** — Website design references475- **godmode:github-search** — External code and library research (GitHub, package registries, open-source ecosystems)476- **godmode:codebase-research** — Internal codebase pattern matching (conventions, similar files, existing implementations)477- **godmode:system-design** — Architecture decision references478- **godmode:quality-enforcement** — Quality standard references479- **godmode:security-protocol** — Security pattern references480- **godmode:performance-tuning** — Performance references481- **godmode:project-bootstrap** — Project structure references482483**Invoked by:**484- **godmode:intent-discovery** — During the "what exists?" phase485- **godmode:specification-first** — To inform specs with proven patterns486- **godmode:task-planning** — To ground plans in reality487488**The hierarchy:**489```490reference-engine (this protocol - the universal router)491+-- ux-patterns (UI/UX domain)492+-- design-research (website design domain)493+-- github-search (external code research domain)494+-- codebase-research (internal code pattern domain)495+-- system-design (structural design domain)496+-- quality-enforcement (quality domain)497+-- security-protocol (security domain)498+-- performance-tuning (performance domain)499+-- project-bootstrap (structure domain)500+-- [this protocol's built-in libraries] (API, DB, testing, CI/CD, DevOps, docs)501```