# peterh0323/streamer-sales architecture

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

- Interactive diagram: https://gitdiagram.com/peterh0323/streamer-sales
- Repository: https://github.com/peterh0323/streamer-sales

## Overview

##### Project Type & Purpose
- Full‑stack, microservices‑based web application for AI “sell‑product” live‑streaming.
- Frontend: Vue + Pinia + Element‑Plus SPA;
- Backend: FastAPI/Uvicorn microservices, PostgreSQL, vector store (RAG), LMDeploy inference, ASR/TTS/digital‑human modules, Agent for external queries.
- Deployed via Docker Compose as discrete containers.

##### Main Components
a. Frontend (Container)
- Vue SPA (App.vue, router, pinia stores, Element‑Plus UI)
- Communicates over HTTPS/REST to “API Gateway” (Base service)
b. Base Service / API Gateway (Container)
- FastAPI routers (users, products, streaming_room, digital_human, llm, asr, tts, etc.)
- JWT authentication, PostgreSQL ORM & migrations
- Dispatches requests to sub‑services, stores metadata in PostgreSQL
c. Microservices (each in its own container)
- LLM Service: LMDeploy + Turbomind inference (lelemiao‑7b/4bit)
- RAG Service: retrieves embeddings from Faiss/feature_store + file operations
- ASR Service: speech‑to‑text via FunASR or Whisper module
- TTS Service: GPT‑SoVITS pipeline
- Digital Human Service: MuseTalk‑based video synthesis workflow
d. Data Stores
e. External Dependencies

##### Relationships & Data Flows
- Frontend → Base API (REST over HTTPS)
- Base API ↔ PostgreSQL (CRUD)
- Base API → Microservices via HTTP (REST)
- LLM: generate sales script or answer Q&A
- RAG: retrieve relevant docs/embeddings
- ASR: convert live audio → text
- TTS: convert text → audio
- DigitalHuman: convert script + audio → video stream
- Microservices → Weights/Static Storage (load models, artifacts)
- Agent Module within Base Service calls external APIs (DeliveryTime, Weather)
- Docker Compose orchestrates multi‑container deployment and networks

