# wangzmgit/alnitak architecture

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

- Interactive diagram: https://gitdiagram.com/wangzmgit/alnitak
- Repository: https://github.com/wangzmgit/alnitak

## Overview

##### Main Components
a. Front-end Clients:
- Web Client (nuxt-based UI)
- Admin Client (management interface for content/users)
- Mobile Client (mobile-tailored client)
b. Back-end Server:
- Core Go Server (located in the “server” directory) that handles API endpoints, business logic, and request routing.
- API Layer (inside server/internal/api/v1) that aggregates endpoints for features like video, article/专栏, comments, likes, collections, etc.
- Middleware (authentication, CORS, request logging, operation logging) that secures and intercepts HTTP calls.
- Services & Domain Logic:
– Services for handling functionalities including transcoding, caching, messaging (real-time, WebSocket), and user management.
– Domain models, Data Transfer Objects (DTOs) and Value Objects (VOs) in server/internal/domain for business logic.
- Utilities and Helpers:
– Packages handling logging, JWT, MySQL, OSS (integrating Aliyun or MinIO), Redis, and WebSocket (server/pkg/ws).
c. Databases and External Storage:
- MySQL: Managed via configuration files (server/internal/config/mysql.go; sql/structure.sql) and used as the relational database.
- Redis: Used for caching and session management (server/internal/config/redis.go; server/pkg/redis).
- Object Storage Service (OSS): For file and video/media uploads which rely on libraries inside server/pkg/oss (support for Aliyun and MinIO).
d. Additional Components:
- Docker Infrastructure: docker-compose.yml and Dockerfiles for server and clients that indicate containerized deployment.
- Third-party Integrations: External libraries like wplayer-next (弹幕播放器) and the Go-based puzzle sliding captcha (jigsaw).
- Cron Jobs: In server/internal/cron for scheduled jobs (popular video, click count aggregations, etc.) indicating background processing.
- WebSocket Service: For live messaging and online user counts.

##### Relationships and Interactions
- File uploads and Media Handling: Illustrate OSS (or local disk storage in “data/upload” and “server/upload”) as a storage component interfacing with the server.

##### Architectural Patterns & Design Principles
- Modularization (the Go code is organized into modules such as internal/api, service, domain, config, middleware, etc.). This separation of concerns shows layered architecture (route → middleware → service → repository/data access).
- Separation of Frontend and Backend: The different front-end directories (web/admin-client, web/mobile-client, web/web-client) clearly illustrate a decoupled architecture communicating with a centralized API server.
- Use of JWT for Authentication and Casbin for RBAC indicates security best practices.
- Containerization with Docker suggests deployment in clustered or microservice-like environments even if the Go server is more monolithic in structure.

##### Technologies, Frameworks & Libraries
- Front-end: Nuxt (Vue-based) for web and mobile UI.
- Back-end: Go with a structured project layout. Look for “server/internal/” to highlight controllers, services, and domain models.
- Database: MySQL (with schema defined in sql/structure.sql).
- Caching: Redis.
- OSS Integration: Aliyun/MinIO for media file handling.
- WebSocket: For real-time features and notifications.
- Docker: Deployment and container orchestration.
- Additional dependencies like wplayer and jigsaw are significant in terms of external packages.

