# snyk-tech-services/snyk-scm-contributors-count architecture

> Architecture diagram of the GitHub repository snyk-tech-services/snyk-scm-contributors-count, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/snyk-tech-services/snyk-scm-contributors-count
- Repository: https://github.com/snyk-tech-services/snyk-scm-contributors-count

## Overview

##### Project Overview
- This is a command-line interface (CLI) utility built in TypeScript that interacts with multiple Source Code Management (SCM) systems. It counts contributors with commits in the last 90 days and optionally verifies if repositories are monitored by Snyk.
- The tool supports several SCM platforms, each implemented as a distinct command and integration module.
- The provided README details how the commands work and lists examples for using the tool.

##### Key Components
a. CLI Entry & Command Parsing:
– Represent the main entry point from src/index.ts that initiates the CLI.
– Include a command-line parser that dispatches commands based on user input (e.g., reading options and the command name).

b. Command Handlers:
– Each SCM command lives under src/cmds (for example, azure-devops.ts, bitbucket-cloud.ts, github.ts, etc.).
– Each command handler is responsible for reading command-line arguments and coordinating further operations.

c. SCM Integration Modules:
– In src/lib, see separate directories for each SCM (such as azure-devops, bitbucket-cloud, bitbucket-server, github, github-enterprise, and gitlab).
– Each module implements the logic to interact with the corresponding SCM’s API (e.g., fetching contributors data).
– For new command integrations, the developer simply adds a new command handler and corresponding integration module.

d. Common Utilities and Shared Logic:
– Under src/lib/common there are utilities such as the SCMHandler base class, exclusion handling, and output formatting.
– Represent a shared common layer that the individual SCM modules extend or build upon.

e. Snyk Integration:
– The src/lib/snyk directory contains the code related to validating whether repositories are monitored by Snyk.
– Show that this component may be optionally invoked by some command handlers depending on the provided flags (such as --skipSnykMonitoredRepos).

f. Consolidate Results Module:
– The consolidation logic (found in src/lib/consolidateResults) is used to aggregate or process the results across multiple SCM queries.

##### Relationships & Data Flows
- All modules should then feed back into a “Results Consolidation” component (if used) and finally push the data back to an “Output Formatter” (likely leveraging shared common utilities).

