# ybg0416/slack-lunchtogether architecture

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

- Interactive diagram: https://gitdiagram.com/ybg0416/slack-lunchtogether
- Repository: https://github.com/ybg0416/slack-lunchtogether

## Overview

##### Project Type and Purpose
- This project is essentially an automation tool that, on weekdays at 11 AM, uses web automation and image processing to download a profile/menu image from a Kakao channel. It then crops the image using PIL, performs Optical Character Recognition (OCR) with PaddleOCR (ppOCR), and finally sends the parsed result to a designated Slack channel.
- The purpose is to automate the lunch menu workflow by verifying the menu image and communicating outcomes to Slack.

##### Analyzing the File Structure
- Top-Level Files and Directories:
- Dockerfile, .dockerignore, and related configuration files indicate that the project supports containerized deployment.
- The run.py file appears to be the entry point for executing the script.
- The cron directory suggests there is a scheduling mode (cron-based execution, likely to run periodically in a Docker container).
- Directories like fonts, input, output, and result_image indicate that the project manages assets and processed images, with separate folders for results (both 'ok' and 'fail' cases).
- Other files like util.py and slack.json likely contain helper functions and Slack configurations.

- Architectural Implications:
- The project is structured as a straightforward automated script rather than a full-stack or distributed system.
- The use of Docker and a cron directory indicates an option for containerized, scheduled automation.
- The separation between configuration (.env.example), image handling (result_image, fonts, input/output), and core logic (run.py, util.py) shows a clean separation of concerns.

##### Architectural Components
a. Main Components:
- Scheduler/Trigger:
- Cron-based scheduler (or Docker container’s timer) that initiates the job at the set time.
- Image Fetcher:
- Uses Playwright to download the profile/menu image from the Kakao channel.
- Image Processor:
- Library integration using PIL to crop and modify the downloaded image into a target for OCR.
- OCR Engine:
- PaddleOCR (ppOCR) that parses the processed image to extract the textual menu.
- Decision Logic:
- A component (likely embedded inside run.py/util.py) that checks if the image is valid (menu vs. non-menu) and decides whether to process further or exit.
- Slack Integration:
- Responsible for sending the final parsing result (or any error result) to Slack via a webhook (configured in the .env and referenced in slack.json).
- File Management:
- Directories for fonts, input, output, and result_image to store and manage resources and logs.
- Configuration & Environment:
- .env configuration for keys and endpoints (like SLACK_WEBHOOK_URL), and Docker-related files for container deployment.

b. Relationships and Data Flow:
- The scheduler triggers run.py that coordinates the entire pipeline.
- The Image Fetcher contacts the external Kakao server to get the profile image.
- The image then passes into the Image Processor (with PIL) which prepares it for OCR.
- The processed image is fed to the OCR Engine (using PaddleOCR) to extract text.
- The Decision Logic then checks the OCR results: if the text is as expected (i.e., valid menu), the process continues; otherwise, it might flag a failure.
- Finally, results are sent to Slack, and optionally files are updated in the result_image directories.
- Use of Docker allows all of the above to run in a controlled environment, ensuring dependencies as defined in requirements.txt and setups from Dockerfile.

c. Architectural Patterns & Design Principles:
- Separation of Concerns: Each component (fetching, processing, OCR, and integration) has its role.
- Modular Design: The use of separate modules and folders indicates that each functionality (image manipulation, Slack integration, etc.) can be maintained and potentially extended independently.
- Containerization: Docker encapsulates the environment, ensuring consistent deployment across different platforms.
- Environment Configuration: Use of .env files for sensitive configurations evidences good security and maintainability practices.

