# znsio/specmatic architecture

> Architecture diagram of the GitHub repository znsio/specmatic, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/znsio/specmatic
- Repository: https://github.com/znsio/specmatic

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TD
    A["CLI / Application Module<br/>(Orchestrates commands and workflows)"]:::cli
    B["Core Contract Engine<br/>(Processes contracts, conversions, reporting)"]:::core
    C["JUnit5 & Testing Support Module<br/>(Integrates contract tests with JUnit5)"]:::junit
    D["Specmatic Config Files"]:::external
    E["Specifications Resources"]:::external
    F["Build & Deployment<br/>(Gradle, Docker, GitHub Workflows)"]:::build

    %% Relationships and Data Flow
    A -->|"triggers"| B
    B -->|"reports"| C
    B -->|"feedback"| A
    D -->|"supplies"| B
    E -->|"supplies"| B
    F ---|"build_support"| A
    F ---|"build_support"| B
    F ---|"build_support"| C

    %% Click Events
    click A "https://github.com/znsio/specmatic/tree/main/application/src/main/kotlin/application"
    click B "https://github.com/znsio/specmatic/tree/main/core/src/main/kotlin/io/specmatic"
    click C "https://github.com/znsio/specmatic/tree/main/junit5-support"
    click D "https://github.com/znsio/specmatic/tree/main/core/src/test/resources/specmaticConfigFiles"
    click E "https://github.com/znsio/specmatic/tree/main/application/src/test/resources/specifications"
    click F "https://github.com/znsio/specmatic/blob/main/build.gradle"

    %% Styles
    classDef cli fill:#ffcc00,stroke:#333,stroke-width:2px
    classDef core fill:#66ccff,stroke:#333,stroke-width:2px
    classDef junit fill:#99ff99,stroke:#333,stroke-width:2px
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:2px
    classDef external fill:#ff9999,stroke:#333,stroke-width:2px
```
