You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-68
Original file line number
Diff line number
Diff line change
@@ -28,17 +28,23 @@ leading to brittle integrations, manual fixes, and unexpected failures.
28
28
29
29
**Some of the biggest pain points teams face include:**
30
30
31
-
-**Schema Drift & Misalignment:** APIs and data contracts become inconsistent across teams, leading to mismatches,
32
-
broken integrations, and regressions.
31
+
-**Schema Drift & Misalignment:** APIs and data contracts become inconsistent across teams, leading to mismatches, broken integrations, and regressions.
33
32
34
-
-**Code Sharing**: Teams struggle to share and reuse schemas across services, leading to duplicated efforts and
35
-
inconsistent data structures.
33
+
-**Untracked Changes & Breaking Updates:** Without tracking modifications, updates can unexpectedly break consumers, causing downtime and costly debugging.
36
34
37
-
-**Untracked & Breaking Changes:** Without tracking modifications, updates can unexpectedly break consumers, causing
38
-
downtime and costly debugging.
35
+
-**Scattered Schemas & Code Maintenance:** Outdated documentation and manually managed type definitions create unreliable integrations and make maintaining entity models error-prone.
39
36
40
-
-**Scattered Schemas & Code Maintenance:** Outdated documentation and manually managed type definitions create
41
-
unreliable integrations and make maintaining entity models error-prone.
37
+
38
+
## 🔑 The Contract-First Approach
39
+
Most teams take a **code-first** approach to API development, where schemas are generated after implementation. This often results in **misalignment between services, outdated documentation, and accidental breaking changes.** Backend teams define APIs, frontend teams consume them, and data engineers rely on structured data formats—all of which can drift over time when schemas are an afterthought.
40
+
41
+
A **contract-first** approach flips this process: schemas are designed before any implementation begins, ensuring that API structures, event definitions, and data formats remain stable and predictable. This approach allows teams to:
42
+
43
+
- Define schemas upfront and enforce them as the single source of truth.
44
+
45
+
- Track changes and prevent breaking updates before they impact consumers.
46
+
47
+
- Generate type-safe clients and server contracts in multiple languages, reducing friction between teams.
42
48
43
49
## 🚀 In Practice
44
50
@@ -169,66 +175,6 @@ Here’s a short video showing contract generation in action:
169
175
- Use generated type-safe clients to keep your frontend perfectly aligned with backend APIs.
170
176
- Integrate tools like React Query or Vue for a seamless developer experience.
171
177
172
-
## 🔑 The Contract-First Approach
173
-
174
-
Most teams take a code-first approach to API development, where schemas are generated after implementation. This leads
175
-
to misalignment between services, outdated documentation, and accidental breaking changes. Backend teams define APIs,
176
-
frontend teams consume them, and data engineers rely on structured data formats—all of which can drift over time when
177
-
schemas are an afterthought.
178
-
179
-
A contract-first approach flips this process: schemas are designed before any implementation begins, ensuring that API
180
-
structures, event definitions, and data formats remain stable and predictable. This approach allows teams to:
181
-
182
-
- Define schemas upfront and enforce them as the single source of truth.
183
-
184
-
- Track changes and prevent breaking updates before they impact consumers.
185
-
186
-
- Generate type-safe clients and server contracts in multiple languages, reducing friction between teams.
187
-
188
-
- Distribute schemas efficiently across backend services, frontend applications, and data pipelines.
189
-
190
-
---
191
-
192
-
1. **Define Once**:
193
-
- Use **TypeSpec**, a declarative DSL, to define your API or schema in a centralized file.
194
-
- This becomes the authoritative source for your API’s structure, endpoints, and data contracts.
195
-
196
-
2. **Generate Everything**:
197
-
- From the spec, Contractual generates:
198
-
- **OpenAPI specifications** for REST documentation and tooling.
199
-
- **Type-safe clients** with **ts-rest** and **Zod** for runtime validation.
200
-
- **Server contracts** for Express, Fastify, and NestJS.
201
-
- **JSON Schemas** for validation or data workflows.
202
-
203
-
3. **Version and Diff**:
204
-
- Track changes to your APIs or schemas.
205
-
- Use versioning and diffing tools to detect and prevent breaking changes.
206
-
207
-
4. **Enforce Consistency**:
208
-
- Use the spec to drive all API-related workflows, ensuring backend, frontend, and data teams are in sync.
209
-
210
-
211
-
## 📃 Goals
212
-
213
-
* Provide a centralized tool for managing OpenAPI and JSON Schema lifecycles.
214
-
215
-
* Simplify API workflows with type-safe client/server generation.
216
-
217
-
* Offer robust versioning and diffing tools to prevent breaking changes.
218
-
219
-
* Lay the foundation for multi-language support, starting with Python.
220
-
221
-
* Enable language-agnostic workflows, allowing developers to generate code and contracts across multiple languages (
222
-
e.g., TypeScript to Python).
223
-
224
-
* Introduce "contractual pack" to prepare contracts and generated clients/servers into distributable packages for
225
-
publication.
226
-
227
-
## 🚫 Non-Goals
228
-
229
-
* Contractual does not currently support gRPC, ProtoBufs, or GraphQL. While these protocols may be considered in the
230
-
future, the initial focus is on REST APIs and JSON Schemas.
231
-
232
178
## 📘 Roadmap
233
179
234
180
Want to contribute? Check out the alpha version [Roadmap](https://github.com/contractual-dev/contractual/issues/8) and
0 commit comments