-
Notifications
You must be signed in to change notification settings - Fork 887
docs(docs): added prisma next overview #7568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aidankmcalister
wants to merge
4
commits into
main
Choose a base branch
from
docs/prisma-next-overview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4d618e7
docs(docs): added prisma next overview
aidankmcalister 3c97454
refactor(docs): merge prisma next pages into one
aidankmcalister 8983903
Merge remote-tracking branch 'origin/main' into docs/prisma-next-over…
aidankmcalister d1e219c
docs(docs): update mermaid diagram
aidankmcalister File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
apps/docs/content/docs/orm/temp-next/how-prisma-next-works.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| --- | ||
| title: How Prisma Next works | ||
| description: Walk through the full lifecycle from Schema to Verified Runtime Queries. | ||
| url: /orm/temp-next/how-prisma-next-works | ||
| metaTitle: "How Prisma Next works schema contract signing and runtime verification" | ||
| metaDescription: "Follow the lifecycle from Schema to Data Contract, Database Signing, immutable Plan creation, and verified runtime query execution." | ||
| --- | ||
|
|
||
| Prisma Next works as a Verification-First Workflow: | ||
|
|
||
| **Schema -> Data Contract -> Database Signing -> Verified Runtime Queries** | ||
|
|
||
| ## Lifecycle diagram | ||
|
|
||
| ```mermaid | ||
| flowchart LR | ||
| A(Schema<br/>authored model definition) | ||
| B(Data Contract<br/>emit contract.json + contract.d.ts + hashes) | ||
| C(Database Signing<br/>verify DB state and write Contract Marker) | ||
| D(Runtime Plan<br/>build immutable Plan from contract-aware query surface) | ||
| E(Runtime Verification<br/>compare contract and Plan hashes to marker) | ||
| F(Verified Runtime Queries<br/>execute only after verification succeeds) | ||
|
|
||
| A --> B --> C --> D --> E --> F | ||
| ``` | ||
|
|
||
| ## Step 1: Schema | ||
|
|
||
| You define the data model in Schema authoring sources. | ||
|
|
||
| This is the intent stage: what data exists, how it relates, and what capabilities are required. | ||
|
|
||
| ```prisma title="schema.prisma" | ||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| email String @unique | ||
| } | ||
| ``` | ||
|
|
||
| ## Step 2: Data Contract | ||
|
|
||
| Schema intent is emitted into Contract Artifacts: | ||
|
|
||
| - `contract.json` (machine-readable contract data) | ||
| - `contract.d.ts` (typed contract surface) | ||
|
|
||
| The Data Contract carries hash identities such as `storageHash` and `profileHash`, which are used for compatibility checks. | ||
|
|
||
| ```ts title="load-contract.ts" | ||
| import type { Contract } from './contract.d'; | ||
| import contractJson from './contract.json' with { type: 'json' }; | ||
| import { validateContract } from '@prisma-next/sql-contract/validate'; | ||
|
|
||
| const contract = validateContract<Contract>(contractJson); | ||
| const { storageHash, profileHash } = contract; | ||
| ``` | ||
|
|
||
| ## Step 3: Database Signing | ||
|
|
||
| The database is verified against the Data Contract and then signed by writing the Contract Marker. | ||
|
|
||
| The Contract Marker stores the signed contract identity (for example `storageHash` and `profileHash`) so later stages can prove compatibility quickly and deterministically. | ||
|
|
||
| ```sql title="contract-marker.sql" | ||
| -- Conceptual marker record after successful signing | ||
| storage_hash = 'sha256:2e7d...' | ||
| profile_hash = 'sha256:9af1...' | ||
| ``` | ||
|
|
||
| ## Step 4: Verified Runtime Queries | ||
|
|
||
| Application queries are built as immutable Plans from the contract-aware query surface. | ||
|
|
||
| Before execution, runtime verifies that plan and contract identity match the Contract Marker. | ||
|
|
||
| - If hashes match, query execution proceeds. | ||
| - If hashes do not match, runtime blocks execution and reports a contract mismatch. | ||
|
|
||
| This is what makes runtime queries verified, not assumed. | ||
|
|
||
| ```ts title="build-and-execute-plan.ts" | ||
| import { schema } from '@prisma-next/sql-relational-core/schema'; | ||
| import { sql } from '@prisma-next/sql-lane/sql'; | ||
|
|
||
| const tables = schema(contract).tables; | ||
|
|
||
| const plan = sql({ contract, adapter }) | ||
| .from(tables.user) | ||
| .select({ | ||
| id: tables.user.columns.id, | ||
| email: tables.user.columns.email, | ||
| }) | ||
| .build(); | ||
|
|
||
| for await (const row of runtime.execute(plan)) { | ||
| // executes only after Contract Marker verification passes | ||
| console.log(row.id, row.email); | ||
| } | ||
| ``` | ||
|
|
||
| ## Verification-first feedback loop | ||
|
|
||
| Prisma Next keeps verification in the loop continuously: | ||
|
|
||
| 1. Verify before signing database state. | ||
| 2. Verify again before runtime query execution. | ||
| 3. Fail early on mismatch instead of allowing drift to propagate. | ||
|
|
||
| As Schema evolves, the lifecycle repeats with a new Data Contract and a new signature state. |
71 changes: 71 additions & 0 deletions
71
apps/docs/content/docs/orm/temp-next/what-is-prisma-next.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| title: What is Prisma Next? | ||
| description: Define Prisma Next clearly and lock core terms for the rest of the docs. | ||
| url: /orm/temp-next/what-is-prisma-next | ||
| metaTitle: "What is Prisma Next contract-driven data access with verification" | ||
| metaDescription: "Learn what Prisma Next is and how Data Contracts, Contract Artifacts, and Verification-First Workflow enforce verified execution." | ||
| --- | ||
|
|
||
| Prisma Next is a **contract-driven data access layer with verification before execution**. It is designed for deterministic behavior, explicit safety checks, and machine-readable artifacts. | ||
|
|
||
| Prisma Next is **not Prisma ORM**. | ||
|
|
||
| Prisma ORM centers on generating and using an executable client. Prisma Next centers on emitting and using a **Data Contract** that every stage verifies before it acts. | ||
|
|
||
| In plain language: Prisma Next turns your Schema into a signed agreement between your application and your database. Queries run only when that agreement is verified. | ||
|
|
||
| ## Contract-driven architecture in plain language | ||
|
|
||
| In a contract-driven architecture: | ||
|
|
||
| - You define your data model as a Schema. | ||
| - That Schema is emitted as Contract Artifacts (`contract.json` + `contract.d.ts`). | ||
| - The database is signed to the contract by storing contract hashes in a Contract Marker. | ||
| - Runtime queries verify the contract against that marker before executing. | ||
|
|
||
| The Data Contract is the shared source of truth for tools, runtimes, migrations, and automated agents. | ||
|
|
||
| ## Example: contract artifact (conceptual) | ||
|
|
||
| ```json title="contract.json" | ||
| { | ||
| "schemaVersion": "1", | ||
| "targetFamily": "sql", | ||
| "storageHash": "sha256:2e7d...", | ||
| "profileHash": "sha256:9af1...", | ||
| "models": { | ||
| "User": { | ||
| "storage": { "table": "user" }, | ||
| "fields": { | ||
| "id": { "column": "id" }, | ||
| "email": { "column": "email" } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| This is the core idea: application and runtime reason over explicit contract data, not opaque generated runtime behavior. | ||
|
|
||
| ## What Prisma Next gives you | ||
|
|
||
| - A machine-readable Data Contract instead of opaque runtime generation. | ||
| - Deterministic Contract Artifacts that are easy to inspect and reason about. | ||
| - Verification gates before state changes and before query execution. | ||
| - A composable query surface that produces explicit immutable Plans. | ||
|
|
||
| ## Key terms you will see everywhere | ||
|
|
||
| - **Schema**: Human-authored data model. | ||
| - **Data Contract**: Canonical data representation emitted from the Schema. | ||
| - **Contract Artifacts**: `contract.json` and `contract.d.ts`. | ||
| - **Storage Hash**: Identity of storage structure. | ||
| - **Profile Hash**: Identity of capability profile. | ||
| - **Database Signing**: Writing verified contract identity into the database marker. | ||
| - **Contract Marker**: Signed contract identity stored in the database. | ||
| - **Plan**: Immutable query representation prepared for runtime execution. | ||
| - **Verified Runtime Query**: Query execution only after marker verification succeeds. | ||
|
|
||
| ## One-paragraph definition | ||
|
|
||
| Prisma Next is a contract-driven data access layer, not Prisma ORM. It takes an authored Schema, emits deterministic Contract Artifacts, signs the database to that contract, and enforces verification again before runtime queries execute. This Verification-First Workflow gives teams and agents a clear, machine-readable, auditable path from data model intent to safe query execution. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| --- | ||
| title: Why Prisma Next? | ||
| description: Explain why Prisma Next uses a contract-driven, verification-first approach. | ||
| url: /orm/temp-next/why-prisma-next | ||
| metaTitle: "Why Prisma Next contract-driven verification-first architecture" | ||
| metaDescription: "Understand how Prisma Next reduces compatibility ambiguity with Data Contracts, Database Signing, and Verified Runtime Queries." | ||
| --- | ||
|
|
||
| Prisma Next exists to remove ambiguity in how applications and databases stay compatible over time. | ||
|
|
||
| Traditional generated-client workflows hide important behavior in generated runtime code. Prisma Next takes the opposite approach: it makes compatibility explicit, verifiable, and machine-readable through a Data Contract. | ||
|
|
||
| ## Why contract-driven | ||
|
|
||
| A contract-driven model solves three core problems: | ||
|
|
||
| 1. **Ambiguous compatibility** | ||
| Without a shared Data Contract, it is harder to prove that app code and database state agree. | ||
|
|
||
| 2. **Opaque behavior** | ||
| Generated code can hide assumptions and make change impact harder to inspect. | ||
|
|
||
| 3. **Weak automation surface** | ||
| Agents and tooling work better with deterministic Contract Artifacts than with implicit runtime behavior. | ||
|
|
||
| With Prisma Next, the Data Contract is the explicit system boundary. Every participant reads the same artifact and validates against the same hashes. | ||
|
|
||
| ## Why verification-first | ||
|
|
||
| Prisma Next applies verification before risky actions: | ||
|
|
||
| - Before Database Signing, Schema state is checked against the Data Contract. | ||
| - Before runtime execution, Storage Hash and Profile Hash are checked against the Contract Marker. | ||
| - If verification fails, execution halts with explicit mismatch signals instead of silently continuing. | ||
|
|
||
| This is the core idea behind a Verification-First Workflow: safety checks happen before mutations and before query execution, not after incidents. | ||
|
|
||
| ## Example: verification gate before execution | ||
|
|
||
| ```ts title="verification-gate.ts" | ||
| type ContractHashes = { storageHash: string; profileHash: string }; | ||
| type Marker = { storageHash: string; profileHash: string } | null; | ||
|
|
||
| function assertVerified(contract: ContractHashes, marker: Marker): void { | ||
| if (!marker) throw new Error('contract/marker-missing'); | ||
| if (contract.storageHash !== marker.storageHash) throw new Error('contract/hash-mismatch'); | ||
| if (contract.profileHash !== marker.profileHash) throw new Error('contract/hash-mismatch'); | ||
| } | ||
|
|
||
| // Runtime flow: | ||
| // 1. load contract hashes | ||
| // 2. read marker from database | ||
| // 3. assertVerified(...) | ||
| // 4. execute Plan only if verification passes | ||
| ``` | ||
|
|
||
| ## Why this matters in practice | ||
|
|
||
| - Teams can reason about change with explicit lifecycle checkpoints. | ||
| - Platform and data workflows become more auditable and deterministic. | ||
| - Agent-assisted development becomes safer because the artifacts are machine-readable. | ||
| - Runtime behavior is predictable because queries are executed only in a verified state. | ||
|
|
||
| ## Prisma Next vs Prisma ORM (high-level positioning) | ||
|
|
||
| Prisma Next is not a rebrand of Prisma ORM. It is a different architecture: | ||
|
|
||
| - Prisma ORM emphasizes generated client methods. | ||
| - Prisma Next emphasizes Contract Artifacts, Database Signing, and Verified Runtime Queries. | ||
|
|
||
| The goal is not to hide complexity. The goal is to make correctness and compatibility explicit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to display this description in the page ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do, just an oversight with a poor description lol. I can get that updated.
Regarding the mermaid diagram (i can't reply to it's comment for some reason, so doing it here), I'll edit it to make it fit better. Ideally we'll create a mermaid eclipse component
I'm working on some large content changes for this PR so who knows if it'll even stay