# nhemnt/slackify-api architecture

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

- Interactive diagram: https://gitdiagram.com/nhemnt/slackify-api
- Repository: https://github.com/nhemnt/slackify-api

## Overview

Based on your file tree and README, Slackify API is clearly a backend web application built using the NestJS framework. It integrates with Prisma for ORM (using a Supabase DB under the hood), and interacts with external systems such as Slack’s API via webhooks. The application is modular, featuring several feature-specific modules (like check-in-out, problems, trends), as well as a cron module that likely handles scheduled tasks (e.g., daily and weekly notifications).

##### Main Components
- API Server (NestJS Application): This is the central component where the application’s entry point (main.ts) initializes the system.
- Cron Module: Represent the cron service separately as it handles scheduled tasks that might trigger the Slack notifications and other scheduled features.
- External Services: Include a node for the Slack API, which is used to send messages to Slack channels via webhooks (you have environment variables like WEBHOOK_URI and WEBHOOK_URI_PUNCH_IN_OUT).
- Utilities & Middleware: Consider representing shared utilities (like the logger middleware and other helper functions under src/lib) as common/shared components.

##### Relationships and Data Flow
- Each module (check-in-out, problems, trends, etc.) receives incoming HTTP requests (as documented by the Swagger UI available at /docs) and sends/receives data to/from the Database.
- The Prisma Service bridges the NestJS backend and the Supabase DB.
- The cron module periodically triggers tasks that may involve fetching data from the database or preparing messages.

##### Architectural Patterns and Design Principles
- Scheduled Tasks: Emphasize the use of a dedicated Cron module to handle scheduled operations.
- External Integrations: Clearly indicate external integrations such as the Slack API and Supabase DB, ensuring to denote the dependency relationships.
- Configuration & Environment: Although not a runtime component, note that environment configuration (e.g., .env file) controls how external services and secrets (like the Bot User OAuth Access Token) are handled.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main API Server and Entry Point
    API["API Server (NestJS Application)"]:::internal
    Swagger["Swagger UI (/docs)"]:::internal

    %% Feature Modules subgraph
    subgraph "Feature Modules"
        CICO["Check-In-Out Module"]:::internal
        CICO_Ctrl["Check-In-Out Controller"]:::internal
        CICO_Svc["Check-In-Out Service"]:::internal

        Problems["Problems Module"]:::internal
        Problems_Ctrl["Problems Controller"]:::internal
        Problems_Svc["Problems Service"]:::internal

        Trends["Trends Module"]:::internal
        Trends_Ctrl["Trends Controller"]:::internal
        Trends_Svc["Trends Service"]:::internal

        Health["Health Module"]:::internal
        Health_Ctrl["Health Controller"]:::internal
    end

    %% Cron Module for scheduled tasks
    Cron["Cron Module"]:::internal

    %% Database Layer and ORM service
    PrismaSvc["Prisma Service"]:::internal
    DB["Supabase DB (via Prisma)"]:::database

    %% External Slack API service
    Slack["Slack API (Webhook)"]:::external

    %% Utilities & Middleware
    Utils["Utilities & Middleware"]:::internal

    %% Relationships
    Swagger --> API

    API -->|"routes to"| CICO_Ctrl
    API -->|"routes to"| Problems_Ctrl
    API -->|"routes to"| Trends_Ctrl
    API -->|"routes to"| Health_Ctrl
    API -->|"uses"| Utils

    %% Feature Modules internal flow
    CICO_Ctrl -->|"delegates"| CICO_Svc
    Problems_Ctrl -->|"delegates"| Problems_Svc
    Trends_Ctrl -->|"delegates"| Trends_Svc

    %% All services interact with the database via Prisma service
    CICO_Svc -->|"calls"| PrismaSvc
    Problems_Svc -->|"calls"| PrismaSvc
    Trends_Svc -->|"calls"| PrismaSvc
    Health_Ctrl -->|"checks"| PrismaSvc

    PrismaSvc -->|"accesses"| DB

    %% Cron Module interactions
    Cron -->|"triggers tasks via"| PrismaSvc
    Cron -->|"sends notifications to"| Slack

    %% Notification flow from a module example (Check-In-Out)
    CICO_Svc -->|"sends notification to"| Slack

    %% Click Events for Component Mapping
    click API "https://github.com/nhemnt/slackify-api/blob/main/src/main.ts"
    click API "https://github.com/nhemnt/slackify-api/blob/main/src/app.module.ts"
    click CICO "https://github.com/nhemnt/slackify-api/tree/main/src/check-in-out"
    click Problems "https://github.com/nhemnt/slackify-api/tree/main/src/problems"
    click Trends "https://github.com/nhemnt/slackify-api/tree/main/src/trends"
    click Health "https://github.com/nhemnt/slackify-api/tree/main/src/heath"
    click Cron "https://github.com/nhemnt/slackify-api/tree/main/src/cron"
    click PrismaSvc "https://github.com/nhemnt/slackify-api/blob/main/src/prisma.service.ts"
    click DB "https://github.com/nhemnt/slackify-api/tree/main/prisma"
    click Utils "https://github.com/nhemnt/slackify-api/tree/main/src/lib"
    click Utils "https://github.com/nhemnt/slackify-api/blob/main/src/logger.middleware.ts"
    click Slack "https://github.com/nhemnt/slackify-api/blob/main/.env.example"

    %% Styles
    classDef internal fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef database fill:#A9DFBF,stroke:#28B463,stroke-width:2px;
    classDef external fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;
```
