# larchliu/stargram architecture

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

- Interactive diagram: https://gitdiagram.com/larchliu/stargram
- Repository: https://github.com/larchliu/stargram

## Overview

##### Project type and purpose
- This is a full-stack, monorepo application called “Stargram” that lets users capture and manage starred pages across the web.
- It comprises three main deliverables:
- A Chrome extension (app/extension/chrome) for capturing and interacting with starred content.
- A Nuxt3-based web front-end and API server (server/nuxt3) for configuration, storage, and bot integrations.
- A shared core library (packages/core) plus auxiliary packages (packages/plugins, packages/webHub) that provide data processing, LLM integration, storage adapters, and route generation.

##### File-structure overview and architectural patterns
- Top-level orchestration (pnpm, turbo):
- pnpm-workspace.yaml, turbo.json define the multi-package workspace.
- app/extension/chrome:
- Chrome extension built with Vue 3 + Vite: background scripts, content scripts, pop-up and settings UIs.
- packages/core:
- Business logic (chain, LLM wrappers for OpenAI/GoogleAI, storage adapters for Postgres/Chroma/Supabase/Notion, web scraping).
- Provides a programmatic API consumed by both the extension and server side.
- packages/plugins/generate-routes and packages/webHub:
- Unplugin/Vite/Nuxt plugins to auto-generate routes or website pages based on metadata.
- server/nuxt3:
- Nuxt3 full-stack app with pages, components, composables, service-worker for PWA.
- server/api folder implements serverless endpoints (Slack, Telegram, Stargram chain, webcard generation).
- Integration points with external platforms (Slack Bot, Telegram Bot, Notion).

##### README insights
- Title “Stargram” and tagline “Manage all your Starred Pages” confirm capture + management use case.
- Deployment on Railway hints at cloud deployment with environment variables.

a. Main components
- Chrome Extension (UI + background)
- Nuxt3 Server (SSR Frontend + Serverless API)
- Core Library (LLM, Storage, Web scraping)
- Auxiliary Plugins (Route generation, WebHub)
- External Services (OpenAI/GoogleAI, Postgres/Supabase/Chroma/Notion, Slack API, Telegram API)
b. Interactions and data flow
1. User stars a page → Extension content script captures metadata and sends API call to Nuxt3 server.
2. Nuxt3 API routes invoke core library to process text (LLM), save to selected storage adapter.
3. Server pushes updates via service-worker or webhooks to clients or bots.
4. Slack/Telegram bots call serverless endpoints (via Webhook) → core library processes commands and returns results.
5. The web dashboard (Nuxt3 pages) reads from storage via server API.
c. Architectural patterns and principles
- Monorepo with workspace management (pnpm, Turborepo)
- Shared domain logic in packages/core (DRY).
- Plugin-based extensibility for routes and site generators.
- Serverless functions for each API route (Nuxt3 server/api).
- PWA and service-worker for offline/notification support.
d. Key technologies
- Vue 3 + Vite (extension + server)
- Nuxt3 (SSR + serverless)
- TypeScript monorepo (pnpm + turbo)
- OpenAI/GoogleAI SDKs
- Storage adapters: Postgres, Supabase, Chroma, Notion
- Slack & Telegram Bot frameworks

