Skip to main content

Architecture Overview

This document provides a comprehensive overview of CVT's system architecture, components, and design decisions.

Introduction

CVT (Contract Validator Toolkit) is a contract validation platform for OpenAPI v2/v3 specifications. It consists of:

  • CVT Server: A Go-based gRPC server that validates HTTP request/response interactions against registered OpenAPI schemas
  • Client SDKs: Native libraries for Node.js, Python, Go, and Java that communicate with the server
  • Storage Backends: Pluggable persistence layer supporting in-memory, SQLite, and PostgreSQL
  • Observability Stack: Prometheus metrics and Grafana dashboards for monitoring

System Overview

Core Components

CVT Server

The server is implemented in Go and provides the following capabilities:

ComponentTechnologyPurpose
gRPC Servicegrpc-goRPC interface for all client operations
Validation Enginekin-openapiOpenAPI parsing and request/response validation
RoutergorillamuxRoute matching for OpenAPI paths
CacheRistrettoHigh-performance LRU cache for schemas
LoggingZapStructured logging
MetricsPrometheusObservability metrics

Key characteristics:

  • Single static binary (~23MB)
  • Container image ~30-40MB (Alpine-based)
  • Memory footprint: 50-100MB typical
  • Startup time: <1 second

Client SDKs

All SDKs provide a consistent interface for contract validation:

SDKLanguageFeatures
Node.jsTypeScriptDynamic proto loading, Axios/Fetch adapters
PythonPython 3.11+requests/httpx adapters, uv package manager
GoGo 1.25+http.RoundTripper adapter
JavaJava 21+Maven build, Spring/Servlet middleware

SDKs are pure validator clients - they handle gRPC communication, configuration, and authentication but do not execute HTTP requests themselves.

Storage Backends

CVT supports three storage backends:

BackendUse CasePersistencePerformance
In-MemoryDevelopment, CINoneFastest
SQLiteSingle-instanceFile-basedFast
PostgreSQLProductionExternal DBScalable
Storage Architecture

For detailed information about the storage layer, caching strategies, and data models, see Storage Layer Architecture.

Observability Stack

CVT integrates with Prometheus and Grafana for monitoring:

  • Metrics Endpoint: Exposes Prometheus metrics on port 9551
  • Prometheus: Scrapes metrics every 10 seconds
  • Grafana: Pre-configured dashboards for validation performance
Observability Details

For complete metrics reference, alert configuration, and dashboard setup, see the Observability Guide.

gRPC Service Contract

The CVT server exposes the following gRPC services, organized by functional phase:

Phase 1: Schema & Validation

ServiceInputOutputPurpose
RegisterSchemaSchema ID, content, versionSuccess status, metadataRegister OpenAPI schema
ValidateInteractionSchema ID, request, responseValidation resultValidate HTTP interaction
GetSchemaSchema ID, versionSchema content, metadataRetrieve registered schema
ListSchemasFilters, paginationSchema listList all schemas
CompareSchemasSchema ID, old/new versionsBreaking changesDetect breaking changes
GenerateFixtureSchema ID, endpointRequest/response fixtureGenerate test data
ListEndpointsSchema IDEndpoint listList schema endpoints
ValidateProducerResponseSchema ID, method, path, responseValidation resultProducer-side validation

Phase 2: Consumer Registry

ServiceInputOutputPurpose
RegisterConsumerConsumer ID, schema ID, endpointsConsumer infoRegister consumer dependency
ListConsumersSchema ID, environmentConsumer listList schema consumers
DeregisterConsumerConsumer ID, schema IDSuccess statusRemove consumer registration

Phase 3: Deployment Safety

ServiceInputOutputPurpose
CanIDeploySchema ID, new version, environmentSafety assessmentCheck deployment safety
Validation Engine

For detailed information about how validation works, including the kin-openapi integration and route matching, see Validation Engine Architecture.

Deployment Models

CVT supports multiple deployment models to fit different use cases:

Local Development

┌─────────────────────────────────────────────────────────────┐
│ Developer Machine │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ gRPC ┌──────────────────────────┐ │
│ │ Test Suite │ ──────────► │ CVT Server (Docker) │ │
│ │ (Jest/etc) │ │ Port 9550 │ │
│ └──────────────┘ └──────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘

