Dynamic Contract Protocol (DCP)
A contract-first, dynamic API protocol for AI-driven applications.
Why DCP?
DCP eliminates the need for static documentation like Swagger or Postman by enabling contract-driven API interactions. It supports REST, GraphQL, OData, and Protobuf with JWT-based authorization and regional data compliance.
Features
- ✅ Dynamic API generation
- ✅ JSON & Protobuf support
- ✅ JWT and API Key authorization
- ✅ AI-powered schema generation
- ✅ Lite mode for edge devices
Usage Journey
- Client sends a
ContractMessage
describing needed data. - Server responds with a
ContractAcknowledgement
if accepted. - Client sends a
DataRequest
using the agreed structure. - Server replies with a
DataResponse
containing results.
Contract Flow Diagram
sequenceDiagram
participant Client
participant AuthService
participant DCP
Client->>AuthService: Get JWT
AuthService->>Client: Return token
Client->>DCP: Submit ContractMessage
DCP->>AuthService: Validate JWT
AuthService-->>DCP: OK
DCP->>Client: ContractAcknowledgement
Client->>DCP: Send DataRequest
DCP-->>Client: Return DataResponse
ContractMessage Example
{
"type": "ContractMessage",
"protocol_version": "1.0",
"contract": {
"resources": [
{
"name": "Product",
"operations": ["get", "list"],
"fields": ["id", "name", "price"],
"filters": ["price > 100"]
}
],
"response_formats": ["json"]
}
}
ContractAcknowledgement Example
{
"type": "ContractAcknowledgement",
"status": "accepted",
"endpoints": {
"rest": "/dcp/client_123/products"
},
"expires_at": "2025-03-25T00:00:00Z"
}
DataRequest Example
{
"type": "DataRequest",
"resource": "Product",
"operation": "list",
"parameters": {
"filters": ["price < 200"],
"page": 1
}
}
DataResponse Example
{
"type": "DataResponse",
"data": [
{ "id": 1, "name": "Phone", "price": 199 }
],
"metadata": {
"total_records": 1,
"current_page": 1
}
}
Contract Schema Discovery
{
"schemas": {
"ContractMessage": "/schemas/contract.schema.json",
"DataRequest": "/schemas/data-request.schema.json"
}
}
OPA Policy Example
{
"contract": {
"resources": [
{
"name": "products",
"operations": ["get", "list"],
"fields": ["id", "name", "price", "stock"],
"filters": ["price > 100", "stock > 0"]
}
],
"policies": [
{
"name": "read_only_policy",
"source": "package dcp.read\nallow { input.method == \"GET\" }"
}
]
}
}
Contributing
We welcome contributions!
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature
- Commit your changes
- Open a pull request
See CONTRIBUTING.md for guidelines.
License
This project is licensed under the Apache 2.0 License.