# codacy/codacy-coverage-reporter architecture

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

- Interactive diagram: https://gitdiagram.com/codacy/codacy-coverage-reporter
- Repository: https://github.com/codacy/codacy-coverage-reporter

## Overview

##### Main Components
- Coverage Report Parser Module – Represented by the “coverage-parser” directory. This module contains a set of parser implementations (e.g., Clover, Cobertura, Jacoco, LCOV, Dotcover, PhpUnit, Go, OpenCover) that process various coverage report formats.
- API Integration Module – Shown in the “api-scala” directory. It includes classes for building requests, handling responses, processing timeouts, and communicating with the Codacy API.
- Core Reporter and Configuration – Located in the “src” directory (and parts of “src/main/scala/com/codacy”). This includes the main runner (CodacyCoverageReporter), configuration parsing (in the configuration folder), dependency injection (in the DI/Components file), and transformation logic for file paths and names.
- CI/CD Providers and Rules – The “src/main/scala/com/codacy/rules/commituuid/providers” folder contains different provider implementations (e.g., GitHubActionProvider, JenkinsProvider, TravisCIProvider, etc.) to integrate with a variety of CI/CD systems, thereby allowing the reporter to fetch commit UUIDs and related information.
- Build & Integration Tools – Additional folders and files like the CircleCI configuration (.circleci), GitHub workflows, Dockerfile, and a variety of test suites that showcase continuous integration and testing strategies.
- Utilities and Helpers – These include helpers for file operations, JSON utility classes, and transformation modules that help adjust paths and file names relative to the environment.

##### Relationships and Data Flow
- User Input/CI Integration: The process begins when the tool is invoked (usually via a CLI call or within a CI pipeline). This input is processed by the primary runner (CodacyCoverageReporter).
- Configuration Handling: At startup, the configuration parser reads the provided options (from flags/environment variables) to wire up the dependencies using the DI module.
- Coverage Parsing: Based on the specified coverage report file(s), control is passed to the relevant parser in the “coverage-parser” module. Each parser processes the raw report to produce a standardized coverage model.
- API Communication: Once the coverage data is standardized, the API Integration module (under “api-scala”) formats the data into a CoverageReport and sends it to the Codacy API via the CodacyClient.
- CI/CD Provider Integration: During execution, if the reporter is invoked in a continuous integration environment, the tool may invoke one of the many provider implementations to fetch additional metadata (like commit UUIDs) which are then used in the API calls.

##### Architectural Patterns and Design Principles
- Modular Architecture: The project is divided into logically isolated submodules (parsing, API integration, configuration, CI providers) enabling easier maintenance and testing.
- Dependency Injection (DI): The DI pattern is employed (see the “di/Components.scala” file) to decouple modules, making unit testing and module replacement straightforward.
- Plugin/Provider Pattern: The CI/CD integration providers illustrate a plugin pattern where multiple implementations adhere to a common interface, allowing the tool to work in various environments without changing the core logic.

