# huasenjio/huasenjio-compose architecture

> Architecture diagram of the GitHub repository huasenjio/huasenjio-compose, 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/huasenjio/huasenjio-compose
- Repository: https://github.com/huasenjio/huasenjio-compose

## Overview

##### Project Type and Purpose
- This is a full‑stack, containerized web platform (“花森起始页”) composed of:
- A public “portal” front end (Vue.js SPA)
- An “admin” management front end (Vue.js SPA)
- A Node.js/Express back‑end service
- MongoDB for persistence
- Redis for caching/session/concurrency
- Nginx as a reverse proxy
- Jenkins for CI/CD
- Shell scripts for one‑click deploy & maintenance

##### File Structure Analysis
Top‐level directories reveal the system components:
- bin/             – deployment & upgrade scripts
- docker‑compose.yml – orchestrates containers
- huasen‑frontend/ – two Vue.js apps: admin & portal
- huasen‑server/   – Express app (MVC: router, controller, service, middleware, MongoDB models, plugins)
- huasen‑mongo/    – MongoDB init scripts & data volume
- huasen‑redis/    – Redis config & data
- huasen‑nginx/    – Nginx conf & static default pages
- huasen‑store/    – static assets (images, PDF, mini‑webapps)
- huasen‑lib/      – shared JS utility library
- Jenkins container defined in docker‑compose

##### Architectural Insights from README
- Layers:
- Edge: Nginx
- Presentation: portal & admin SPAs
- API: Node.js (Express)
- Data: MongoDB + Redis
- CI/CD: Jenkins
- Patterns: classic MVC on server; decoupled cache (Redis) and persistence (MongoDB); containerized micro‑services style; WebSocket channel for real‑time; scheduler for cron tasks; plugin-based middleware.

##### Diagramming the Architecture
a. Main Components (group as containers):
- Nginx Reverse Proxy Container
- Vue.js SPAs: portal app, admin app
- Express API Server Container
- MongoDB Container (with volume)
- Redis Container (with volume)
- Jenkins Container (CI/CD)
- Shell-script host (bin/*.sh) – for orchestration (outside containers)

b. Relationships & Data Flows:
1. Client browsers → HTTP(S) → Nginx
2. Nginx → static SPA assets or → API (proxy_pass to Express)
3. Portal/Admin SPAs ↔ RESTful HTTP (Axios) → Express API
4. Express API ↔ MongoDB (CRUD via Mongoose)
5. Express API ↔ Redis (ioredis plugin for caching, sessions, concurrency)
6. Express API ↔ WebSocket plugin for push updates
7. Express API ↔ Mail service (nodemailer plugin)
8. Express API ↔ Scheduler module (cron tasks)
9. Jenkins ↔ Git repo; Jenkins builds/ pushes new Docker images → docker‑compose
10. bin/*.sh scripts invoke Docker‑compose to start/stop/upgrade containers

c. Architectural Patterns & Principles:
- MVC Separation: router → controller → service → model
- Container per concern: each service in its own Docker container
- Decouple caching (Redis) & persistence (MongoDB)
- Plugin‑based extensibility in server (mail, jwt, throttle, ws)
- Scheduler for background jobs
- CI/CD pipeline with Jenkins

d. Key Technologies & Frameworks:
- Frontend: Vue.js (2.6.x), ElementUI, TailwindCSS, Axios
- Backend: Node.js (Express), Mongoose, ioredis, ws (WebSocket), nodemailer
- Data stores: MongoDB, Redis
- Orchestration: Docker & Docker‑compose
- Proxy: Nginx
- CI/CD: Jenkins

## Diagram (Mermaid)

```mermaid
graph TB
    classDef frontend fill:#cce5ff,stroke:#2a6f97
    classDef api fill:#d4edda,stroke:#2e7d32
    classDef data fill:#ffe5b4,stroke:#ff8c00
    classDef infra fill:#e2e3e5,stroke:#6c757d
    classDef host fill:#f5f5dc,stroke:#a67c00
    classDef external fill:#f0f0f0,stroke:#999
    classDef internal fill:#ffffff,stroke:#cccccc,stroke-dasharray: 2 2

    Browser["Client Browser"]:::external

    subgraph "Docker-Compose Host"
        Nginx["Nginx Reverse Proxy\n(80/443)"]:::infra
        Portal["Portal SPA"]:::frontend
        Admin["Admin SPA"]:::frontend
        Express["Express API Server\n(3000)"]:::api
        Mongo["MongoDB\n(volume)"]:::data
        Redis["Redis\n(volume)"]:::data
        Jenkins["Jenkins CI/CD"]:::infra
    end

    Mail["Mail Service (SMTP)"]:::external
    DC["docker-compose.yml"]:::infra
    Bin["Shell Scripts (bin/*.sh)"]:::host

    Browser -->|"HTTPS"| Nginx
    Nginx -->|"serves static"| Portal
    Nginx -->|"serves static"| Admin
    Nginx -->|"proxy_pass API"| Express

    Portal -->|"REST (Axios)"| Express
    Admin -->|"REST (Axios)"| Express

    Express -->|"CRUD (Mongoose)"| Mongo
    Express -->|"cache/session"| Redis
    Express -->|"SMTP"| Mail
    Express ---|"WebSocket"| Portal
    Express ---|"WebSocket"| Admin

    Express -->|"Cron Scheduler"| ScheduleNote((Scheduler))
    Express -->|"Plugins (JWT, Mail, Throttle)"| PluginNote((Plugins))

    Jenkins -->|"trigger build/deploy"| DC
    Bin -->|"invoke docker-compose"| DC

    class ScheduleNote,PluginNote internal

    click Bin "https://github.com/huasenjio/huasenjio-compose/tree/master/bin/"
    click DC "https://github.com/huasenjio/huasenjio-compose/blob/master/docker-compose.yml"
    click Nginx "https://github.com/huasenjio/huasenjio-compose/tree/master/huasen-nginx/"
    click Portal "https://github.com/huasenjio/huasenjio-compose/tree/master/huasen-frontend/portal/"
    click Admin "https://github.com/huasenjio/huasenjio-compose/tree/master/huasen-frontend/admin/"
    click Express "https://github.com/huasenjio/huasenjio-compose/blob/master/huasen-server/app.js"
    click Mongo "https://github.com/huasenjio/huasenjio-compose/tree/master/huasen-mongo/"
    click Redis "https://github.com/huasenjio/huasenjio-compose/tree/master/huasen-redis/"
```
