# jiangrui1994/cloudsaver architecture

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

- Interactive diagram: https://gitdiagram.com/jiangrui1994/cloudsaver
- Repository: https://github.com/jiangrui1994/cloudsaver

## Overview

##### Project Type and Purpose
- CloudSaver is a full-stack web application (monorepo managed by pnpm) combining a Vue 3 + TypeScript frontend with an Express + TypeScript backend and SQLite3 for persistence.
- It provides users with multi-source resource search and one-click transfers to various cloud storage services (115, Quark, Tianyi, 123yun), plus Douban integration and multi-user support.

##### File-Structure Analysis
- Top-level:
- Dockerfile, docker-entrypoint.sh, nginx.conf → containerization & reverse proxy
- pnpm-workspace.yaml, package.json → monorepo root, shared scripts
- backend/: Express app in src/ with subfolders for config, controllers, services, models, middleware, routes, utils, core, types → classic layered architecture (MVC‐ish + service layer)
- frontend/: Vite + Vue 3 app in src/, organized by api/, components/, views/ (pc & mobile), router/, stores/ (Pinia), styles/, utils/, assets/ → responsive multi-platform UI
- docs/, .github/: documentation and CI/CD workflows (docker build/test)

##### README Insights
- Confirms technology stack (Vue 3, Pinia, Element Plus, Vant, Express, SQLite3)
- Describes features: multi-source search, cloud transfer, Douban ranking, multi-user & role-based auth, responsive design
- Offers deployment options: local dev, Docker single container, Docker Compose

##### Main Components
a. Client
- Browser (PC / Mobile) → interacts via HTTP(S)
b. CDN / Reverse Proxy
- Nginx container (serves static assets, proxies API calls to Express)
c. Frontend
- Vue 3 + Vite dev server (dev mode) or built static files served by Nginx in production
- Pinia store, Vue Router (PC & mobile routes), UI libraries
d. Backend
- Express server (app.ts)
- Controllers (handle HTTP requests) → Services (business logic, cloud API wrappers) → Models (TypeORM or SQLite3 queries via DatabaseService)
- Middleware (auth, CORS, rate limiting, error handler, request logger)
- Core modules (ApiResponse, types)
e. Database
- SQLite3 file accessed via DatabaseService
f. External Services
- Cloud115 API, Quark API, Tianyi, 123yun (via Cloud115Service, QuarkService, etc.)
- Douban API (DoubanService)
- Optional Telegram integration (for channel configs)
g. Persistence & Config
- /app/data (SQLite DB file), /app/config (.env) mounted as Docker volumes

##### Relationships & Data Flow
- Browser → (HTTP GET/POST) → Nginx
- Nginx → serves static JS/CSS or proxies `/api/*` → Express
- Express middleware processes → Route → Controller → Service → (External API calls or SQLite operations)
- Service returns data → Controller → ApiResponse → JSON → Browser
- For cloud-transfer: Service orchestrates requests to third-party cloud APIs, returns status to client
- Auth flows: login/register → JWT issued → subsequent requests validated by auth middleware

##### Architectural Patterns & Principles
- Layered architecture (presentation → controller → service → data)
- Dependency injection via inversify.js (inversify.config.ts)
- Centralized error handling and request logging middleware
- Separation of concerns: API integrations encapsulated in dedicated services
- Responsive UI using same codebase with platform-specific routes & components

