How znsio/specmatic works
Overall Project Modules
• CLI/Command Module ("application" directory):
– This is the entry point of the tool. It hosts many command implementations (for example, the BackwardCompatibilityCheckCommand, CompatibleCommand, MergeCommand, etc.) which respond to various user inputs.
– The CLI component orchestrates high-level work such as contract validation, generation of stubs, report creation, and proxying.
• Core Contract Engine ("core" directory):
– This module contains the domain logic. It implements extensible contract processing routines including pattern matching, protocol conversions (OpenAPI, AsyncAPI, WSDL, etc.), scenario handling, and report generation.
– It integrates features like logging (with multiple logger implementations), filtering, overlays, and utilities for file system operations and Git integration.
• JUnit5/Testing Support ("junit5-support" directory):
– This module provides integration support for executing Specmatic tests within the JUnit5 ecosystem.
– It also includes utilities and listeners that capture test execution details and generate reports such as OpenAPI coverage reports in various output formats (HTML/JSON/console).
• Build and Deployment:
– Gradle build scripts (build.gradle at the root and in module directories), gradle wrapper, and Dockerfile show that the project is containerized and built using Gradle.
– CI/CD integration is evident from the GitHub workflows and related config files.
• Supporting Artifacts:
– There are numerous test resources and sample specification files which are used to validate different scenarios across multiple API specification types.
– Configuration and resource files (like various specmaticConfigFiles) indicate how the tool manages versioned configuration and externalized data.
Relationships and Data Flow
• The CLI module receives user commands and orchestrates workflows that call functions in the core module.
• The core engine processes contracts: it parses API definitions, applies conversion routines (as seen in the conversions package), validates contract adherence, and generates outputs (like stub responses or detailed reports).
• Logging and reporting components within the core module communicate with the testing support module to clearly display results.
• The JUnit5 support module integrates testing frameworks with the core contract logic, facilitating automated contract testing.
• External specifications (OpenAPI/AsyncAPI, etc.) feed into the core engine while generated outputs (stub examples, contract reports) form the feedback loop.
• Build scripts and deployment configurations (Dockerfile, GitHub workflows, gradle scripts) are separate but ensure that all modules build coherently and are deployed as containers or consumed via Maven.
Architectural Patterns and Design Principles
• Modular design: Separate modules for command-line interaction, core business logic, and testing integration promote separation of concerns.
• Dependency inversion: The core module exposes functionality that the CLI and test modules consume, allowing easy extension and substitution.
• File-based configuration and extensibility: The presence of multiple configuration directories and external resource files indicates an architecture that is both configurable and extensible.
• Integration of external services and frameworks: With support for multiple API specification formats and externalized contract validations, the design leverages adapters and converters.