home / skills / amnadtaowsoam / cerebraskills / event-contract-generator
This skill generates consistent event contracts including schemas, types, validators, and documentation to ensure producers and consumers share a common format.
npx playbooks add skill amnadtaowsoam/cerebraskills --skill event-contract-generatorReview the files below or copy the command above to add this skill to your agents.
---
name: Event Contract Generator
description: Generator for creating event schemas, types, validators, and documentation for event-driven architecture
---
# Event Contract Generator
## Overview
Automatically generates event contracts (schemas, types, validators) so that producers and consumers use the same event format.
## Why This Matters
- **Type safety**: TypeScript types from schema
- **Validation**: Auto-validate events
- **Documentation**: Auto-generated event catalog
- **Versioning**: Track schema changes
---
## Quick Start
```bash
# Generate event contract
npx generate-event-contract user.created
# Output:
events/user.created/
├── schema.json # JSON Schema
├── types.ts # TypeScript types
├── validator.ts # Validation functions
└── examples.json # Example events
```
---
## Generated Files
### Schema (JSON Schema)
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "UserCreated",
"type": "object",
"required": ["eventId", "eventType", "timestamp", "data"],
"properties": {
"eventId": { "type": "string", "format": "uuid" },
"eventType": { "const": "user.created" },
"timestamp": { "type": "string", "format": "date-time" },
"data": {
"type": "object",
"required": ["userId", "email"],
"properties": {
"userId": { "type": "string" },
"email": { "type": "string", "format": "email" },
"name": { "type": "string" }
}
}
}
}
```
### TypeScript Types
```typescript
// types.ts (auto-generated)
export interface UserCreatedEvent {
eventId: string;
eventType: 'user.created';
timestamp: string;
data: {
userId: string;
email: string;
name?: string;
};
}
```
### Validator
```typescript
// validator.ts (auto-generated)
import Ajv from 'ajv';
import schema from './schema.json';
const ajv = new Ajv();
const validate = ajv.compile(schema);
export function validateUserCreatedEvent(event: unknown): event is UserCreatedEvent {
return validate(event) as boolean;
}
```
---
## Event Catalog
### Auto-generated Documentation
```markdown
# Event Catalog
## user.created
**Version:** 1.0.0
**Producer:** user-service
**Consumers:** email-service, analytics-service
### Schema
- eventId: UUID (required)
- eventType: "user.created" (required)
- timestamp: ISO 8601 (required)
- data.userId: string (required)
- data.email: email format (required)
- data.name: string (optional)
### Example
```json
{
"eventId": "123e4567-e89b-12d3-a456-426614174000",
"eventType": "user.created",
"timestamp": "2024-01-16T12:00:00Z",
"data": {
"userId": "user_123",
"email": "[email protected]",
"name": "Test User"
}
}
```
```
---
## Versioning
```bash
# Create new version
npx generate-event-contract user.created --version 2.0.0
# Output:
events/user.created/
├── v1/
│ ├── schema.json
│ └── types.ts
└── v2/
├── schema.json # New version
└── types.ts
```
---
## Summary
**Event Contract Generator:** Automatically generates event schemas
**Generated:**
- JSON Schema
- TypeScript types
- Validators
- Documentation
- Examples
**Benefits:**
- Type safety
- Auto-validation
- Version control
- Event catalog
This skill generates event contracts for event-driven systems, producing JSON Schemas, TypeScript types, validators, examples, and documentation. It ensures producers and consumers share a single source of truth for event shapes and supports versioned contracts for safe evolution. The output is ready to use in build pipelines and service repositories.
Provide an event identifier and optional version, and the generator emits a folder with schema.json, types.ts, validator.ts, and examples.json. It creates JSON Schema compliant definitions, derives TypeScript types, compiles runtime validators (e.g., Ajv), and produces human-readable event catalog entries. Versioning organizes historical schemas into subfolders to maintain compatibility and auditability.
Can I generate multiple versions of the same event?
Yes. The generator places each version in its own subfolder (e.g., v1, v2) so services can reference the appropriate contract.
Which runtime validator is used?
The default output includes an Ajv-based validator, but the schemas are standard JSON Schema and can be used with other validation libraries.