# amrutjadhav/cardchecker architecture

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

- Interactive diagram: https://gitdiagram.com/amrutjadhav/cardchecker
- Repository: https://github.com/amrutjadhav/cardchecker

## Overview

##### Project Overview
- CardChecker is a Node.js application that listens to Trello webhook events when a new card is created or updated. It validates the card against a set of predefined rules (e.g., title word count, presence of description, due date checks, etc.) and, when issues are detected, it sends notifications to one or more messaging platforms (Slack, Teams, or Flock).
- The project is structured in a modular way with clear separation between controllers, validation rules, job processors, publishers, and utility functions.

##### Main Architectural Components
a. External Integrations:
- Trello: Source of webhook events. Trello sends card creation/updates to the CardChecker’s webhook endpoint.
- Messaging Platforms: Slack, Teams, and Flock—CardChecker pushes notifications to these channels if a card does not adhere to the configured standards.

b. Core Application Layers:
- Web Server / Entry Point: (index.js) The main entry point which likely initializes the server, routes, and middleware.
- Controllers Layer (app/controllers):
- Configuration Controller (configuration_controller.js): Handles API endpoints for subscribing Trello webhooks and configuration changes.
- Event Controller (event_controller.js): Receives and processes events from Trello.
- Handlers and Jobs:
- Handlers (app/handlers, e.g., card.js): Likely responsible for processing business logic around cards (parsing, normalization).
- Jobs (app/jobs, e.g., trello_checker.js): Potential background tasks, such as regularly checking card statuses or processing webhook events asynchronously.
- Models & Rules:
- Models (app/models/card.js): Representing the data structure for a Trello card.
- Rules (app/rules/card.js): Contains the logic for each card validation rule.
- Publishers (app/publishers):
- Code for each publisher (flock.js, slack.js, teams.js): Manages integration with respective messaging platforms to send notifications.
- Utilities (app/utilities):
- Utility functions (e.g., app/utilities/common.js and card.js): For common operations like parsing, formatting, or shared helper methods related to cards.
- Message Templates:
- A dedicated file (app/message_template.js) for constructing the content of notifications.
- Configuration:
- A default pipeline configuration file under config (config/default_pipeline_config.yml) that defines the behavior of the card checking rules.
- Additional configuration management (e.g., pipeline_config_validator.js) ensuring any provided pipeline_config overlays are valid.
- Logger configuration (config/logger.js) likely for standardized logging.

##### Relationships & Data Flow
- A Trello webhook event triggers an API call handled by the Event Controller.
- The controller calls upon the handler and model logic to extract and standardize the card data.
- The Rules layer validates the card against each predefined rule (using configurations from the pipeline YAML) to decide whether the card meets the standards.
- If a card does not pass validation, the Publishers are invoked to send notification messages to the appropriate external messaging service.
- The Configuration Controller provides endpoints to register new webhooks and update any pipeline configurations dynamically.
- Jobs (like trello_checker.js) might be scheduled or triggered asynchronously to perform additional checks or updates, ensuring that card validations are continuously enforced.

