# binary-ho/bandicute-server architecture

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

- Interactive diagram: https://gitdiagram.com/binary-ho/bandicute-server
- Repository: https://github.com/binary-ho/bandicute-server

## Overview

##### Main Components

a. External Services Layer:
- Tistory Blog API (for blog post collection)
- GitHub API (for PR creation)
- OpenAI GPT API (for summarization)
- Supabase (PostgreSQL database)

b. Core Application Components:
- API Server (Echo Framework)
- Job Scheduler
- Service Layer
- Storage Layer

##### Component Organization

**┌─ External Services ─────────────────────┐**
- Tistory API │ GitHub API │ OpenAI API   │
- ┘
- ↕️
**┌─ Application Layer ────────────────────┐**
- ┌─ API Layer (Echo) ─┐                │
- Routes           │                │
- Handlers         │                │
- ┘               │
- ┌─ Service Layer ──────┐               │
- Channel Service    │               │
- Parser Service     │               │
- Summarizer Service │               │
- Writer Service     │               │
- ┘               │
- ┌─ Job Scheduler ──────┐               │
- Write All Jobs     │               │
- ┘               │
- ┘
- ↕️
**┌─ Storage Layer ──────────────────────┐**
- ┌─ Repository Layer ─┐               │
- Member          │               │
- Post            │               │
- Study           │               │
- Pull Request    │               │
- Summary         │               │
- ┘                │
- ┘
- ↕️
**┌─ Database ────────────────────────────┐**
- Supabase                   │
- ┘

##### Key Interactions to Highlight

a. Blog Post Collection Flow:
- Job Scheduler → Tistory API
- Parser Service → Storage Layer
- Storage Layer → Supabase

b. Summarization Flow:
- Service Layer → OpenAI GPT API
- Summarizer Service → Storage Layer

c. GitHub Integration Flow:
- Writer Service → GitHub API
- Pull Request Service → Storage Layer

##### Additional Elements

**┌─ Template System ─────────────┐**
- Pull Request Templates      │
- Summary Prompt Templates    │
- ┘

##### Important Notes

- Clear separation between internal and external services
- Job scheduler's role in automation
- Repository pattern in the storage layer
- Error handling and retry flows
- Configuration management flow

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Services Layer
    subgraph External
        TistoryAPI["Tistory API"]:::external
        GitHubAPI["GitHub API"]:::external
        OpenAIAPI["OpenAI GPT API"]:::external
    end

    %% API Layer
    subgraph APILayer
        Routes["Routes"]:::api
        Handlers["Handlers"]:::api
    end

    %% Service Layer
    subgraph ServiceLayer
        ChannelService["Channel Service"]:::service
        ParserService["Parser Service"]:::service
        SummarizerService["Summarizer Service"]:::service
        WriterService["Writer Service"]:::service
        PRService["Pull Request Service"]:::service
    end

    %% Job Scheduler
    subgraph JobScheduler
        Scheduler["Scheduler"]:::scheduler
        WriteAllJobs["Write All Jobs"]:::scheduler
    end

    %% Storage Layer
    subgraph StorageLayer
        subgraph Repositories
            MemberRepo["Member Repository"]:::repo
            PostRepo["Post Repository"]:::repo
            StudyRepo["Study Repository"]:::repo
            PRRepo["Pull Request Repository"]:::repo
            SummaryRepo["Summary Repository"]:::repo
        end
        DBConnection["Database Connection"]:::db
    end

    %% Template System
    subgraph TemplateSystem
        PRTemplates["PR Templates"]:::template
        SummaryTemplates["Summary Templates"]:::template
        TemplateParser["Template Parser"]:::template
    end

    %% Utils
    subgraph Utils
        GitHubUtils["GitHub Utils"]:::util
        ParserUtils["Parser Utils"]:::util
        SummarizerUtils["Summarizer Utils"]:::util
    end

    %% Configuration
    subgraph Config
        ConfigHandler["Config Handler"]:::config
        Properties["Properties"]:::config
    end

    %% Database
    Supabase[(Supabase)]:::database

    %% Relationships
    Routes --> Handlers
    Handlers --> ServiceLayer
    
    ChannelService --> TistoryAPI
    ParserService --> PostRepo
    SummarizerService --> OpenAIAPI
    WriterService --> GitHubAPI
    PRService --> PRRepo
    
    Scheduler --> WriteAllJobs
    WriteAllJobs --> ServiceLayer
    
    Repositories --> DBConnection
    DBConnection --> Supabase
    
    ServiceLayer --> TemplateSystem
    ServiceLayer --> Utils
    
    ConfigHandler --> Properties
    Properties --> ServiceLayer

    %% Styles
    classDef external fill:#ADD8E6
    classDef api fill:#90EE90
    classDef service fill:#FFA500
    classDef scheduler fill:#FFFF00
    classDef repo fill:#DDA0DD
    classDef db fill:#0000FF
    classDef template fill:#FFB6C1
    classDef util fill:#F0E68C
    classDef config fill:#E6E6FA
    classDef database fill:#4169E1

    %% Click Events
    click Routes "https://github.com/binary-ho/bandicute-server/blob/main/internal/api/routes.go"
    click Handlers "https://github.com/binary-ho/bandicute-server/blob/main/internal/api/handlers.go"
    click ChannelService "https://github.com/binary-ho/bandicute-server/blob/main/internal/service/channel/channel.go"
    click ParserService "https://github.com/binary-ho/bandicute-server/blob/main/internal/service/parser.go"
    click SummarizerService "https://github.com/binary-ho/bandicute-server/blob/main/internal/service/summerizer.go"
    click WriterService "https://github.com/binary-ho/bandicute-server/blob/main/internal/service/writer.go"
    click PRService "https://github.com/binary-ho/bandicute-server/blob/main/internal/service/pull-reqeust.go"
    click Scheduler "https://github.com/binary-ho/bandicute-server/blob/main/internal/job/scheduler.go"
    click WriteAllJobs "https://github.com/binary-ho/bandicute-server/blob/main/internal/job/write-all.go"
    click MemberRepo "https://github.com/binary-ho/bandicute-server/tree/main/internal/storage/repository/member/"
    click PostRepo "https://github.com/binary-ho/bandicute-server/tree/main/internal/storage/repository/post/"
    click StudyRepo "https://github.com/binary-ho/bandicute-server/tree/main/internal/storage/repository/study/"
    click PRRepo "https://github.com/binary-ho/bandicute-server/tree/main/internal/storage/repository/pull-request/"
    click SummaryRepo "https://github.com/binary-ho/bandicute-server/tree/main/internal/storage/repository/summary/"
    click DBConnection "https://github.com/binary-ho/bandicute-server/blob/main/internal/storage/repository/connection/supabase.go"
    click PRTemplates "https://github.com/binary-ho/bandicute-server/blob/main/internal/template/templates/pull-request-template.json"
    click SummaryTemplates "https://github.com/binary-ho/bandicute-server/blob/main/internal/template/templates/summary-prompt.json"
    click TemplateParser "https://github.com/binary-ho/bandicute-server/blob/main/internal/template/parser.go"
    click GitHubUtils "https://github.com/binary-ho/bandicute-server/blob/main/internal/util/github.go"
    click ParserUtils "https://github.com/binary-ho/bandicute-server/blob/main/internal/util/parser.go"
    click SummarizerUtils "https://github.com/binary-ho/bandicute-server/blob/main/internal/util/summarizer.go"
    click ConfigHandler "https://github.com/binary-ho/bandicute-server/blob/main/config/config.go"
    click Properties "https://github.com/binary-ho/bandicute-server/blob/main/config/encrypted-property.yml"
```
