Note
Wesley is pre-alpha. It does work, but it's somewhere between MVP and alpha.
Just being real: probably don't want to use this in prod until at least beta.
Star the repo, watch for updates! It's under active development.
- flyingrobots
The data layer compiler that turns GraphQL schemas into production-ready PostgreSQLβwith zero-downtime migrations, comprehensive tests, and cryptographic deployment proofs.
Wesley inverts the entire database development paradigm. While everyone else generates GraphQL from databases, Wesley generates a battle-tested PostgreSQL backend from GraphQLβalong with TypeScript types, Zod schemas, Row-Level Security (RLS) policies, comprehensive tests, and SHA-locked deployment certificates. All from a single source of truth.
Stop maintaining schemas in 5 places. Start shipping with confidence.
type Document @wes_table @wes_tenant(by: "org_id") @wes_rls(enabled: true) {
id: ID! @wes_pk
title: String!
org_id: ID! @wes_fk(ref: "Org.id")
created_by: ID! @wes_fk(ref: "User.id")
}| Goal | Command(s) | Notes |
|---|---|---|
| Install tooling & sanity-check repo | pnpm installpnpm run bootstrap |
Bootstraps dependencies, runs preflight, executes workspace tests. |
| Generate everything from the example schema | node packages/wesley-host-node/bin/wesley.mjs generate --schema test/fixtures/examples/schema.graphql --ops test/fixtures/examples/ops --emit-bundle --out-dir out/examples |
Produces SQL, pgTAP, ops SQL, and a .wesley/ evidence bundle. |
| Preview migration plan & rehearsal | node packages/wesley-host-node/bin/wesley.mjs plan --schema test/fixtures/examples/schema.graphql --explainnode packages/wesley-host-node/bin/wesley.mjs rehearse --schema test/fixtures/examples/schema.graphql --dry-run --json |
No database required for --dry-run; inspect JSON for lock levels and REALM verdicts. |
| Run HOLMES evidence checks | pnpm --filter @wesley/holmes exec node packages/wesley-host-node/bin/wesley.mjs generate --schema test/fixtures/examples/schema.graphql --emit-bundle --out-dir out/examplespnpm --filter @wesley/holmes exec node packages/wesley-holmes/src/cli.mjs investigate --json holmes.json > holmes.md |
Generates scores + markdown report; see Evidence, HOLMES, and Observability. |
| Experience the Daywalker (BLADE) demo | node packages/wesley-host-node/bin/wesley.mjs blade --schema test/fixtures/blade/schema-v2.graphql --out-dir out/blade --dry-run |
Uses curated fixtures to demonstrate the zero-downtime flow end-to-end. |
| Dive into docs/tests/scripts | docs/README.md, scripts/README.md, test/README.md |
Each guide explains prerequisites, commands, and fixture usage. |
- TL;DR β Getting Started
- Why Wesley Exists
- Quick Start
- Key Features
- Advanced Features
- FAQ
- Evidence, HOLMES, and Observability
Modern development forces you to describe the same data shape across multiple domains:
- PostgreSQL DDL for your database schema
- GraphQL schema for your API contract
- TypeScript types for your frontend/backend
- Zod schemas for runtime validation
- RLS policies for granular security
When these five sources drift, production breaks. Reviews are harder. Deploys are scarier. You're constantly playing schema telephone with yourself.
GraphQL is the single source of truth. Everything else is generated and tested.
Migrations aren't manual tasksβthey're diffs you get for free when your schema evolves. Wesley realizes the promise of the schema-first approach: Schema is the source. Migrations are just artifacts.
When you run wesley generate, it outputs a complete, ready-to-deploy data layer:
β migrations/
ββ 001_expand.sql # Online DDL (CONCURRENTLY, NOT VALID)
ββ 001_backfill.sql # Idempotent data transformations
ββ 001_contract.sql # Cleanup phase
β types/generated.ts # TypeScript interfaces
β schemas/zod.ts # Runtime validation
β policies/rls.sql # Row-level security + helpers
β tests/ # pgTAP suites
ββ structure/ # Table, column, constraint tests
ββ rls/ # Policy enforcement tests
ββ plan/ # Migration plan validation
β certs/
ββ deploy-<sha>.json # Cryptographic deployment proofflowchart LR
subgraph YOU["You Write"]
GQL["π GraphQL Schema<br/><small>schema.graphql</small>"]
end
subgraph WES["Wesley Generates"]
IR["π§ Wesley IR"]
SQL["ποΈ Postgres DDL<br/><small>+ phased migrations</small>"]
TS["π TypeScript<br/><small>+ Zod</small>"]
RLS["π RLS Policies<br/><small>+ helpers</small>"]
TEST["β
pgTAP Suite<br/><small>structure/constraints/RLS/plan</small>"]
CERT["π SHA-Locked Cert<br/><small>proofs & hashes</small>"]
end
subgraph PLAN["Zero-Downtime Plan"]
EXP[Expand]
BKG[Backfill]
VAL[Validate]
SWT[Switch]
CTR[Contract]
end
subgraph PROD["You Deploy"]
DEP["π Production"]
end
GQL -->|"wesley generate"| IR
IR --> SQL
IR --> TS
IR --> RLS
IR --> TEST
IR --> CERT
SQL --> EXP --> BKG --> VAL --> SWT --> CTR -->|"wesley deploy"| DEP
classDef p1 fill:#e3f2fd,stroke:#1976d2,stroke-width:2px
classDef p2 fill:#fff3e0,stroke:#ff9800
classDef p3 fill:#e8f5e9,stroke:#388e3c,stroke-width:2px
class GQL p1
class SQL,TS,RLS,TEST,CERT p2
class DEP p3
git clone https://github.com/flyingrobots/wesley.git
cd wesley
pnpm install
# Explore the CLI via the workspace script
pnpm wesley --help
# Generate everything from your GraphQL schema
pnpm wesley generate --schema schema.graphql
# Deploy to production (with zero-downtime planning)
pnpm wesley deploy# Generate everything for the example schema
node packages/wesley-host-node/bin/wesley.mjs generate \
--schema test/fixtures/examples/schema.graphql \
--ops test/fixtures/examples/ops \
--emit-bundle \
--out-dir out/examples
# Preview migration plan (no database required)
node packages/wesley-host-node/bin/wesley.mjs plan \
--schema test/fixtures/examples/schema.graphql \
--explain
# Validate the entire repository
pnpm run bootstrap # install deps β preflight β test
Wesley is engineered for safety, speed, and confidence.
- Zero-downtime DDL: All operations automatically use
CONCURRENTLYandNOT VALIDpatterns. - Phased Migration Protocol: Implements the battle-tested Expand β Backfill β Validate β Switch β Contract strategy.
- Advisory Locks: Automated locking prevents concurrent migration disasters.
- Lock-Aware Planning: The DDL planner rewrites SQL operations to minimize lock impact.
- Drift Detection: Runtime validation catches schema mismatches before damage occurs.
- pgTAP Suites: Generates PostgreSQL-native tests for structure, constraints, RLS enforcement, and migration logic.
- Property-Based Testing: Uses
fast-checkto prove the DDL planner's correctness. - Round-Trip Validation: Guarantees schema preservation: GraphQL β SQL β GraphQL.
- Idempotence Checks: All generated operations are safe to retry.
- SHA-Locked Certificates: Provides an immutable, auditable record of the deployed state.
- Explain Mode: Shows the precise lock levels for every operation in the migration plan.
- HOLMES Scoring: An evidence-based confidence system that produces SCS/TCI/MRI metrics (Schema Coverage, Test Confidence, Migration Risk) for deployment readiness.
- Dead Column Detection: Tools to find and flag unused database columns for safe cleanup.
- EvidenceMap is the authoritative mapping between schema elements and generated artifacts. Generators record evidence under stable UIDs:
- Tables:
tbl:TableName - Columns:
col:TableName.columnName
- Tables:
- SQL comments like
COMMENT ON COLUMN β¦ IS 'uid: β¦'are human-readable hints. Tooling (SourceMap, scoring, HOLMES) reads from EvidenceMap, not from the comment strings. - To surface a SQL error in the original GraphQL SDL, load the evidence bundle (
.wesley/bundle.json) and callfindSourceForSql(evidenceMap, { file, line }). - Scores (SCS/TCI/MRI) are computed from EvidenceMap; ensure generators record artifacts to keep scores accurate.
Example: map a SQL error back to SDL
import fs from 'node:fs/promises';
import { EvidenceMap } from '@wesley/core';
// Temporary deep import until re-exported at package root
import { findSourceForSql } from '@wesley/core/src/application/SourceMap.mjs';
// Load the bundle written by `wesley generate --emit-bundle`
const raw = await fs.readFile('.wesley/bundle.json', 'utf8');
const bundle = JSON.parse(raw);
// Evidence payload may be nested; normalize it
const payload = bundle?.evidence?.evidence ? bundle.evidence : bundle;
const ev = EvidenceMap.fromJSON(payload);
// If a failure mentions out/schema.sql:123
const mapped = findSourceForSql(ev, { file: 'out/schema.sql', line: 123 });
if (mapped?.source) {
console.log(`SDL: ${mapped.source.file} lines ${mapped.source.lines} (uid ${mapped.uid})`);
}| Hand-written | ORMs | Wesley | |
|---|---|---|---|
| Source of truth | β Many files | β Code-first | β GraphQL schema |
| Zero-downtime | β Manual | β Table locks risk | β Planned by default |
| RLS generation | β Manual SQL | β Limited | β Automated + tests |
| Drift detection | β Ad-hoc | β Partial | β Enforced |
| Test coverage | β Rare | β App-only | β pgTAP suites |
| Proof of safety | β None | β None | β SHA-locked certs |
type User @wes_table @wes_rls(enabled: true) {
id: ID! @wes_pk
email: String! @wes_unique
}type User @wes_table @wes_rls(enabled: true) {
id: ID! @wes_pk
email: String! @wes_unique
posts: [Post!]! @wes_hasMany # New relationship
}
type Post @wes_table @wes_rls(enabled: true) {
id: ID! @wes_pk
title: String!
author_id: ID! @wes_fk(ref: "User.id")
published: Boolean! @wes_default(value: "false")
}wesley generate # Generates migrations, types, policies, tests
wesley plan # Shows lock-aware migration plan
wesley rehearse # Tests on shadow database
wesley certify # Creates SHA-locked proof
wesley deploy # Applies to production
Wesley ensures a safe, zero-downtime deployment by automatically creating:
- The new
poststable with the foreign key and RLS policies. - All required TypeScript types and Zod schemas.
- All pgTAP tests to validate the new structure and security.
Wesley includes an experimental Query Intermediate Representation pipeline that compiles GraphQL operations into deterministic, optimized SQL.
The QIR pipeline translates queries, mutations, and subscriptions, then emits optimized PostgreSQL and generates pgTAP tests for operation contracts. See the documentation for details.
wesley generate \
--schema schema.graphql \
--ops ./operations \
--emit-bundleSee docs/guides/qir-ops.md for details.
The HOLMES (Heuristic for Observable Logic, Metrics, and Evidence System) toolkit inspects Wesley's evidence bundles (.wesley/) to produce an objective, machine-readable score for deployment readiness.
# Investigate deployment readiness
holmes investigate --bundle .wesley/
# Verify against previous deployment
watson verify --current .wesley/ --baseline .wesley/previous/
# Predict migration impact
moriarty predict --bundle .wesley/This system allows you to define a minimum confidence score before a deploy can proceed.
The certificate is generates is SHA-locked to the commit it ran against.
See packages/wesley-holmes/README.md for the complete guide.
- Documentation Hub β Philosophy, architecture, and manifesto
- Quick Start Guide β Get running in 60 seconds
- Migration Strategies β Schema evolution patterns
- Query Operations (QIR) β Experimental operation pipeline
- The Paradigm Shift β Why GraphQL is your source of truth
- Architecture Overview β Hexagonal, event-driven design
- The Algorithm β How GraphQL becomes SQL
- Delivery Lifecycle β Transform β Plan β Rehearse β Ship
- HOLMES Integration β Evidence bundles and scoring
- Internals Deep Dive β How Wesley works under the hood
- Event Flow β Tracing events through the system
- Parser Design β GraphQL SDL to domain model
@wesley/cliβ Command-line interface@wesley/coreβ Pure domain logic (directive registry, IR, SQL emission)@wesley/host-nodeβ Node.js adapters and binary entrypoint@wesley/generator-jsβ JavaScript/TypeScript/Zod emitters@wesley/generator-supabaseβ Supabase-specific generators@wesley/holmesβ SHA-lock investigations and scoring@wesley/tasksβ Task orchestration primitives@wesley/slapsβ Lock-aware scheduling utilities
test/β Integration and E2E test suitesschemas/β Canonical GraphQL schemastest/fixtures/reference/β Comprehensive SDL for experiments and future tests
- Scripts Reference β Complete
pnpm runcommands guide scripts/β Maintenance and automation scripts- Roadmap β Current focus and upcoming milestones
- SAGENTS Codex β Protocol for human and AI contributors
- BLADE (Daywalker Deploys) β 5-minute demo of the full pipeline
Wesley is a monorepo managed with pnpm workspaces:
wesley/
βββ packages/ # Core packages
β βββ wesley-cli/ # Command-line interface
β βββ wesley-core/ # Pure domain logic
β βββ wesley-holmes/ # Evidence scoring
β βββ ...
βββ docs/ # Documentation
βββ test/ # Integration tests
β βββ fixtures/ # Canonical test inputs
βββ schemas/ # Reference schemas
βββ scripts/ # Automation tools
βββ .wesley/ # Build artifacts (gitignored)
βββ snapshot.json # IR snapshot for diffs
βββ realm.json # Rehearsal verdicts
βββ SHIPME.md # Deployment certificate
# Run tests for specific package
pnpm --filter @wesley/core test
pnpm --filter @wesley/cli test
# Full system validation
pnpm run bootstrap
# Watch mode during development
wesley watch --schema schema.graphqlCopy .env.example to .env:
# Logging
WESLEY_LOG_LEVEL=info # trace|debug|info|warn|error|silent
# Git integration
WESLEY_GIT_POLICY=emit # emit|strict|off
# Schema limits
WESLEY_MAX_SCHEMA_BYTES=5242880 # 5MB default
# Database connections
SUPABASE_DB_URL=postgresql://...
WESLEY_TEST_DSN=postgresql://...--dsnflag wins for all commands- With
--provider supabase, falls back toSUPABASE_DB_URL/SUPABASE_POSTGRES_URL - Otherwise, uses local default:
postgres://wesley:wesley_test@localhost:5432/wesley_test
- Node.js: 18.x, 20.x, 22.x (CI uses Node 20 LTS)
- Package manager: pnpm 9 (workspace pinned)
- CI runners: Ubuntu (macOS removed to control costs)
- Development: Works on macOS/Windows, but CI targets Ubuntu
Q: What if I need custom SQL?
Use @custom blocks. Wesley will test them and preserve them across generations.
Q: Can I bring an existing database?
Yesβintrospect to a starting GraphQL schema, then let Wesley own future diffs.
Q: What about breaking changes?
Detected and flagged. Wesley prefers backward-compatible plans; explicit approval required for breaking steps.
Q: How does Wesley compare to Prisma?
Prisma focuses on queries. Wesley compiles the entire data layer (DDL, migrations, RLS, tests, proofs).
Q: Can I use Wesley with [framework]?
Yes! Wesley generates standard SQL, TypeScript, and Zod schemas that work with any framework. Dedicated integrations for Next.js/Remix/SvelteKit are on the roadmap.
Wesley follows the SAGENTS Codex for contribution guidelines. Whether you're human or machine:
- Obey repository rules β Every rule was written for a reason
- Respect
.llmignoreβ It guards focus from noise - Log your work β Append to the Chronicles, never alter history
- Test thoroughly β Run
pnpm run bootstrapbefore submitting - Read
AGENTS.mdβ Guide for AI Agents
See the roadmap for current priorities and the Wesley Project Board for active work.
Wesley is just the beginning. The roadmap includes:
- Visual Schema Editor β Design schemas visually
- Multi-Database Support β MySQL, SQLite, and more
- Framework Integration β First-class Next.js, Remix, SvelteKit plugins
- Time-Travel Debugging β Replay schema evolution
- AI-Powered Optimization β Let AI suggest schema improvements
"Things are only impossible until they're not." β Jean-Luc Picard
Wesley is named after Wesley Crusher, the brilliant ensign who saw possibilities others couldn't. Like his namesake, Wesley (the tool) transcends conventional thinking to solve problems in ways that seem obvious only in hindsight.
The revolution is declaring GraphQL as the single source of truth.
The innovation is making that actually work.
The magic is making it boring.
Stop playing schema telephone.
Start shipping with confidence.
Make it so. π
- Website: https://flyingrobots.github.io/wesley/
- GitHub: https://github.com/flyingrobots/wesley
- Issues: https://github.com/flyingrobots/wesley/issues
- Project Board: https://github.com/users/flyingrobots/projects/5
MIT Β© J. Kirby Ross (flyingrobots