d. Relevant Technologies and Frameworks:
- Playwright for automated web interaction
- Python Imaging Library (PIL/Pillow) for image processing
- PaddleOCR/ppOCR for text recognition via OCR
- Slack API (via incoming webhook) for notifications
- Docker for containerized deployments
- Standard Python scripts with a virtual environment setup

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Scheduling & Coordination Group
    subgraph "Scheduling & Coordination"
        scheduler["Scheduler (Cron)"]:::scheduler
        coordinator["Pipeline Coordinator (run.py)"]:::processing
    end

    %% Image Processing Pipeline Group
    subgraph "Image Processing Pipeline"
        fetcher["Image Fetcher (Playwright)"]:::processing
        processor["Image Processor (PIL)"]:::processing
        ocr["OCR Engine (PaddleOCR)"]:::processing
        decision["Decision Logic (util.py)"]:::processing
    end

    %% Integration & Notification Group
    subgraph "Integration & Notification"
        slack["Slack Integration (Webhook)"]:::integration
    end

    %% File Management Group
    subgraph "File Management"
        fonts["Fonts Directory"]:::config
        input["Input Directory"]:::config
        output["Output Directory"]:::config
        resultOk["Result Image - OK"]:::config
        resultFail["Result Image - FAIL"]:::config
    end

    %% Environment & Configuration Group
    subgraph "Environment & Config"
        docker["Docker Configuration (Dockerfile, .dockerignore)"]:::config
        env["Env Template (.env.example)"]:::config
        slackConfig["Slack Config (slack.json)"]:::config
    end

    %% External Services
    kakao["External: Kakao Channel"]:::external
    slackService["External: Slack Service"]:::external

    %% Data Flow Connections
    scheduler -->|"triggers"| coordinator
    coordinator -->|"initiates image fetch"| fetcher
    fetcher -->|"downloads image from"| kakao
    fetcher -->|"passes image to"| processor
    processor -->|"prepares image for"| ocr
    ocr -->|"extracts text for"| decision
    decision -->|"on success->notify"| slack
    decision -->|"on failure->store in"| output

    coordinator -->|"accesses assets in"| fonts
    coordinator -->|"reads raw input from"| input
    coordinator -->|"stores outcomes in"| resultOk
    coordinator -->|"stores failures in"| resultFail

    coordinator -->|"loads container config from"| docker
    coordinator -->|"loads environment from"| env
    coordinator -->|"reads Slack webhook from"| slackConfig

    slack -->|"sends message to"| slackService

    %% Styles
    classDef scheduler fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef processing fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef integration fill:#f94144,stroke:#333,stroke-width:2px;
    classDef config fill:#577590,stroke:#333,stroke-width:2px;
    classDef external fill:#90a4ae,stroke:#333,stroke-width:2px;

    %% Click Events
    click scheduler "https://github.com/ybg0416/slack-lunchtogether/tree/master/cron/"
    click coordinator "https://github.com/ybg0416/slack-lunchtogether/blob/master/run.py"
    click fetcher "https://github.com/ybg0416/slack-lunchtogether/blob/master/run.py"
    click processor "https://github.com/ybg0416/slack-lunchtogether/blob/master/util.py"
    click ocr "https://github.com/ybg0416/slack-lunchtogether/blob/master/run.py"
    click decision "https://github.com/ybg0416/slack-lunchtogether/blob/master/util.py"
    click slack "https://github.com/ybg0416/slack-lunchtogether/blob/master/slack.json"
    click fonts "https://github.com/ybg0416/slack-lunchtogether/tree/master/fonts/"
    click input "https://github.com/ybg0416/slack-lunchtogether/tree/master/input/"
    click output "https://github.com/ybg0416/slack-lunchtogether/tree/master/output/"
    click resultOk "https://github.com/ybg0416/slack-lunchtogether/tree/master/result_image/ok"
    click resultFail "https://github.com/ybg0416/slack-lunchtogether/tree/master/result_image/fail"
    click docker "https://github.com/ybg0416/slack-lunchtogether/tree/master/Dockerfile"
    click env "https://github.com/ybg0416/slack-lunchtogether/blob/master/.env.example"
    click slackConfig "https://github.com/ybg0416/slack-lunchtogether/blob/master/slack.json"
```