Characteristics:

  • Run via make up or docker compose up
  • In-memory or SQLite storage
  • Full observability stack optional

CI/CD Pipeline

┌─────────────────────────────────────────────────────────────┐
│ CI Runner │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. Start Container ┌────────────────────┐ │
│ ─────────────────► │ CVT Server │ │
│ │ (ephemeral) │ │
│ 2. Run Tests │ │ │
│ ─────────────────► │ │ │
│ │ │ │
│ 3. Stop Container │ │ │
│ ─────────────────► └────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘

Characteristics:

  • Ephemeral container lifecycle
  • In-memory storage (no persistence needed)
  • Fast startup for pipeline efficiency

Centralized Production

┌─────────────────────────────────────────────────────────────┐
│ Production Environment │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌─────────────────────┐ │
│ │ Service A │ ───┐ │ CVT Server │ │
│ └──────────────┘ │ │ (persistent) │ │
│ │ gRPC │ │ │ │
│ ┌──────────────┐ ├──────────► │ ▼ │ │
│ │ Service B │ ───┤ │ ┌───────────┐ │ │
│ └──────────────┘ │ │ │ PostgreSQL│ │ │
│ │ │ └───────────┘ │ │
│ ┌──────────────┐ │ │ │ │
│ │ Service C │ ───┘ │ Prometheus/ │ │
│ └──────────────┘ │ Grafana │ │
│ └─────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘

Characteristics:

  • PostgreSQL for persistent storage
  • Consumer registry for deployment safety
  • Full observability with alerting
  • TLS/mTLS for secure communication

Performance Architecture

CVT is designed for high-throughput validation with low latency.

Performance Targets

MetricTargetAchieved By
Throughput5000+ validations/secGo concurrency, efficient caching
Startup time<1 secondSingle static binary
Memory50-100MBRistretto cache with bounded size
Container size30-40MBAlpine base, multi-stage build

Caching Strategy

The caching layer is critical for performance:

┌──────────────────────────────────────────────────────────────┐
│ Request Flow │
├──────────────────────────────────────────────────────────────┤
│ │
│ ValidateInteraction │
│ │ │
│ ▼ │
│ ┌───────────┐ Hit ┌──────────────────────────────┐ │
│ │ Cache │ ─────────► │ Return cached SchemaEntry │ │
│ │ Lookup │ │ (Document + Metadata) │ │
│ └───────────┘ └──────────────────────────────┘ │
│ │ │
│ │ Miss │
│ ▼ │
│ ┌───────────┐ ┌──────────────────────────────┐ │
│ │ Storage │ ─────────► │ Load from backend, │ │
│ │ Read │ │ populate cache, return │ │
│ └───────────┘ └──────────────────────────────┘ │
│ │
└──────────────────────────────────────────────────────────────┘

Cache configuration:

  • Maximum schemas: 1000
  • TTL: 24 hours
  • Eviction policy: LRU with TinyLFU admission

Concurrency Model

Go's goroutine-based concurrency allows CVT to handle many concurrent requests efficiently:

  • Each gRPC request is handled in its own goroutine
  • Schema cache is thread-safe (Ristretto handles concurrency)
  • Consumer registry uses mutex protection for writes
  • No global locks in the hot path
Storage Deep Dive

For detailed information about the caching implementation and storage backends, see Storage Layer Architecture.

Security Architecture

CVT provides multiple layers of security:

Transport Security

FeatureConfigurationPurpose
TLSCVT_TLS_ENABLED=trueEncrypt all communication
mTLSCVT_TLS_CLIENT_AUTH=requireMutual authentication

Authentication

MethodConfigurationPurpose
API KeysCVT_API_KEY_ENABLED=trueClient authentication
Key FileCVT_API_KEYS_FILEExternalized key management

Container Security

  • Non-root user in Docker image
  • Read-only filesystem support
  • No shell in production image
  • Resource limits configurable

Deep Dive Documents

For detailed information about specific subsystems:

DocumentTopics Covered
Validation Enginekin-openapi integration, route matching, request/response validation
Storage LayerCaching, persistence backends, data models
Consumer RegistryConsumer tracking, deployment safety, breaking change detection
SDK ArchitectureSDK design patterns, adapters, cross-language consistency