# adhocteam/certwatcher architecture

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

- Interactive diagram: https://gitdiagram.com/adhocteam/certwatcher
- Repository: https://github.com/adhocteam/certwatcher

## Overview

##### Project Type & Purpose
- This is a utility tool (CLI app) written in Go.
- Its purpose is to:
- Read a list of host URLs (and optional descriptions) from a CSV file.
- Check the SSL/TLS certificate status for each host.
- Alert via SMTP if any certificate is expiring soon.
- With very few files (main.go, main_test.go, Makefile, config example, etc.), it follows a single-application, minimal architecture.

##### Analyzing the File Structure
- Top-level files include:
- main.go: The core application logic.
- main_test.go: Test cases for the main functionality.
- config.ini.example: An example configuration file (SMTP and possibly other parameters).
- Makefile: Likely used for building, testing, and/or running the project.
- There is no explicit separation into directories, meaning that all components are tightly integrated within the main application.

##### Key Architectural Components & Relationships
- Input Handling:
- CSV File Parser: Reads the list of URLs and (optional) descriptions.
- Validates the format (ignoring comments and parsing 'host,description' values).

- Certificate Checker:
- For each host, establishes an HTTPS connection to retrieve its certificate.
- Checks the certificate’s expiry date against the threshold specified by a command-line parameter (e.g., -days 90).

- Notification Service:
- Reads SMTP configuration from config.ini.
- Sends an email notification if a certificate is about to expire.

- Logging & Reporting:
- Logs the status of each host’s certificate check (e.g., “certificate is ok”).
- Logs notification events when alerts are sent.

- Testing:
- Included primary testing via main_test.go ensures the reliability of core functionalities (input validation, certificate checking logic, notification triggers).

a. And Label Main Components:
- “CSV Input Parser” (handles reading and sanitizing URL input).
- “Certificate Checker” (handles the connection, fetching the certificate, and evaluating expiration).
- “SMTP Notification Service” (manages email alerting when certificates are near expiration).
- “Configuration Manager” (loads SMTP and possibly other config options from config.ini).
- “Logging/Monitoring” (records status messages and alert events).

b. Relationships and Data Flow:
- The parser sends URL data to “Certificate Checker”.
- “Certificate Checker” interacts with external “Remote Hosts” (each providing a certificate).
- “SMTP Notification Service” then interacts with the “SMTP Server” (depicted as an external mail service).
- Throughout, include a “Logging” component that receives status updates from both the Checker and Notification Service.

c. Architectural Design Principles:
- Fact that the tool leverages built-in libraries (like Go’s crypto/tls, net/smtp, etc.) for its functionalities.

d. Relevant Technologies and Patterns:
- That this is a command-line utility built in Go.
- Mention that configuration is managed via an INI file.
- Use minimal layering but make sure to represent clear separation between input, business logic (certificate checking), and output (notification).

## Diagram (Mermaid)

```mermaid
flowchart TD
    operator["Operator/User"]:::external
    input["CSV File (Input)"]:::internal

    csvParser["CSV Input Parser"]:::internal
    certChecker["Certificate Checker"]:::internal
    smtpService["SMTP Notification Service"]:::internal
    configManager["Configuration Manager"]:::internal
    logging["Logging/Monitoring"]:::internal

    remote["Remote Host"]:::external
    smtpServer["SMTP Server"]:::external

    operator --> input
    input --> csvParser
    csvParser --> certChecker
    certChecker -->|"retrieves_certificate"| remote
    certChecker -->|"if_expiring"| smtpService
    configManager --> smtpService
    certChecker --> logging
    smtpService --> smtpServer
    smtpService --> logging

    click csvParser "https://github.com/adhocteam/certwatcher/blob/master/main.go"
    click certChecker "https://github.com/adhocteam/certwatcher/blob/master/main.go"
    click smtpService "https://github.com/adhocteam/certwatcher/blob/master/main.go"
    click configManager "https://github.com/adhocteam/certwatcher/blob/master/config.ini.example"
    click logging "https://github.com/adhocteam/certwatcher/blob/master/main.go"

    classDef internal fill:#a2d5f2,stroke:#1B4965,stroke-width:2px;
    classDef external fill:#f9c74f,stroke:#f3722c,stroke-width:2px;
```