##### Detailed Suggestions for the Principal Software Engineer
- Dependencies between modules – for example, the service layer depends on repository/data access, Redis caching, and OSS integration.
- Use nested blocks or containers to show the internal organization of the monolithic Go server if needed.
- Explicitly mention that the front-end clients are built with Nuxt/Vue and that the server code uses Go’s standard packages and an organized internal structure to support real-time communication and video functionalities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        FClient["Web Client (Nuxt UI)"]:::client
        AdminClient["Admin Client (Management UI)"]:::client
        MobileClient["Mobile Client (Mobile UI)"]:::client
    end

    %% API/Backend Layer
    subgraph "API/Backend Layer"
        direction TB
        GoServer["Go Core Server"]:::backend
        subgraph "Internal Modules"
            direction TB
            APILayer["API Layer (v1)"]:::api
            Middleware["Middleware (Auth,CORS,Logging)"]:::middleware
            ServiceLayer["Service Layer (Business Logic)"]:::service
            DomainModels["Domain Models/DTOs/VOs"]:::domain
            subgraph "Utilities & Helpers"
                direction TB
                JWTNode["JWT Helper"]:::util_child
                WSNode["WebSocket Service"]:::util_child
                OSSNode["OSS Integration"]:::util_child
                OtherUtil["Other Utilities"]:::util_child
            end
            CronJobs["Cron Jobs (Scheduled)"]:::cron
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        MySQL["MySQL Database"]:::database
        Redis["Redis Cache"]:::database
        OSS_Storage["OSS / File Storage"]:::storage
    end

    %% Deployment / External Services
    subgraph "Deployment & External"
        Docker["Docker Infrastructure"]:::docker
        ExtIntegration["Third-party Integrations (wplayer & jigsaw)"]:::external
    end

    %% Connections: Clients to Backend
    FClient -->|"REST/WebSocket"| GoServer
    AdminClient -->|"REST"| GoServer
    MobileClient -->|"REST"| GoServer

    %% Connections: Internal flow in Backend
    GoServer --> APILayer
    APILayer --> Middleware
    Middleware --> ServiceLayer
    ServiceLayer --> DomainModels
    ServiceLayer --> JWTNode
    ServiceLayer --> WSNode
    ServiceLayer --> OSSNode
    ServiceLayer --> OtherUtil
    ServiceLayer --> CronJobs
    ServiceLayer -->|"DB Access"| MySQL
    ServiceLayer -->|"Cache Query"| Redis
    ServiceLayer -->|"Media Upload"| OSS_Storage

    %% External and Deployment Links
    Docker --> GoServer
    ExtIntegration --- GoServer

    %% Click Events for Component Mapping
    click FClient "https://github.com/wangzmgit/alnitak/tree/master/web/web-client"
    click AdminClient "https://github.com/wangzmgit/alnitak/tree/master/web/admin-client"
    click MobileClient "https://github.com/wangzmgit/alnitak/tree/master/web/mobile-client"
    click GoServer "https://github.com/wangzmgit/alnitak/tree/master/server"
    click APILayer "https://github.com/wangzmgit/alnitak/tree/master/server/internal/api/v1"
    click Middleware "https://github.com/wangzmgit/alnitak/tree/master/server/internal/middleware"
    click ServiceLayer "https://github.com/wangzmgit/alnitak/tree/master/server/internal/service"
    click DomainModels "https://github.com/wangzmgit/alnitak/tree/master/server/internal/domain"
    click JWTNode "https://github.com/wangzmgit/alnitak/blob/master/server/pkg/jwt/jwt.go"
    click WSNode "https://github.com/wangzmgit/alnitak/blob/master/server/pkg/ws/ws.go"
    click OSSNode "https://github.com/wangzmgit/alnitak/tree/master/server/pkg/oss"
    click OtherUtil "https://github.com/wangzmgit/alnitak/tree/master/server/utils"
    click MySQL "https://github.com/wangzmgit/alnitak/blob/master/server/internal/config/mysql.go"
    click Redis "https://github.com/wangzmgit/alnitak/blob/master/server/internal/config/redis.go"
    click CronJobs "https://github.com/wangzmgit/alnitak/tree/master/server/internal/cron"
    click Docker "https://github.com/wangzmgit/alnitak/blob/master/docker-compose.yml"
    click ExtIntegration "https://github.com/wangzmgit/alnitak/blob/master/server/pkg/jigsaw/jigsaw.go"

    %% Styles
    classDef client fill:#fffae6,stroke:#f3c623,stroke-width:2px;
    classDef backend fill:#e6f7ff,stroke:#1f8ef1,stroke-width:2px;
    classDef api fill:#d5f5e3,stroke:#28b463,stroke-width:2px;
    classDef middleware fill:#fdebd0,stroke:#e67e22,stroke-width:2px;
    classDef service fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;
    classDef domain fill:#fadbd8,stroke:#e74c3c,stroke-width:2px;
    classDef util_child fill:#e8daef,stroke:#8e44ad,stroke-width:2px;
    classDef cron fill:#d6eaf8,stroke:#3498db,stroke-width:2px;
    classDef database fill:#ebedef,stroke:#616a6b,stroke-width:2px,stroke-dasharray: 5 5;
    classDef storage fill:#fef9e7,stroke:#f39c12,stroke-width:2px,stroke-dasharray: 5 5;
    classDef docker fill:#defde0,stroke:#27ae60,stroke-width:2px;
    classDef external fill:#f5eef8,stroke:#9b59b6,stroke-width:2px;
```