##### Architectural Patterns & Principles
- Front‑end/Back‑end separation (SPA vs REST API)
- Microservices: each AI capability decoupled for independent scaling & deployment
- Stateless services behind API Gateway; state persisted in PostgreSQL & vector store
- RAG pattern: retrieval + generation
- Agent pattern: encapsulate external API calls
- Containerized deployment: Docker Compose for service orchestration

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Docker Network"
        direction TB

        subgraph "Frontend" 
            direction TB
            FEApp["Vue SPA<br/>(App.vue, router, Pinia, Element-Plus)"]:::frontend
            click FEApp "https://github.com/peterh0323/streamer-sales/blob/main/frontend/src/App.vue"
            FERouter["Router<br/>(index.ts)"]:::frontend
            click FERouter "https://github.com/peterh0323/streamer-sales/blob/main/frontend/src/router/index.ts"
            FEStore["Pinia Store<br/>(userToken.ts)"]:::frontend
            click FEStore "https://github.com/peterh0323/streamer-sales/blob/main/frontend/src/stores/userToken.ts"
            FEAPI["API Client<br/>(base.ts)"]:::frontend
            click FEAPI "https://github.com/peterh0323/streamer-sales/blob/main/frontend/src/api/base.ts"
        end

        subgraph "Base API / Gateway"
            direction TB
            APIServer["FastAPI + Uvicorn<br/>(base_server.py)"]:::backend
            click APIServer "https://github.com/peterh0323/streamer-sales/blob/main/server/base/base_server.py"
            subgraph "Routers & Modules"
                direction TB
                Routers["FastAPI Routers<br/>(users, products, streaming_room, llm, asr, tts, digital_human)"]:::backend
                click Routers "https://github.com/peterh0323/streamer-sales/tree/main/server/base/routers/"
                AgentMod["Agent Module<br/>(agent_worker.py)"]:::backend
                click AgentMod "https://github.com/peterh0323/streamer-sales/blob/main/server/base/modules/agent/agent_worker.py"
                DeliveryQuery["DeliveryTime Query<br/>(delivery_time_query.py)"]:::backend
                click DeliveryQuery "https://github.com/peterh0323/streamer-sales/blob/main/server/base/modules/agent/delivery_time_query.py"
                RAGMod["RAG Module<br/>(rag_worker.py)"]:::backend
                click RAGMod "https://github.com/peterh0323/streamer-sales/blob/main/server/base/modules/rag/rag_worker.py"
            end
            DBQueue["Queue Thread<br/>(queue_thread.py)"]:::backend
            click DBQueue "https://github.com/peterh0323/streamer-sales/blob/main/server/base/queue_thread.py"
            Utils["Utils & Migrations<br/>(utils.py)"]:::backend
            click Utils "https://github.com/peterh0323/streamer-sales/blob/main/server/base/utils.py"
        end

        subgraph "AI Microservices"
            direction TB
            subgraph "LLM Service"
                direction TB
                LLM["LMDeploy + Turbomind<br/>(7b/4bit)"]:::microservice
                click LLM "https://github.com/peterh0323/streamer-sales/tree/main/server/llm/"
            end
            subgraph "RAG Service"
                direction TB
                FeatureStore["Feature Store<br/>(feature_store.py)"]:::microservice
                click FeatureStore "https://github.com/peterh0323/streamer-sales/blob/main/server/base/modules/rag/feature_store.py"
                Retriever["Retriever<br/>(retriever.py)"]:::microservice
                click Retriever "https://github.com/peterh0323/streamer-sales/blob/main/server/base/modules/rag/retriever.py"
                FileOps["File Ops<br/>(file_operation.py)"]:::microservice
                click FileOps "https://github.com/peterh0323/streamer-sales/blob/main/server/base/modules/rag/file_operation.py"
            end
            subgraph "ASR Service"
                direction TB
                ASRServer["ASR Server<br/>(asr_server.py)"]:::microservice
                click ASRServer "https://github.com/peterh0323/streamer-sales/blob/main/server/asr/asr_server.py"
                ASRWorker["ASR Worker<br/>(asr_worker.py)"]:::microservice
                click ASRWorker "https://github.com/peterh0323/streamer-sales/blob/main/server/asr/asr_worker.py"
            end
            subgraph "TTS Service"
                direction TB
                TTSServer["TTS Server<br/>(tts_server.py)"]:::microservice
                click TTSServer "https://github.com/peterh0323/streamer-sales/blob/main/server/tts/tts_server.py"
                TTSWorker["TTS Worker<br/>(tts_worker.py)"]:::microservice
                click TTSWorker "https://github.com/peterh0323/streamer-sales/blob/main/server/tts/modules/tts_worker.py"
            end
            subgraph "DigitalHuman Service"
                direction TB
                DHSrv["DigitalHuman Server<br/>(digital_human_server.py)"]:::microservice
                click DHSrv "https://github.com/peterh0323/streamer-sales/blob/main/server/digital_human/digital_human_server.py"
                DHWorker["DigitalHuman Worker<br/>(digital_human_worker.py)"]:::microservice
                click DHWorker "https://github.com/peterh0323/streamer-sales/blob/main/server/digital_human/modules/digital_human_worker.py"
            end
        end

        subgraph "Data Stores"
            direction TB
            Postgres["PostgreSQL<br/>(ORM & Migrations)"]:::datastore
            click Postgres "https://github.com/peterh0323/streamer-sales/blob/main/server/base/database/init_db.py"
            VectorStore["FAISS/Redis Vector Store"]:::datastore
            Storage["Weights & Static Files"]:::storage
        end
    end

    subgraph "External APIs"
        direction TB
        DeliveryAPI["DeliveryTime API"]:::external
        WeatherAPI["Weather API"]:::external
    end

    %% Connections
    FEApp -->|"HTTPS/REST"| APIServer
    FERouter --> FEApp
    FEStore --> FEApp
    FEAPI --> FEApp

    APIServer -->|"CRUD (HTTP)"| Postgres
    APIServer -->|"REST"| LLM
    APIServer -->|"REST"| FeatureStore
    APIServer -->|"REST"| ASRServer
    APIServer -->|"REST"| TTSServer
    APIServer -->|"REST"| DHSrv

    LLM -->|"loads models"| Storage
    FeatureStore -->|"load embeddings"| VectorStore
    FileOps --> Storage
    ASRWorker --> LLM
    TTSWorker --> LLM
    DHWorker --> storage

    AgentMod -->|"Agent logic"| DeliveryAPI
    AgentMod -->|"Agent logic"| WeatherAPI

    %% Class definitions
    classDef frontend fill:#cbeafe,stroke:#1e3a8a,color:#1e3a8a;
    classDef backend fill:#dcfce7,stroke:#166534,color:#166534;
    classDef microservice fill:#fde68a,stroke:#92400e,color:#92400e;
    classDef datastore fill:#e5e7eb,stroke:#374151,color:#374151;
    classDef storage fill:#f3f4f6,stroke:#9ca3af,color:#9ca3af;
    classDef external fill:#dbeafe,stroke:#1e40af,color:#1e40af;
```