##### Relevant Technologies and Frameworks
- Scala – The main programming language used in the implementation.
- SBT – Indicated by build.sbt and project configuration files.
- Docker – The Dockerfile shows how the reporter can be containerized.
- CI/CD Tools – CircleCI and GitHub Actions configurations in the .circleci and .github directories.
- Testing Framework – Note the extensive “src/test” and “coverage-parser/src/test” directories which indicate a robust suite of tests.
- Code Style/Formatting Tools – The existence of .scalafmt.conf indicates code formatting conventions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Entities
    A["User/CI Input"]:::external

    %% Core Reporter & Configuration
    subgraph "Core Reporter & Configuration"
        CR1["CodacyCoverageReporter"]:::core
        CR2["Configuration Parser"]:::core
        CR3["DI Components"]:::core
    end

    %% Coverage Parser Module
    subgraph "Coverage Parser Module"
        CP1["Coverage Parsers"]:::core
        CP2["Parser Implementations"]:::core
        CP3["Parser Utilities"]:::util
    end

    %% API Integration Module
    subgraph "API Integration Module"
        API1["API Module"]:::api
        API2["API Client"]:::api
        API3["API Service"]:::api
        API4["API Helpers"]:::api
    end

    %% CI/CD Providers
    subgraph "CI/CD Providers"
        CPV["CI/CD Providers"]:::providers
    end

    %% Utilities & Helpers
    subgraph "Utilities & Helpers"
        U1["Transformation Module"]:::util
    end

    %% Build & Integration Tools
    subgraph "Build & Integration Tools"
        B1[".circleci"]:::build
        B2[".github"]:::build
        B3["Dockerfile"]:::build
        B4["build.sbt"]:::build
    end

    %% External API
    Ex["Codacy API"]:::external

    %% Data Flow Connections
    A --> CR1
    CR1 -->|"triggers"| CP1
    CR1 -->|"fetches_metadata"| CPV
    CP1 -->|"delegates_to"| CP2
    CP2 -->|"processes"| CP3
    CP3 -->|"transforms"| U1
    U1 -->|"prepares"| API1
    CPV -->|"supplies_metadata"| API1
    API1 -->|"invokes"| API2
    API2 -->|"utilizes"| API3
    API3 -->|"assists"| API4
    API4 -->|"reports_to"| Ex

    %% Build Tools trigger via CI
    B1 -.-> A
    B2 -.-> A
    B3 -.-> A
    B4 -.-> A

    %% Click Events for Core Reporter & Configuration
    click CR1 "https://github.com/codacy/codacy-coverage-reporter/blob/master/src/main/scala/com/codacy/CodacyCoverageReporter.scala"
    click CR2 "https://github.com/codacy/codacy-coverage-reporter/blob/master/src/main/scala/com/codacy/configuration/parser/ConfigurationParser.scala"
    click CR3 "https://github.com/codacy/codacy-coverage-reporter/blob/master/src/main/scala/com/codacy/di/Components.scala"

    %% Click Events for Coverage Parser Module
    click CP1 "https://github.com/codacy/codacy-coverage-reporter/tree/master/coverage-parser/src/main/scala/com/codacy/parsers"
    click CP2 "https://github.com/codacy/codacy-coverage-reporter/tree/master/coverage-parser/src/main/scala/com/codacy/parsers/implementation"
    click CP3 "https://github.com/codacy/codacy-coverage-reporter/tree/master/coverage-parser/src/main/scala/com/codacy/parsers/util"

    %% Click Events for API Integration Module
    click API1 "https://github.com/codacy/codacy-coverage-reporter/tree/master/api-scala/src/main/scala/com/codacy/api"
    click API2 "https://github.com/codacy/codacy-coverage-reporter/tree/master/api-scala/src/main/scala/com/codacy/api/client"
    click API3 "https://github.com/codacy/codacy-coverage-reporter/tree/master/api-scala/src/main/scala/com/codacy/api/service"
    click API4 "https://github.com/codacy/codacy-coverage-reporter/tree/master/api-scala/src/main/scala/com/codacy/api/helpers"

    %% Click Event for CI/CD Providers
    click CPV "https://github.com/codacy/codacy-coverage-reporter/tree/master/src/main/scala/com/codacy/rules/commituuid/providers"

    %% Click Event for Utilities & Helpers
    click U1 "https://github.com/codacy/codacy-coverage-reporter/tree/master/src/main/scala/com/codacy/transformation"

    %% Click Events for Build & Integration Tools
    click B1 "https://github.com/codacy/codacy-coverage-reporter/blob/master/.circleci"
    click B2 "https://github.com/codacy/codacy-coverage-reporter/blob/master/.github"
    click B3 "https://github.com/codacy/codacy-coverage-reporter/tree/master/Dockerfile"
    click B4 "https://github.com/codacy/codacy-coverage-reporter/blob/master/build.sbt"

    %% Styles
    classDef core fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef api fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef providers fill:#ffff99,stroke:#000,stroke-width:2px;
    classDef build fill:#ffa07a,stroke:#000,stroke-width:2px;
    classDef external fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef util fill:#f0e68c,stroke:#000,stroke-width:2px;
```