##### Must-Haves
- Component names and roles
- Notes on technologies at each component (e.g., “Pinia, Vue Router”, “Express, inversify.js”, “SQLite3”)
- Docker containers and volume mounts if illustrating deployment

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        BrowserPC["PC Browser"]:::client
        BrowserMobile["Mobile Browser"]:::client
    end

    %% Reverse Proxy Layer
    subgraph "CDN / Reverse Proxy"
        direction TB
        Nginx["Nginx (serves static & proxies API)"]:::proxy
    end

    %% Frontend Layer
    subgraph "Frontend (Vue 3 + Vite)" 
        direction TB
        MainTS["main.ts"]:::frontend
        AppVue["App.vue"]:::frontend
        Router["Vue Router"]:::frontend
        Store["Pinia Store"]:::frontend
        APIWrappers["API Wrappers"]:::frontend
        Components["Components"]:::frontend
        Views["Views (PC/Mobile)"]:::frontend
        UtilsStyles["Utils & Styles"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend API (Express + TypeScript)"
        direction TB
        subgraph "HTTP Layer"
            direction TB
            Middleware["Middleware"]:::backend
            Routes["Routes (/api/*)"]:::backend
            Controllers["Controllers"]:::backend
        end
        subgraph "Business Logic"
            direction TB
            Services["Services"]:::backend
        end
        subgraph "Data Layer"
            direction TB
            Models["Models"]:::backend
            DatabaseService["DatabaseService"]:::backend
        end
        CoreUtils["Core/Utils"]:::backend
    end

    %% Database
    Database["SQLite3 Database"]:::database

    %% External Services
    subgraph "External Services"
        direction TB
        Cloud115["Cloud115 API"]:::external
        Quark["Quark API"]:::external
        Tianyi["Tianyi API"]:::external
        Yun123["123yun API"]:::external
        Douban["Douban API"]:::external
        Telegram["Telegram Integration"]:::external
    end

    %% CI/CD & Monorepo
    subgraph "Monorepo & CI/CD"
        direction TB
        PNPM["pnpm-workspace.yaml"]:::ci
        PackageJSON["package.json"]:::ci
        GHWorkflows["GitHub Actions"]:::ci
    end

    %% Connections
    BrowserPC -->|"HTTP(S)"| Nginx
    BrowserMobile -->|"HTTP(S)"| Nginx

    Nginx -->|"serves static"| AppVue
    Nginx -->|"proxies /api"| Routes

    AppVue -->|uses| Router
    AppVue -->|uses| Store
    AppVue -->|calls| APIWrappers
    APIWrappers -->|HTTP calls| Routes

    Router --> Views
    AppVue --> Components
    AppVue --> UtilsStyles

    Routes --> Controllers
    Controllers --> Services
    Services --> DatabaseService
    Services --> Cloud115
    Services --> Quark
    Services --> Tianyi
    Services --> Yun123
    Services --> Douban
    Services --> Telegram
    DatabaseService --> Database
    Controllers --> CoreUtils

    %% CI/CD flows
    PNPM -->|defines| Frontend
    PNPM -->|defines| BackendAPI[Backend API]
    PackageJSON -->|scripts| Frontend
    GHWorkflows -->|build/test| DockerImage["Docker Image"]

    %% Click Events - Reverse Proxy
    click Nginx "https://github.com/jiangrui1994/cloudsaver/blob/main/nginx.conf"
    click Nginx "https://github.com/jiangrui1994/cloudsaver/blob/main/docker-entrypoint.sh"
    click Nginx "https://github.com/jiangrui1994/cloudsaver/tree/main/Dockerfile"

    %% Click Events - Frontend
    click MainTS "https://github.com/jiangrui1994/cloudsaver/blob/main/frontend/src/main.ts"
    click AppVue "https://github.com/jiangrui1994/cloudsaver/blob/main/frontend/src/App.vue"
    click Router "https://github.com/jiangrui1994/cloudsaver/blob/main/frontend/src/router/index.ts"
    click Router "https://github.com/jiangrui1994/cloudsaver/blob/main/frontend/src/router/pc-routes.ts"
    click Router "https://github.com/jiangrui1994/cloudsaver/blob/main/frontend/src/router/mobile-routes.ts"
    click Store "https://github.com/jiangrui1994/cloudsaver/tree/main/frontend/src/stores"
    click APIWrappers "https://github.com/jiangrui1994/cloudsaver/tree/main/frontend/src/api"
    click Components "https://github.com/jiangrui1994/cloudsaver/tree/main/frontend/src/components"
    click Views "https://github.com/jiangrui1994/cloudsaver/tree/main/frontend/src/views"
    click UtilsStyles "https://github.com/jiangrui1994/cloudsaver/tree/main/frontend/src/utils"

    %% Click Events - Backend
    click BackendAPI "https://github.com/jiangrui1994/cloudsaver/blob/main/backend/src/app.ts"
    click BackendAPI "https://github.com/jiangrui1994/cloudsaver/blob/main/backend/src/inversify.config.ts"
    click Routes "https://github.com/jiangrui1994/cloudsaver/blob/main/backend/src/routes/api.ts"
    click Controllers "https://github.com/jiangrui1994/cloudsaver/tree/main/backend/src/controllers"
    click Middleware "https://github.com/jiangrui1994/cloudsaver/tree/main/backend/src/middleware"
    click Services "https://github.com/jiangrui1994/cloudsaver/tree/main/backend/src/services"
    click Models "https://github.com/jiangrui1994/cloudsaver/tree/main/backend/src/models"
    click DatabaseService "https://github.com/jiangrui1994/cloudsaver/blob/main/backend/src/services/DatabaseService.ts"
    click CoreUtils "https://github.com/jiangrui1994/cloudsaver/blob/main/backend/src/core/ApiResponse.ts"
    click CoreUtils "https://github.com/jiangrui1994/cloudsaver/blob/main/backend/src/utils/response.ts"
    click CoreUtils "https://github.com/jiangrui1994/cloudsaver/blob/main/backend/src/utils/handleError.ts"

    %% Click Events - CI/CD & Config
    click PNPM "https://github.com/jiangrui1994/cloudsaver/blob/main/pnpm-workspace.yaml"
    click PackageJSON "https://github.com/jiangrui1994/cloudsaver/blob/main/package.json"
    click GHWorkflows "https://github.com/jiangrui1994/cloudsaver/blob/main/.github/workflows/docker-build-test.yml"
    click GHWorkflows "https://github.com/jiangrui1994/cloudsaver/blob/main/.github/workflows/docker-image.yml"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#1E90FF,color:#000
    classDef proxy fill:#F0F0F0,stroke:#A0A0A0,color:#000
    classDef frontend fill:#E6F7E6,stroke:#00A000,color:#000
    classDef backend fill:#FFE6CC,stroke:#FF8C00,color:#000
    classDef database fill:#E5E5FF,stroke:#7F7FFF,color:#000
    classDef external fill:#FFF0F5,stroke:#FF69B4,color:#000
    classDef ci fill:#F5F5F5,stroke:#808080,color:#000
```