##### Final advice
- Be very detailed: break down server/api into logical groups (stargram, slack, telegram, webcard).
- Storage adapters and LLM flows inside the core module.

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Chrome Extension Layer
  subgraph "Chrome Extension" 
    direction TB
    BG["background script"]:::api
    CS["contentScript"]:::api
    PP["popup UI"]:::ui
    ST["settings UI"]:::ui
    MF["manifest.json"]:::library
  end

  %% Server Layer
  subgraph "Nuxt3 Server" 
    direction TB
    subgraph "Frontend (SSR + PWA)"
      direction TB
      PAGES["pages"]:::ui
      APP["app.vue"]:::ui
      CONF["nuxt.config.ts"]:::ui
      SW["service-worker"]:::api
    end
    subgraph "Serverless API" 
      direction TB
      SWI["/api/save-web-info"]:::api
      subgraph "stargram API" 
        direction TB
        STAR["[appid]/*.ts"]:::api
      end
      subgraph "Slack Bot API" 
        direction TB
        SLACK["[appid]/*.ts"]:::api
      end
      subgraph "Telegram Bot API" 
        direction TB
        TELE["[token]/*.ts"]:::api
      end
    end
  end

  %% Core Library Layer
  subgraph "Core Library" 
    direction TB
    subgraph "Chain"
      direction TB
      SWI_CORE["saveWebInfo.ts"]:::library
      QA["qa.ts"]:::library
    end
    subgraph "LLM Wrappers"
      direction TB
      OAI["openai"]:::library
      GAI["googleai"]:::library
    end
    subgraph "Storage Adapters"
      direction TB
      PG["Postgres"]:::library
      SB["Supabase"]:::library
      CH["Chroma"]:::library
      NT["Notion"]:::library
    end
    WEBINFO["webInfo"]:::library
    WEBCARD["webCard"]:::library
  end

  %% Plugin Layer
  subgraph "Plugins"
    direction TB
    subgraph "Generate Routes"
      direction TB
      GR_IDX["index.ts"]:::library
      GR_NUXT["nuxt.ts"]:::library
      GR_VITE["vite.ts"]:::library
      GR_CORE["unplugin.ts"]:::library
    end
    subgraph "WebHub"
      direction TB
      WH_RA["routes-auto-generate.ts"]:::library
      WH_EX["article-extractor"]:::library
      WH_COMMON["common router"]:::library
      WH_SITE["website routers"]:::library
    end
  end

  %% External Services
  subgraph "External Services"
    direction TB
    EX_LLM["OpenAI/GoogleAI"]:::external
    EX_DB["Postgres/Supabase/Chroma/Notion"]:::external
    SLACK_API["Slack API"]:::external
    TELE_API["Telegram API"]:::external
  end

  %% Connections
  CS -->|HTTP POST| SWI
  BG -->|messaging| CS
  PP -->|UI Interaction| SWI
  SWI -->|calls| SWI_CORE
  SWI_CORE -->|uses| OAI
  SWI_CORE -->|uses| GAI
  SWI_CORE -->|writes| PG
  SWI_CORE -->|writes| SB
  SWI_CORE -->|writes| CH
  SWI_CORE -->|writes| NT
  SLACK_API -->|Webhook| SLACK
  TELE_API -->|Webhook| TELE
  SLACK -->|calls| QA
  TELE -->|calls| QA

  %% Plugin usage
  GR_IDX -->|extends| PAGES
  WH_RA -->|build-time| PAGES

  %% Click events - Chrome Extension
  click BG "https://github.com/larchliu/stargram/blob/main/app/extension/chrome/src/background/index.ts"
  click CS "https://github.com/larchliu/stargram/blob/main/app/extension/chrome/src/contentScript/index.ts"
  click PP "https://github.com/larchliu/stargram/blob/main/app/extension/chrome/src/popup/App.vue"
  click ST "https://github.com/larchliu/stargram/blob/main/app/extension/chrome/src/settings/App.vue"
  click MF "https://github.com/larchliu/stargram/blob/main/app/extension/chrome/src/manifest.json"

  %% Click events - Server
  click PAGES "https://github.com/larchliu/stargram/tree/main/server/nuxt3/pages"
  click APP "https://github.com/larchliu/stargram/blob/main/server/nuxt3/app.vue"
  click CONF "https://github.com/larchliu/stargram/blob/main/server/nuxt3/nuxt.config.ts"
  click SWI "https://github.com/larchliu/stargram/blob/main/server/nuxt3/server/api/save-web-info.ts"
  click STAR "https://github.com/larchliu/stargram/blob/main/server/nuxt3/server/api/stargram/[appid]/*.ts"
  click SLACK "https://github.com/larchliu/stargram/blob/main/server/nuxt3/server/api/slack/[appid]/*.ts"
  click TELE "https://github.com/larchliu/stargram/blob/main/server/nuxt3/server/api/telegram/[token]/*.ts"
  click SW "https://github.com/larchliu/stargram/blob/main/server/nuxt3/service-worker/sw.ts"

  %% Click events - Core Library
  click SWI_CORE "https://github.com/larchliu/stargram/blob/main/packages/core/src/chain/saveWebInfo.ts"
  click QA "https://github.com/larchliu/stargram/blob/main/packages/core/src/chain/qa.ts"
  click OAI "https://github.com/larchliu/stargram/tree/main/packages/core/src/llm/openai"
  click GAI "https://github.com/larchliu/stargram/tree/main/packages/core/src/llm/googleai"
  click PG "https://github.com/larchliu/stargram/blob/main/packages/core/src/storage/postgres/index.ts"
  click SB "https://github.com/larchliu/stargram/blob/main/packages/core/src/storage/supabase/index.ts"
  click CH "https://github.com/larchliu/stargram/blob/main/packages/core/src/storage/chroma/index.ts"
  click NT "https://github.com/larchliu/stargram/blob/main/packages/core/src/storage/notion/index.ts"
  click WEBINFO "https://github.com/larchliu/stargram/blob/main/packages/core/src/webInfo/index.ts"
  click WEBCARD "https://github.com/larchliu/stargram/blob/main/packages/core/src/webCard/index.ts"

  %% Click events - Plugins
  click GR_IDX "https://github.com/larchliu/stargram/blob/main/packages/plugins/generate-routes/src/index.ts"
  click GR_NUXT "https://github.com/larchliu/stargram/blob/main/packages/plugins/generate-routes/src/nuxt.ts"
  click GR_VITE "https://github.com/larchliu/stargram/blob/main/packages/plugins/generate-routes/src/vite.ts"
  click GR_CORE "https://github.com/larchliu/stargram/blob/main/packages/plugins/generate-routes/src/core/unplugin.ts"
  click WH_RA "https://github.com/larchliu/stargram/blob/main/packages/webHub/src/routes-auto-generate.ts"
  click WH_EX "https://github.com/larchliu/stargram/blob/main/packages/webHub/src/utils/article-extractor/index.ts"
  click WH_COMMON "https://github.com/larchliu/stargram/blob/main/packages/webHub/src/website/common/router.ts"
  click WH_SITE "https://github.com/larchliu/stargram/blob/main/packages/webHub/src/website/github.com/router.ts"
  click WH_SITE "https://github.com/larchliu/stargram/blob/main/packages/webHub/src/website/twitter.com/router.ts"

  %% Styles
  classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
  classDef api fill:#DFFFE0,stroke:#28a745,color:#28a745;
  classDef library fill:#FFF5BA,stroke:#E6A800,color:#E6A800;
  classDef external fill:#F0F0F0,stroke:#888888,color:#888888;
```
