# junah201/chzzk-discord-bot architecture

> Architecture diagram of the GitHub repository junah201/chzzk-discord-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/junah201/chzzk-discord-bot
- Repository: https://github.com/junah201/chzzk-discord-bot

## Overview

##### Main System Components

The system should be divided into these key components:

a) Frontend Layer
- React-based dashboard application
- User authentication flow
- Guild management interface
- Notification configuration UI

b) Backend Layer (Serverless)
- Lambda functions for different operations
- DynamoDB for data persistence
- Discord API integration
- Chzzk API integration

##### Key Architectural Elements

a) Client-Side Flow:
- User authentication via Discord OAuth2
- Dashboard interface for managing notifications
- Documentation and help pages

b) Serverless Backend:
- Event-driven Lambda functions
- Periodic checks for stream status
- Session management for Naver/Chzzk
- Discord webhook notifications

##### Specific Implementation Details

**[Frontend Application]**

- [Discord OAuth2 Flow]

- [API Gateway]

- [Lambda Functions]
- discord_oauth2_redirect
- discord_guilds
- discord_me
- event_handler
- live_check (5-min intervals)
- naver_session_renew (12-hour intervals)

- [DynamoDB]
- Notification configurations

- [External Services]
- Discord API
- Chzzk API

- [Notification Delivery]
- Discord Webhooks

##### Flow Directions

Key flows:
- User interaction flow
- Authentication flow
- Notification check flow
- Alert delivery flow

##### Important Notes

- Serverless architecture
- Event-driven nature of the system
- Periodic checks for stream status
- Session renewal mechanism
- Data persistence patterns

##### Special Attention Points

Crucial elements:
- Security flow with Discord OAuth2
- Periodic stream status checking mechanism
- Session management for Naver/Chzzk
- Error handling paths
- Scalability aspects of the serverless architecture

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Frontend
        Dashboard["Dashboard Interface"]
        Auth["Authentication Flow"]
        Guild["Guild Management"]
        ApiInt["API Integration Layer"]
    end

    subgraph "AWS API Gateway"
        API["REST API Endpoints"]
    end

    subgraph "Lambda Functions"
        OAuth["Discord OAuth2 Handler"]
        Guilds["Discord Guilds Handler"]
        UserInfo["Discord User Info"]
        EventH["Event Handler"]
        LiveCheck["Live Stream Check"]
        NaverRenew["Naver Session Renewal"]
        NotifMgmt["Notification Management"]
    end

    subgraph "Core Services"
        DiscordInt["Discord Integration"]
        ChzzkInt["Chzzk Integration"]
        DataModel["Data Models"]
        DbInterface["DynamoDB Interface"]
    end

    subgraph "External Services"
        DiscordAPI["Discord API"]
        ChzzkAPI["Chzzk API"]
    end

    subgraph "Data Storage"
        DynamoDB[(DynamoDB)]
    end

    %% Frontend connections
    Dashboard --> API
    Auth --> API
    Guild --> API
    ApiInt --> API

    %% API Gateway connections
    API --> OAuth
    API --> Guilds
    API --> UserInfo
    API --> EventH
    API --> NotifMgmt

    %% Lambda connections
    OAuth --> DiscordInt
    Guilds --> DiscordInt
    UserInfo --> DiscordInt
    EventH --> ChzzkInt
    LiveCheck --> ChzzkInt
    NaverRenew --> ChzzkInt
    NotifMgmt --> DbInterface

    %% Core service connections
    DiscordInt --> DiscordAPI
    ChzzkInt --> ChzzkAPI
    DbInterface --> DynamoDB
    DataModel --> DbInterface

    %% Styling
    classDef frontend fill:#3498db
    classDef lambda fill:#2ecc71
    classDef external fill:#f1c40f
    classDef core fill:#9b59b6
    classDef storage fill:#e74c3c

    class Dashboard,Auth,Guild,ApiInt frontend
    class OAuth,Guilds,UserInfo,EventH,LiveCheck,NaverRenew,NotifMgmt lambda
    class DiscordAPI,ChzzkAPI external
    class DiscordInt,ChzzkInt,DataModel,DbInterface core
    class DynamoDB storage

    %% Click events
    click Dashboard "https://github.com/junah201/chzzk-discord-bot/tree/main/frontend/src/pages/Dashboard"
    click Auth "https://github.com/junah201/chzzk-discord-bot/tree/main/frontend/src/pages/Login"
    click Guild "https://github.com/junah201/chzzk-discord-bot/tree/main/frontend/src/pages/Guild"
    click ApiInt "https://github.com/junah201/chzzk-discord-bot/tree/main/frontend/src/api"
    click OAuth "https://github.com/junah201/chzzk-discord-bot/tree/main/lambdas/discord_oauth2_redirect"
    click Guilds "https://github.com/junah201/chzzk-discord-bot/tree/main/lambdas/discord_guilds"
    click UserInfo "https://github.com/junah201/chzzk-discord-bot/tree/main/lambdas/discord_me"
    click EventH "https://github.com/junah201/chzzk-discord-bot/tree/main/lambdas/event_handler"
    click LiveCheck "https://github.com/junah201/chzzk-discord-bot/tree/main/lambdas/live_check"
    click NaverRenew "https://github.com/junah201/chzzk-discord-bot/tree/main/lambdas/naver_session_renew"
    click DiscordInt "https://github.com/junah201/chzzk-discord-bot/tree/main/shared/discord"
    click ChzzkInt "https://github.com/junah201/chzzk-discord-bot/blob/main/shared/chzzk.py"
    click DataModel "https://github.com/junah201/chzzk-discord-bot/blob/main/shared/models.py"
    click DbInterface "https://github.com/junah201/chzzk-discord-bot/blob/main/shared/dynamodb.py"
```
