# khachung/goprogramming architecture

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

- Interactive diagram: https://gitdiagram.com/khachung/goprogramming
- Repository: https://github.com/khachung/goprogramming

## Overview

##### Project Type and Purpose
- This is a monolithic Go server (“gobot”) that implements a Facebook Messenger chatbot.
- Its sole responsibility is to receive Messenger webhooks, run bot logic, and reply via the Facebook Graph API.

##### File Structure
- Root
- README.md – project description
- gobot/ (Go sources)
- main.go – entry point, HTTP server setup
- bot.go – core bot logic (message routing, business rules)
- message.go – data structures for incoming/outgoing Messenger payloads

##### README
- Confirms: “gobot” is a Facebook Messenger chatbot monolith.
- No database layer or separate services mentioned; everything lives in one process.

##### Main Components
a. External Service
– Facebook Messenger Platform (webhook provider & Graph API endpoint)
b. Gobot Server
– HTTP Webhook Listener (net/http)
– Request Parser (message.go types, JSON unmarshal)
– Bot Core Logic (bot.go)
– Response Generator (JSON marshal of reply messages)
– Facebook Graph API Client (outgoing HTTP POST)
c. Configuration & Logging
– Environment/config module (page tokens, verify tokens)
– Logging subsystem (console or file)
d. (Optional) Persistence
– If extended later, e.g., a Redis or SQL component for state

##### Relationships & Data Flow
- Listener → Request Parser → Bot Logic
- Bot Logic → Response Generator → Graph API Client → Facebook
- Configuration module feeds tokens to Listener & API Client
- Logging captures each step (incoming request, processing, outgoing reply)

##### Architectural Patterns & Principles
- Monolith with clear module separation
- Single responsibility per Go file: HTTP handling, data modeling, business logic
- Dependency inversion: core logic decoupled from HTTP framework

##### Technologies & Libraries
- Go standard library: net/http, encoding/json
- Facebook Graph API over HTTPS
- Environment variables for secrets

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External System
    FB["Facebook Messenger Platform"]:::external

    %% Gobot Server Modules
    subgraph "Gobot Server"
        WL["Webhook Listener"]:::http
        RP["Request Parser"]:::http
        BL["Bot Core Logic"]:::business
        RG["Response Generator"]:::http
        FC["Facebook API Client"]:::http
        CL["Configuration & Logging"]:::config
    end

    %% Data Flow
    FB -->|"Webhook (JSON payload)"| WL
    WL -->|"raw JSON"| RP
    RP -->|"Parsed Message"| BL
    BL -->|"Bot Response"| RG
    RG -->|"Reply JSON"| FC
    FC -->|"Send Message API Call"| FB

    %% Config & Logging dependencies
    CL -.-> WL
    CL -.-> FC
    CL -.-> RP
    CL -.-> BL
    CL -.-> RG

    %% Click Events
    click WL "https://github.com/khachung/goprogramming/blob/master/gobot/main.go"
    click RP "https://github.com/khachung/goprogramming/blob/master/gobot/message.go"
    click BL "https://github.com/khachung/goprogramming/blob/master/gobot/bot.go"
    click RG "https://github.com/khachung/goprogramming/blob/master/gobot/message.go"
    click FC "https://github.com/khachung/goprogramming/blob/master/gobot/bot.go"
    click CL "https://github.com/khachung/goprogramming/blob/master/gobot/main.go"

    %% Styles
    classDef external fill:#dddddd,stroke:#888,color:#333
    classDef http fill:#bbdefb,stroke:#2196f3,color:#0d47a1
    classDef business fill:#c8e6c9,stroke:#4caf50,color:#1b5e20
    classDef config fill:#fff9c4,stroke:#fbc02d,color:#f57f17
```