##### Architectural Patterns and Design Principles
- Modular Separation: The clear separation into controllers, handlers, models, rules, and publishers reflects a well-organized modular design.
- MVC-like Structure: Even if not a full MVC framework, the separation of concerns (e.g., controllers handling API endpoints and models representing core data) is evident.
- Extensibility: Publishers and rule modules are isolated, which allows for straightforward additions or modifications when integrating new messaging services or card rules.
- Configuration Overriding: The use of a default pipeline configuration that can be overridden by a user-specified configuration file (pipeline_config.json) encourages flexibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Integrations
    subgraph "External Integrations"
        T["Trello Webhook"]:::external
    end

    %% Entry Point & Controllers
    subgraph "Entry & Controllers"
        WS["Web Server (index.js)"]:::server
        CC["Configuration Controller"]:::controller
        EC["Event Controller"]:::controller
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        CH["Card Handler"]:::logic
        CM["Card Model"]:::logic
        CR["Validation Rules"]:::logic
    end

    %% Background Jobs
    subgraph "Background Jobs"
        JP["Trello Checker Job"]:::job
    end

    %% Notification Publishers
    subgraph "Notification Publishers"
        SP["Slack Publisher"]:::publisher
        TP["Teams Publisher"]:::publisher
        FP["Flock Publisher"]:::publisher
        MT["Message Template"]:::template
    end

    %% Configuration & Utilities
    subgraph "Configuration & Utilities"
        DU["Default Pipeline Config"]:::config
        LC["Logger Config"]:::config
        PV["Pipeline Config Validator"]:::config
        UC["Utility Common"]:::utility
        UC2["Utility Card"]:::utility
    end

    %% Relationships / Data Flow
    T -->|"triggers"| WS
    WS -->|"routes"| EC
    WS -->|"configurable"| CC
    EC -->|"calls"| CH
    JP -->|"triggers"| CH
    CH -->|"uses"| CM
    CH -->|"validates"| CR
    CH -->|"helper"| UC
    CH -->|"helper"| UC2
    CR -->|"uses"| DU
    CR -->|"fails"| SP
    CR -->|"fails"| TP
    CR -->|"fails"| FP
    SP -->|"via"| MT
    TP -->|"via"| MT
    FP -->|"via"| MT
    CC -->|"updates"| PV
    CC -->|"configures"| DU
    CC -->|"logsTo"| LC

    %% Click Events
    click WS "https://github.com/amrutjadhav/cardchecker/blob/master/index.js"
    click CC "https://github.com/amrutjadhav/cardchecker/blob/master/app/controllers/configuration_controller.js"
    click EC "https://github.com/amrutjadhav/cardchecker/blob/master/app/controllers/event_controller.js"
    click CH "https://github.com/amrutjadhav/cardchecker/blob/master/app/handlers/card.js"
    click JP "https://github.com/amrutjadhav/cardchecker/blob/master/app/jobs/trello_checker.js"
    click CM "https://github.com/amrutjadhav/cardchecker/blob/master/app/models/card.js"
    click CR "https://github.com/amrutjadhav/cardchecker/blob/master/app/rules/card.js"
    click FP "https://github.com/amrutjadhav/cardchecker/blob/master/app/publishers/flock.js"
    click SP "https://github.com/amrutjadhav/cardchecker/blob/master/app/publishers/slack.js"
    click TP "https://github.com/amrutjadhav/cardchecker/blob/master/app/publishers/teams.js"
    click MT "https://github.com/amrutjadhav/cardchecker/blob/master/app/message_template.js"
    click UC "https://github.com/amrutjadhav/cardchecker/blob/master/app/utilities/common.js"
    click UC2 "https://github.com/amrutjadhav/cardchecker/blob/master/app/utilities/card.js"
    click DU "https://github.com/amrutjadhav/cardchecker/blob/master/config/default_pipeline_config.yml"
    click LC "https://github.com/amrutjadhav/cardchecker/blob/master/config/logger.js"
    click PV "https://github.com/amrutjadhav/cardchecker/blob/master/pipeline_config_validator.js"

    %% Styles
    classDef external fill:#ADD8E6,stroke:#1B4F72,stroke-width:2px;
    classDef server fill:#FEE391,stroke:#B8860B,stroke-width:2px;
    classDef controller fill:#F6B19B,stroke:#D35400,stroke-width:2px;
    classDef logic fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef publisher fill:#D1C4E9,stroke:#6A1B9A,stroke-width:2px;
    classDef job fill:#F48FB1,stroke:#C2185B,stroke-width:2px;
    classDef config fill:#B3E5FC,stroke:#0288D1,stroke-width:2px;
    classDef utility fill:#FFECB3,stroke:#F57C00,stroke-width:2px;
    classDef template fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
```
