# redhat-data-and-ai/naysayer architecture

> Architecture diagram of the GitHub repository redhat-data-and-ai/naysayer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/redhat-data-and-ai/naysayer
- Repository: https://github.com/redhat-data-and-ai/naysayer

## Overview

##### Project Type and Purpose
- NAYSAYER is a standalone backend service written in Go. It implements a GitLab webhook endpoint that automatically approves merge requests when warehouse sizes decrease in dataproduct YAML configurations. It does not include a UI; it’s a single-purpose automation/microservice.

##### Key Architectural Components (to represent
a. HTTP/Webhook Layer
- POST /webhook endpoint (cmd/main.go → Fiber router)
- GET /health endpoint for Kubernetes/OpenShift readiness and liveness checks
b. Configuration & Deployment
- config/*.yaml (deployment.yaml, route.yaml, serviceaccount.yaml, secrets.yaml.example)
- Environment variables (GITLAB_TOKEN, GITLAB_BASE_URL, PORT)
c. GitLab Client
- internal/gitlab/client.go: fetch MR changes via GitLab API
- internal/gitlab/file_content.go: retrieve individual file contents if needed
d. Rules Engine
- internal/rules/manager.go: orchestrates rule evaluation
- internal/rules/registry.go: holds available rules
- internal/rules/warehouse/analyzer.go + rule.go: implements warehouse-size-change logic
- shared types and utils (internal/rules/shared)
e. Logging
- internal/logging/logger.go: structured logging, log levels
f. Core Flow
- HTTP receives webhook → Configuration loaded → GitLab client fetches diffs → Rules manager analyzes diffs → Decision (approve or require manual review) → If auto-approve, GitLab client posts MR approval comment via API → Respond to webhook.

##### Relationships and Data Flow
- External System: GitLab sends merge request events → NAYSAYER /webhook
- HTTP handler decodes JSON payload → extracts project ID + MR IID
- Rules manager calls GitLab client to fetch MR changes
- Warehouse analyzer parses diff hunks for “warehouses:” blocks → computes up/down transitions
- Decision module determines auto-approve or deny → if approve, GitLab client POSTs an approval comment
- NAYSAYER returns JSON summary to caller
- Health endpoint always returns 200 if running

##### Architectural Patterns and Design Principles
- Layered design: Transport (HTTP) → Application (rules manager) → Infrastructure (GitLab API client)
- Single Responsibility: each package (logging, config, gitlab, rules, webhook) has one focus
- Dependency Injection via constructor functions in packages
- Test coverage: almost every package has accompanying _test.go

##### Technologies and Frameworks
- Go (1.23+)
- GoFiber for HTTP routing
- Kubernetes/OpenShift deployment manifests
- GitLab REST API v4
- YAML parsing (gopkg.in/yaml.v3 or similar)
- Makefile for build tasks, Dockerfile for container image

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External System
    GitLab["GitLab"]:::external
    GitLab -->|"Merge Request Event"| Webhook["POST /webhook\n(Webhook Receiver)"]:::transport

    %% NAYSAYER Container
    subgraph "NAYSAYER Microservice\n(Container/Pod)"
        direction TB
        ConfigLoader["Config Loader\n(internal/config)"]:::infra
        Logger["Structured Logger\n(internal/logging)"]:::infra
        Health["GET /health\n(Health Checker)"]:::transport
        Webhook
        RulesManager["Rules Manager\n(internal/rules/manager)"]:::business
        WarehouseAnalyzer["Warehouse Analyzer\n(internal/rules/warehouse)"]:::business
        Decision{"All decreases?"}:::business
        AutoApprove["Auto-approve Path"]:::business
        ManualReview["Manual review Path"]:::business
        GitLabClient["GitLab API Client\n(internal/gitlab/client)"]:::infra
    end

    %% ConfigMap/Secrets
    ConfigMap[(ConfigMap/Secrets\nconfig/)]:::infra
    ConfigMap -->|loads| ConfigLoader

    %% Internal Flow
    Webhook -->|decode payload| RulesManager
    RulesManager -->|invoke analyzer| WarehouseAnalyzer
    WarehouseAnalyzer -->|evaluate diffs| Decision
    Decision -->|yes| AutoApprove
    Decision -->|no| ManualReview
    AutoApprove -->|POST approval| GitLabClient
    GitLabClient -->|GET changes| RulesManager

    %% Health Check Flow
    Health -->|returns 200| GitLab

    %% Click Events
    click Webhook "https://github.com/redhat-data-and-ai/naysayer/blob/main/cmd/main.go"
    click Health "https://github.com/redhat-data-and-ai/naysayer/blob/main/internal/webhook/health.go"
    click ConfigLoader "https://github.com/redhat-data-and-ai/naysayer/blob/main/internal/config/config.go"
    click ConfigMap "https://github.com/redhat-data-and-ai/naysayer/tree/main/config/"
    click GitLabClient "https://github.com/redhat-data-and-ai/naysayer/blob/main/internal/gitlab/client.go"
    click RulesManager "https://github.com/redhat-data-and-ai/naysayer/blob/main/internal/rules/manager.go"
    click WarehouseAnalyzer "https://github.com/redhat-data-and-ai/naysayer/blob/main/internal/rules/warehouse/analyzer.go"
    click Logger "https://github.com/redhat-data-and-ai/naysayer/blob/main/internal/logging/logger.go"

    %% Styles
    classDef external fill:#e0f7e9,stroke:#2e7d32,color:#2e7d32;
    classDef transport fill:#e3f2fd,stroke:#1565c0,color:#1565c0;
    classDef business fill:#fff8e1,stroke:#f9a825,color:#f9a825;
    classDef infra fill:#fff3e0,stroke:#ef6c00,color:#ef6c00;
```
