# sssungjin/velog-stats architecture

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

- Interactive diagram: https://gitdiagram.com/sssungjin/velog-stats
- Repository: https://github.com/sssungjin/velog-stats

## Overview

##### Project type and purpose
- This is a Chrome extension (“Velog Stats”) that fetches and displays real-time statistics (views, likes, comments) for a user’s Velog blog posts.
- It consists of a popup UI, background scripts, helper modules, and a small set of static pages (documentation, release notes, privacy policy).

##### File structure
- Manifest (manifest.json): defines extension permissions, scripts, pages.
- UI components:
- popup.html / popup.js – the extension’s main interface where the user enters a Velog ID and clicks “조회.”
- pages/index.html (+ CSS), pages/release-notes.html – documentation and landing pages served from the extension.
- Background logic:
- background.js – listens for events (e.g., popup requests), orchestrates API calls.
- api.js – encapsulates HTTP calls to the Velog API, retrieving posts and stats.
- logManager.js – processes, caches, and sorts the fetched statistical data.
- utils.js – shared helper functions (e.g., cookie retrieval).
- Privacy policy and static HTML are extra pages registered in the manifest.

##### Key dependencies & interactions (from README)
- Uses Chrome extension APIs for message passing, cookie access, and storage.
- Relies on the Velog site’s `access_token` cookie for authentication when calling Velog’s REST endpoints.
- No external build tools—pure HTML/JS/CSS loaded by the browser.

##### Detail
- Which Chrome extension APIs are in use (e.g., chrome.runtime.sendMessage, chrome.cookies.get).
- Error or loading states if they affect architecture (e.g., error handling in background.js).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Entities
    User["User"]:::external
    VelogAPI["Velog REST API"]:::external
    CookieStore["Velog Site Cookie Store"]:::external

    %% Chrome Browser and Extension
    subgraph "Chrome Browser"
        subgraph "Chrome Extension"
            Manifest["manifest.json"]:::config

            subgraph "Popup UI Layer"
                PopupHTML["popup.html"]:::ui
                PopupJS["popup.js"]:::ui
                Styles["styles.css"]:::ui
            end

            Background["background.js"]:::logic

            subgraph "API Module"
                API["api.js"]:::logic
                Utils["utils.js"]:::logic
            end

            LogManager["logManager.js"]:::logic

            subgraph "Static Pages"
                Docs["pages/index.html"]:::static
                DocsCSS["pages/index_styles.css"]:::static
                Release["pages/release-notes.html"]:::static
                Privacy["privacy-policy.md"]:::static
                Verify["google4988f32cd021f0f1.html"]:::static
            end
        end
    end

    %% Data Flows
    User -->|"clicks icon"| PopupHTML
    PopupHTML -->|"loads popup.js"| PopupJS
    PopupJS -->|"sendMessage(userID)"| Background
    Background -->|"fetchPosts() / fetchStats()"| API
    API -->|"chrome.cookies.get"| CookieStore
    API -->|"HTTP requests"| VelogAPI
    VelogAPI -->|"responses"| API
    API -->|"returns data"| Background
    Background -->|"aggregate()"| LogManager
    LogManager -->|"processed stats"| PopupJS

    User -->|"selects docs"| Docs
    User -->|"selects release notes"| Release
    User -->|"selects privacy policy"| Privacy
    User -->|"Chrome verification"| Verify

    %% Manifest relationships
    Manifest --> PopupHTML
    Manifest --> Background
    Manifest --> Docs
    Manifest --> Release
    Manifest --> Privacy
    Manifest --> Verify

    %% Click Events
    click PopupHTML "https://github.com/sssungjin/velog-stats/blob/master/popup.html"
    click PopupJS "https://github.com/sssungjin/velog-stats/blob/master/popup.js"
    click Styles "https://github.com/sssungjin/velog-stats/blob/master/styles.css"
    click Background "https://github.com/sssungjin/velog-stats/blob/master/background.js"
    click API "https://github.com/sssungjin/velog-stats/blob/master/api.js"
    click Utils "https://github.com/sssungjin/velog-stats/blob/master/utils.js"
    click LogManager "https://github.com/sssungjin/velog-stats/blob/master/logManager.js"
    click Manifest "https://github.com/sssungjin/velog-stats/blob/master/manifest.json"
    click Docs "https://github.com/sssungjin/velog-stats/blob/master/pages/index.html"
    click DocsCSS "https://github.com/sssungjin/velog-stats/blob/master/pages/index_styles.css"
    click Release "https://github.com/sssungjin/velog-stats/blob/master/pages/release-notes.html"
    click Privacy "https://github.com/sssungjin/velog-stats/blob/master/privacy-policy.md"
    click Verify "https://github.com/sssungjin/velog-stats/blob/master/google4988f32cd021f0f1.html"
    click icon "https://github.com/sssungjin/velog-stats/tree/master/icon/"

    %% Styles
    classDef ui fill:#E0F7FA,stroke:#006064,color:#006064
    classDef logic fill:#E8F5E9,stroke:#1B5E20,color:#1B5E20
    classDef external fill:#ECEFF1,stroke:#455A64,color:#455A64
    classDef static fill:#FFF8E1,stroke:#F57F17,color:#F57F17
    classDef config fill:#F3E5F5,stroke:#4A148C,color:#4A148C
```
