# rajgm/backend-superteam_vietnam_ai architecture

> Architecture diagram of the GitHub repository rajgm/backend-superteam_vietnam_ai, 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/rajgm/backend-superteam_vietnam_ai
- Repository: https://github.com/rajgm/backend-superteam_vietnam_ai

## Overview

##### Project type and purpose
- From the file tree and README we see this is a Node.js-based backend service (“backend-Superteam_Vietnam_AI”) that:
- Exposes HTTP endpoints via Express (index.js + routes/)
- Integrates with Firebase (lib/firebaseConfig.js, lib/firebaseUtil.js) for data storage
- Talks to Telegram (lib/telegram.js) and processes tweets (lib/processTweet.js)
- Has a dedicated “LLM” folder with its own Dockerfile, suggesting a separate microservice for large-language-model calls
- Is containerized via Docker and docker-compose

##### File structure
- Top-level files:
- Dockerfile + docker-compose.yml → container orchestration
- index.js → Express-based API server entrypoint
- .env.example → environment configuration
- README.md → minimal project title
- folders:
- routes/ (chat.js, draft_tweet.js, upload.js) → Express route handlers
- lib/ (firebaseConfig.js, firebaseUtil.js, helperFunction.js, processTweet.js, query.js, telegram.js) → core business logic & external integrations
- LLM/ (Dockerfile, startup.sh) → standalone LLM microservice
- docs/ → documentation artifacts
- test.js, test.json → local test harness

##### Key architectural insights from README and structure
- No built-in frontend; this is pure backend/microservices
- Heavy reliance on Firebase as primary DB / storage
- External APIs: Telegram Bot API, Twitter API, (likely) OpenAI or similar inside the LLM service
- Two major containers/services:
1) API Service
2) LLM Worker Service

##### Main components & their interactions
a. Clients/Entry Points
- Telegram users (via Bot)
- Potential HTTP clients (e.g., web UI or Postman for draft_tweet/upload)
b. API Service (Express)
- Routes: /chat, /draft_tweet, /upload
- Reads WRITE/READ from Firebase (Firestore or Realtime DB)
- Calls LLM microservice over HTTP (or gRPC) for heavy NLP tasks
- Uses lib/telegram.js to relay responses back to users
c. LLM Service
- Runs in its own container (LLM/Dockerfile + startup.sh)
- Hosts model calls (OpenAI or local model)
- Responds to API Service requests
d. Firebase
- Data storage (user sessions, drafts, uploaded files)
- Could include both Firestore and Cloud Storage
e. External APIs
- Telegram Bot API
- Twitter API

##### Architectural patterns & design principles
- Microservice decomposition (API vs. LLM worker)
- 12-factor app: env vars, config, stateless services
- Single responsibility per module (routes for routing, lib for logic)
- Containerization via Docker + Docker-Compose for local orchestration

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "Docker-Compose"
    direction TB
    dockerFile["Dockerfile"]:::internal
    compose["docker-compose.yml"]:::internal

    subgraph "API Service (Express)"
      direction TB
      idx["index.js"]:::internal

      subgraph "Routes"
        direction TB
        chat["routes/chat.js"]:::internal
        draft["routes/draft_tweet.js"]:::internal
        upload["routes/upload.js"]:::internal
      end

      subgraph "Libs"
        direction TB
        fbConfig["lib/firebaseConfig.js"]:::internal
        fbUtil["lib/firebaseUtil.js"]:::internal
        telegram["lib/telegram.js"]:::internal
        processTweet["lib/processTweet.js"]:::internal
        helper["lib/helperFunction.js"]:::internal
        query["lib/query.js"]:::internal
      end
    end

    subgraph "LLM Service"
      direction TB
      llmDocker["LLM/Dockerfile"]:::internal
      llmStart["LLM/startup.sh"]:::internal
    end
  end

  fb["Firestore & Storage"]:::datastore
  Telegram["Telegram Bot API"]:::external
  Twitter["Twitter API"]:::external

  subgraph "Test Harness"
    direction TB
    testJs["test.js"]:::internal
    testJson["test.json"]:::internal
  end

  subgraph "Docs"
    direction TB
    teamMd["docs/team.md"]:::internal
    testMd["docs/test.md"]:::internal
    teamJson["docs/team.json"]:::internal
  end

  Telegram -->|HTTPS| idx
  Twitter -->|HTTPS| idx
  idx -->|Firebase SDK| fb
  idx -->|HTTP/REST| llmStart
  llmStart -->|HTTP Response| idx
  testJs -.->|invokes| idx
  testJson -.->|data| testJs

  classDef internal fill:#D6E4FF,stroke:#4C6EF5,color:#081A51;
  classDef datastore fill:#D9F7BE,stroke:#37B24D,color:#1B4332;
  classDef external fill:#FFE7BA,stroke:#F08C00,color:#663E00;

  click idx "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/index.js"
  click chat "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/routes/chat.js"
  click draft "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/routes/draft_tweet.js"
  click upload "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/routes/upload.js"
  click fbConfig "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/lib/firebaseConfig.js"
  click fbUtil "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/lib/firebaseUtil.js"
  click telegram "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/lib/telegram.js"
  click processTweet "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/lib/processTweet.js"
  click helper "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/lib/helperFunction.js"
  click query "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/lib/query.js"
  click llmDocker "https://github.com/rajgm/backend-superteam_vietnam_ai/tree/main/LLM/Dockerfile"
  click llmStart "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/LLM/startup.sh"
  click dockerFile "https://github.com/rajgm/backend-superteam_vietnam_ai/tree/main/Dockerfile"
  click compose "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/docker-compose.yml"
  click testJs "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/test.js"
  click testJson "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/test.json"
  click teamMd "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/docs/team.md"
  click testMd "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/docs/test.md"
  click teamJson "https://github.com/rajgm/backend-superteam_vietnam_ai/blob/main/docs/team.json"
```
