# opencsgs/csghub architecture

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

- Interactive diagram: https://gitdiagram.com/opencsgs/csghub
- Repository: https://github.com/opencsgs/csghub

## Overview

##### Main Components Identification

a) Frontend Layer:
- Vue.js-based web application (located in /frontend)
- Multiple UI components for different features (models, datasets, spaces, etc.)
- Internationalization support (en/zh locales)

b) Backend Layer:
- Go-based server (internal/handlers)
- RESTful API endpoints
- Authentication/Authorization middleware
- Service layer for business logic

c) Storage Layer:
- Database system (pkg/database)
- S3/MinIO integration (pkg/s3)
- Git repository storage

d) External Services:
- Authentication system
- File storage service
- Git server integration

##### Component Relationships

**[Web Clients] → [Frontend Layer] → [Backend API Layer] → [Service Layer] → [Storage Layer]**
- ↘ [External Services]

##### Detailed Component Breakdown

- Admin Portal (Blue)
- User Management (Green)
- Asset Management (Yellow)
- Models
- Datasets
- Spaces
- Codes
- Community Features (Orange)

- API Handlers (Rectangles)
- Middleware (Hexagons)
- Service Layer (Rounded Rectangles)

##### Data Flow Representation

- User requests flow
- Authentication flow
- Asset management flow
- Storage operations flow

##### Integration Points

Integration with:
- S3/MinIO for asset storage
- Git server for code management
- Authentication services
- External APIs

##### Key Features to Emphasize

Create subsections for:
- LLM Asset Management
- Space Management
- User Management
- Access Control
- Data Synchronization

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        WC[Web Clients]
    end

    subgraph Frontend
        FA["Frontend Application"]:::frontend
        UI["UI Layer"]:::frontend
        I18N["Internationalization"]:::frontend

        subgraph "UI Components"
            MOD["Models UI"]:::frontend
            DAT["Datasets UI"]:::frontend
            SPC["Spaces UI"]:::frontend
            USR["User Settings UI"]:::frontend
            ADM["Admin Interface"]:::frontend
        end
    end

    subgraph Backend
        subgraph "API Layer"
            API["API Handlers"]:::backend
            AUM["Auth Middleware"]:::backend
            RTE["API Routes"]:::backend
        end

        subgraph "Service Layer"
            SVC["Core Services"]:::service
            USM["User Management"]:::service
            ASM["Asset Management"]:::service
        end
    end

    subgraph Storage
        DB[(Database)]:::storage
        S3["S3/MinIO Storage"]:::storage
        GIT["Git Repository"]:::storage
    end

    subgraph "External Services"
        AUTH["Authentication Service"]:::external
        EXT_S3["External Storage"]:::external
        EXT_GIT["Git Server"]:::external
    end

    %% Connections
    WC --> FA
    FA --> UI
    UI --> I18N
    UI --> MOD & DAT & SPC & USR & ADM

    UI --> API
    API --> AUM
    AUM --> SVC
    API --> RTE

    SVC --> USM & ASM
    USM & ASM --> DB
    ASM --> S3
    ASM --> GIT

    SVC --> AUTH
    S3 --> EXT_S3
    GIT --> EXT_GIT

    %% Styles
    classDef frontend fill:#42b883,stroke:#333,stroke-width:2px
    classDef backend fill:#1e88e5,stroke:#333,stroke-width:2px
    classDef service fill:#7e57c2,stroke:#333,stroke-width:2px
    classDef storage fill:#ff7043,stroke:#333,stroke-width:2px
    classDef external fill:#78909c,stroke:#333,stroke-width:2px

    %% Click Events
    click FA "https://github.com/OpenCSGs/csghub/tree/main/frontend/src"
    click MOD "https://github.com/OpenCSGs/csghub/tree/main/frontend/src/components/models"
    click DAT "https://github.com/OpenCSGs/csghub/tree/main/frontend/src/components/datasets"
    click SPC "https://github.com/OpenCSGs/csghub/tree/main/frontend/src/components/application_spaces"
    click USR "https://github.com/OpenCSGs/csghub/tree/main/frontend/src/components/user_settings"
    click ADM "https://github.com/OpenCSGs/csghub/tree/main/frontend/src/components/admin_next"
    click I18N "https://github.com/OpenCSGs/csghub/tree/main/frontend/src/locales"
    click API "https://github.com/OpenCSGs/csghub/tree/main/internal/handlers"
    click AUM "https://github.com/OpenCSGs/csghub/blob/main/internal/middleware/auth_middleware.go"
    click RTE "https://github.com/OpenCSGs/csghub/tree/main/internal/routes"
    click SVC "https://github.com/OpenCSGs/csghub/tree/main/internal/services"
    click USM "https://github.com/OpenCSGs/csghub/blob/main/internal/models/user.go"
    click ASM "https://github.com/OpenCSGs/csghub/tree/main/internal/handlers/render"
    click DB "https://github.com/OpenCSGs/csghub/tree/main/pkg/database"
    click S3 "https://github.com/OpenCSGs/csghub/tree/main/pkg/s3"
    click AUTH "https://github.com/OpenCSGs/csghub/tree/main/pkg/utils/jwt"
```
