# legit-labs/legitify architecture

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

- Interactive diagram: https://gitdiagram.com/legit-labs/legitify
- Repository: https://github.com/legit-labs/legitify

## Overview

##### Main Components

a. Core Components:
- Command Line Interface (CLI)
- Analyzers Engine
- Collectors System
- Policy Engine
- Output Formatters
- GPT Integration
- Scorecard Integration

b. External Services:
- GitHub API
- GitLab API
- OpenAI API (for GPT analysis)
- OSSF Scorecard

**┌─ User Interface Layer ─────────────────────┐**
- CLI Commands                             │
- GitHub Action Interface                  │
- ┬───────────────────────┘
- ↓
**┌─ Core Processing Layer ───────────────────┐**
- ┌─ Collection Engine ─┐ ┌─ Analysis Engine┐│
- GitHub Collector  │ │ - Policy Engine ││
- GitLab Collector  │ │ - OPA Rules     ││
- Entity Collectors │ │ - GPT Analyzer  ││
- ┘ └─────────────────┘│
- ┬───────────────────────┘
- ↓
**┌─ Integration Layer ────────────────────────┐**
- GitHub API Client                        │
- GitLab API Client                        │
- Scorecard Integration                    │
- OpenAI Integration                       │
- ┬───────────────────────┘
- ↓
**┌─ Output Layer ───────────────────────────┐**
- Human-readable Formatter                │
- JSON Formatter                          │
- SARIF Formatter                         │
- Output Schemes Handler                  │
- ┘

##### Additional Elements

Specific callouts for:
- Configuration management
- Error handling system
- Cache mechanism
- Authentication flow
- Policy evaluation pipeline

##### Technical Details to Highlight

- Built in Go
- Uses OPA (Open Policy Agent) for policy evaluation
- Supports multiple output formats
- Implements SLSA Level 3 Provenance
- Supports both cloud and enterprise deployments

##### Component Details

- Main purpose
- Key dependencies
- Input/Output formats
- Configuration options

##### Architectural Patterns to Emphasize

- Plugin architecture for collectors
- Strategy pattern for output formatting
- Factory pattern for client creation
- Observer pattern for progress monitoring

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        CLI["CLI Interface"]:::cli
        GHA["GitHub Action Interface"]:::ui
    end

    subgraph Core["Core Processing Layer"]
        subgraph Collection["Collection Engine"]
            Collectors["Collectors System"]:::core
            GHCollector["GitHub Collector"]:::collector
            GLCollector["GitLab Collector"]:::collector
        end

        subgraph Analysis["Analysis Engine"]
            Analyzers["Analyzers Engine"]:::core
            PolicyEngine["Policy Engine"]:::core
            GPTAnalyzer["GPT Integration"]:::integration
            ScorecardInt["Scorecard Integration"]:::integration
        end
    end

    subgraph Integration["Integration Layer"]
        GHClient["GitHub API Client"]:::client
        GLClient["GitLab API Client"]:::client
        OpenAI["OpenAI Integration"]:::external
        Scorecard["OSSF Scorecard"]:::external
    end

    subgraph Output["Output Layer"]
        OutputHandler["Output Schemes Handler"]:::output
        Formatters["Output Formatters"]:::output
        ErrorHandler["Error Handling System"]:::system
    end

    %% Relationships
    CLI --> Collectors
    CLI --> Analyzers
    GHA --> Collectors

    Collectors --> GHCollector
    Collectors --> GLCollector
    GHCollector --> GHClient
    GLCollector --> GLClient

    Analyzers --> PolicyEngine
    Analyzers --> GPTAnalyzer
    Analyzers --> ScorecardInt

    GPTAnalyzer --> OpenAI
    ScorecardInt --> Scorecard

    Analyzers --> OutputHandler
    OutputHandler --> Formatters
    ErrorHandler -.-> OutputHandler

    %% Click Events
    click CLI "https://github.com/legit-labs/legitify/tree/main/cmd/"
    click Collectors "https://github.com/legit-labs/legitify/blob/main/internal/collectors/collector.go"
    click GHCollector "https://github.com/legit-labs/legitify/tree/main/internal/collectors/github/"
    click GLCollector "https://github.com/legit-labs/legitify/tree/main/internal/collectors/gitlab/"
    click Analyzers "https://github.com/legit-labs/legitify/blob/main/internal/analyzers/analyzer.go"
    click PolicyEngine "https://github.com/legit-labs/legitify/tree/main/internal/opa/"
    click GPTAnalyzer "https://github.com/legit-labs/legitify/blob/main/internal/gpt/analyzer.go"
    click ScorecardInt "https://github.com/legit-labs/legitify/blob/main/internal/scorecard/wrapper.go"
    click GHClient "https://github.com/legit-labs/legitify/tree/main/internal/clients/github/"
    click GLClient "https://github.com/legit-labs/legitify/tree/main/internal/clients/gitlab/"
    click OutputHandler "https://github.com/legit-labs/legitify/blob/main/internal/outputer/scheme/scheme.go"
    click Formatters "https://github.com/legit-labs/legitify/tree/main/internal/outputer/formatter/"
    click ErrorHandler "https://github.com/legit-labs/legitify/blob/main/internal/errlog/errlog.go"

    %% Styles
    classDef core fill:#2374ab
    classDef cli fill:#457b9d
    classDef ui fill:#a8dadc
    classDef collector fill:#e63946
    classDef client fill:#f4a261
    classDef integration fill:#2a9d8f
    classDef external fill:#e9c46a
    classDef output fill:#9c89b8
    classDef system fill:#b8bedd

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[CLI Components]:::cli
        L3[UI Elements]:::ui
        L4[Collectors]:::collector
        L5[API Clients]:::client
        L6[Internal Integrations]:::integration
        L7[External Services]:::external
        L8[Output Components]:::output
        L9[System Components]:::system
    end
```
