# ckent-sim/gofilm architecture

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

- Interactive diagram: https://gitdiagram.com/ckent-sim/gofilm
- Repository: https://github.com/ckent-sim/gofilm

## Overview

##### Project Type & Purpose
- GoFilm is a full-stack online streaming platform. The project is divided into three major parts:
- The client folder contains the Vue-based frontend.
- The server (and film/server) directories hold the backend business logic implemented using Gin.
- The film folder also includes deployment configurations (Dockerfile, docker-compose.yml, nginx configurations, Redis config) used to manage production infrastructure.
- The README highlights two primary interfaces: the public-facing website and an administrative backend for managing film resources, data collection, and scheduled updates.

##### Analyzing the File Structure
- The top-level directories (client, film, server) indicate a separation of concerns:
- “client”: Contains everything related to the Vue SPA. With files organized into assets, components, views, and routing, this clearly encapsulates the presentation/UI layer.
- “server” and “film/server”: Both contain controllers, logic, models, plugins, and routers. There are two similar backend directories, which suggests one may be dedicated to a certain deployment or evolution of the backend service.
- “film”: In addition to backend code under film/server, it includes data and configuration for nginx (acting as a reverse proxy/static file server) and Redis (used for caching) as well as Docker-related files. This indicates the deployment flow and container orchestration strategy.
- Configuration files like docker-compose.yml, Dockerfile, and nginx.conf indicate containerized deployment and a structured production stack.

a. Main Components:
- Frontend Client:
- Vue SPA (built with Vite, using ElementPlus) which handles the user-facing interface.
- Backend Services:
- API Service(s): Based on Gin providing RESTful endpoints for both public site and admin sections.
- Two backend directories (“server” and “film/server”) can be represented as a unified backend service or as separate services if they serve different stages (e.g., development vs. production deployment).
- Controllers, Logic layers, and Models are separate but collaborate closely.
- Infrastructure & Deployment:
- Nginx: Reverse proxy and static resource server as configured under film/data/nginx.
- Scheduling/Resource Crawler: Use of robfig/cron (for scheduled tasks like film updates) and gocolly for resource/spider tasks. Represent these as background worker components.
- Data storage & Cache: Indicate the use of a database (likely MySQL or similar via GORM) and a Redis instance used for caching.
- External Systems:
- Integration points may be shown where appropriate (e.g., external film sources or third-party API calls used by the spider).

b. Relationships & Interactions:
- The client communicates with the backend via API endpoints (HTTP calls).
- The backend service communicates with the database and Redis.
- The cron/spider components operate within or as part of the backend, periodically updating film data.
- Nginx serves both as a gateway for static assets (from the client build) and as a reverse proxy, directing API calls to the backend servers.
- Docker-compose indicates container-based orchestration, so these components could be shown as containerized modules.

c. Architectural Patterns and Design Principles:
- Separation of Concerns: Clearly separate frontend presentation (client) from backend API logic.
- Modularization: Use of controllers, logic, models, and plugins in the backend layers allowing for flexibility and testability.
- Use of Middleware: The backend employs middleware for CORS handling and JWT authentication.
- Microservice-like structure: Although not fully split into independent microservices, the separation of film/server and server/ might indicate evolution towards service separation or an environment split (development vs production).

d. Relevant Technologies, Frameworks, Libraries:
- Frontend: Vue, Vite, ElementPlus.
- Backend: Go with Gin, GORM for ORM, go-redis for caching, gocolly for web scraping, and robfig/cron for scheduling.
- Deployment: Docker, docker-compose, nginx.
- Additional libraries are visible within the project’s plugins (e.g., handling file management and request utilities).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Layer
    U1["User (Browser)"]:::user

    %% Deployment & Infrastructure Layer
    subgraph "Deployment & Infrastructure"
        DS["Docker Setup"]:::infra
        NG["Nginx Reverse Proxy"]:::infra
        RC["Redis Config"]:::infra
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        FE["Vue Frontend"]:::frontend
        AD["Admin Dashboard"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend Layer"
        BEP["Gin API Server (Production)"]:::backend
        BEA["Gin API Server (Alternative)"]:::backend
        CRF["Cron/Spider (Film)"]:::backend
        CRS["Cron/Spider (Server)"]:::backend
        DB["MySQL Database"]:::database
        RED["Redis Cache"]:::database
    end

    %% Connections from User to Infrastructure
    U1 -->|"request"| NG

    %% Deployment arrows (indicating containerized setup)
    DS -->|"orchestrates"| NG
    DS -->|"orchestrates"| FE
    DS -->|"orchestrates"| BEP
    DS -->|"orchestrates"| BEA

    %% Nginx routes traffic
    NG -->|"serves static"| FE
    NG -->|"routes API"| BEP
    NG -->|"routes API"| BEA

    %% Frontend internal connection
    FE -->|"accesses"| AD

    %% Backend communication with data stores
    BEP -->|"queries/updates"| DB
    BEP -->|"caches/informs"| RED
    BEA -->|"queries/updates"| DB
    BEA -->|"caches/informs"| RED

    %% Cron/Spider services update data stores
    CRF -->|"updates"| DB
    CRF -->|"updates"| RED
    CRS -->|"updates"| DB
    CRS -->|"updates"| RED

    %% Cron/Spider services interact with backend (triggers data refresh)
    CRF ---|"synchronizes"| BEP
    CRS ---|"synchronizes"| BEA

    %% Click Events
    click FE "https://github.com/ckent-sim/gofilm/tree/main/client/src"
    click AD "https://github.com/ckent-sim/gofilm/tree/main/client/src/views/manage"
    click BEP "https://github.com/ckent-sim/gofilm/tree/main/film/server"
    click BEA "https://github.com/ckent-sim/gofilm/tree/main/server"
    click CRF "https://github.com/ckent-sim/gofilm/tree/main/film/server/plugin/spider"
    click CRS "https://github.com/ckent-sim/gofilm/tree/main/server/plugin/spider"
    click DS "https://github.com/ckent-sim/gofilm/tree/main/film"
    click NG "https://github.com/ckent-sim/gofilm/tree/main/film/data/nginx"
    click RC "https://github.com/ckent-sim/gofilm/tree/main/film/data/redis"
    click DB "https://github.com/ckent-sim/gofilm/blob/main/film/server/plugin/db/mysql.go"
    click RED "https://github.com/ckent-sim/gofilm/blob/main/film/server/plugin/db/redis.go"

    %% Styles
    classDef user fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef infra fill:#FFCC80,stroke:#000,stroke-width:2px;
    classDef frontend fill:#C8E6C9,stroke:#000,stroke-width:2px;
    classDef backend fill:#FFAB91,stroke:#000,stroke-width:2px;
    classDef database fill:#FFF59D,stroke:#000,stroke-width:2px;
```