##### Architectural Patterns & Design Principles
- Modularity: The design separates access to different SCM systems into independent modules.
- Abstraction: There’s a common abstraction (SCMHandler and shared common utilities) that allows for consistent operation across different integrations.
- Extensibility: With clearly defined command and integration modules, new SCM support can be added by following existing patterns.
- CLI-first design: Emphasize that this is a command-line tool with clearly defined commands and options.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    CLI["CLI Entry (src/index.ts)"]:::cli

    %% Command Handlers Layer
    subgraph "Command Handlers"
        CH_Azure["Command Handler - Azure DevOps (src/cmds/azure-devops.ts)"]:::command
        CH_BitbucketCloud["Command Handler - Bitbucket Cloud (src/cmds/bitbucket-cloud.ts)"]:::command
        CH_BitbucketServer["Command Handler - Bitbucket Server (src/cmds/bitbucket-server.ts)"]:::command
        CH_GitHub["Command Handler - GitHub (src/cmds/github.ts)"]:::command
        CH_GitHubEnterprise["Command Handler - GitHub Enterprise (src/cmds/github-enterprise.ts)"]:::command
        CH_GitLab["Command Handler - GitLab (src/cmds/gitlab.ts)"]:::command
        CH_Consolidate["Command Handler - Consolidate Results (src/cmds/consolidateResults.ts)"]:::command
    end

    %% SCM Integration Modules Layer
    subgraph "SCM Integration Modules"
        SCM_Azure["SCM Module - Azure DevOps (src/lib/azure-devops/azure-devops-contributors.ts)"]:::scm
        SCM_BitbucketCloud["SCM Module - Bitbucket Cloud (src/lib/bitbucket-cloud/bitbucket-cloud-contributors.ts)"]:::scm
        SCM_BitbucketServer["SCM Module - Bitbucket Server (src/lib/bitbucket-server/bitbucket-server-contributors.ts)"]:::scm
        SCM_GitHub["SCM Module - GitHub (src/lib/github/github-contributors.ts)"]:::scm
        SCM_GitHubEnterprise["SCM Module - GitHub Enterprise (src/lib/github-enterprise/github-enterprise-contributors.ts)"]:::scm
        SCM_GitLab["SCM Module - GitLab (src/lib/gitlab/gitlab-contributors.ts)"]:::scm
    end

    %% Other Modules
    Snyk["Snyk Integration (src/lib/snyk)"]:::snyk
    Consolidation["Results Consolidation (src/lib/consolidateResults/consolidate.ts)"]:::consolidation
    Common["Output Formatter & Common Utilities (src/lib/common)"]:::common

    %% Connections from CLI to Command Handlers
    CLI --> CH_Azure
    CLI --> CH_BitbucketCloud
    CLI --> CH_BitbucketServer
    CLI --> CH_GitHub
    CLI --> CH_GitHubEnterprise
    CLI --> CH_GitLab
    CLI --> CH_Consolidate

    %% Command Handlers to SCM Integration Modules
    CH_Azure --> SCM_Azure
    CH_BitbucketCloud --> SCM_BitbucketCloud
    CH_BitbucketServer --> SCM_BitbucketServer
    CH_GitHub --> SCM_GitHub
    CH_GitHubEnterprise --> SCM_GitHubEnterprise
    CH_GitLab --> SCM_GitLab

    %% SCM Modules to Consolidation (Direct Flow)
    SCM_Azure --> Consolidation
    SCM_BitbucketCloud --> Consolidation
    SCM_BitbucketServer --> Consolidation
    SCM_GitHub --> Consolidation
    SCM_GitHubEnterprise --> Consolidation
    SCM_GitLab --> Consolidation

    %% Optional Snyk Integration Flow (dashed arrows)
    SCM_Azure --- Snyk
    SCM_BitbucketCloud --- Snyk
    SCM_BitbucketServer --- Snyk
    SCM_GitHub --- Snyk
    SCM_GitHubEnterprise --- Snyk
    SCM_GitLab --- Snyk
    Snyk --- Consolidation

    %% Command Handler for Consolidation directly calls Consolidation Module
    CH_Consolidate --> Consolidation

    %% Results Consolidation to Output Formatter
    Consolidation --> Common

    %% Click Events
    click CLI "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/index.ts"
    click CH_Azure "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/cmds/azure-devops.ts"
    click CH_BitbucketCloud "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/cmds/bitbucket-cloud.ts"
    click CH_BitbucketServer "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/cmds/bitbucket-server.ts"
    click CH_GitHub "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/cmds/github.ts"
    click CH_GitHubEnterprise "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/cmds/github-enterprise.ts"
    click CH_GitLab "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/cmds/gitlab.ts"
    click CH_Consolidate "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/cmds/consolidateResults.ts"
    click SCM_Azure "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/lib/azure-devops/azure-devops-contributors.ts"
    click SCM_BitbucketCloud "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/lib/bitbucket-cloud/bitbucket-cloud-contributors.ts"
    click SCM_BitbucketServer "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/lib/bitbucket-server/bitbucket-server-contributors.ts"
    click SCM_GitHub "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/lib/github/github-contributors.ts"
    click SCM_GitHubEnterprise "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/lib/github-enterprise/github-enterprise-contributors.ts"
    click SCM_GitLab "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/lib/gitlab/gitlab-contributors.ts"
    click Snyk "https://github.com/snyk-tech-services/snyk-scm-contributors-count/tree/main/src/lib/snyk"
    click Consolidation "https://github.com/snyk-tech-services/snyk-scm-contributors-count/blob/main/src/lib/consolidateResults/consolidate.ts"
    click Common "https://github.com/snyk-tech-services/snyk-scm-contributors-count/tree/main/src/lib/common"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef command fill:#87CEFA,stroke:#000,stroke-width:1px;
    classDef scm fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef snyk fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef consolidation fill:#FFFACD,stroke:#000,stroke-width:1px;
    classDef common fill:#FFD700,stroke:#000,stroke-width:1px;
```
