# iggzq/ahut_forum architecture

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

- Interactive diagram: https://gitdiagram.com/iggzq/ahut_forum
- Repository: https://github.com/iggzq/ahut_forum

## Overview

##### Project Type and Purpose
- This is a full-stack, distributed microservices campus forum application (“桃李山屋”).
- Frontend: Vue3 SPA (UserWeb) served via Nginx.
- Backend: Spring Boot 3 + Spring Cloud microservices (user_mod, article_mod, chat_room, search_mod), plus a shared/common library.
- Data stores: MySQL (users, articles, comments, likes), Redis (sessions/cache), Elasticsearch (search index).
- Real-time chat: WebFlux WebSocket.

##### File Structure Highlights
- Top-level: Dockerfile, .github workflows, root pom.xml (multi-module Maven).
- UserWeb/: Vue3 frontend with Nginx config, CSS assets, router/store, env files for dev/prod/test.
- user_mod/: Spring Boot user service (MyBatis, Sa-Token auth, Redis).
- article_mod/: Article service (controllers, services, mappers, Feign clients to user_mod & search_mod, Redis config).
- chat_room/: WebFlux WebSocket chat service.
- search_mod/: Elasticsearch-backed search service (document model, repository, Feign endpoint for article_mod).
- common/: Shared entities & result wrappers.
- sqls/: DDL scripts for MySQL schemas.

##### Core Components
a. Frontend Layer
- Vue3 SPA (UserWeb) deployed behind Nginx (serving static assets + reverse proxy).
b. API Layer (could be an API Gateway or Nginx routing)
- Routes HTTP/REST calls from SPA to microservices.
c. Microservices
- User Service (user_mod): user registration, login, profile, auth via Sa-Token + Redis.
- Article Service (article_mod): CRUD articles/comments/likes, Feign→User Service for user info, Feign→Search Service to index articles.
- Chat Service (chat_room): real-time chat over WebFlux WebSocket.
- Search Service (search_mod): indexes article documents in Elasticsearch, exposes search REST endpoints, Feign→Article Service for sync.
- Common Library: shared DTOs/entities used by all services.
d. Data Stores
- MySQL instance(s): separate schemas or databases per service (users, articles, comments, likes).
- Redis cluster: session storage, caching, Sa-Token session store.
- Elasticsearch cluster: article search index.
e. External / DevOps
- Docker containers for each service & frontend.
- CI/CD via GitHub Actions (docker-publish.yml).
- Configuration profiles: application-dev/prod/test YAMLs.

##### Interactions & Data Flows
1. UserWeb → HTTP/REST → API Gateway/Nginx → appropriate service endpoint.
2. Article Service → Feign → User Service (to fetch author info).
3. Article Service → Feign → Search Service (to create/update ArticleDocument in Elasticsearch).
4. Search Service ↔ Elasticsearch (index & query).
5. All services ↔ MySQL (via MyBatis mappers & XML).
6. All services ↔ Redis (session, cache).
7. UserWeb ↔ WebSocket → Chat Service (for real-time chat rooms).

##### Architectural Patterns & Design Principles
- Microservices: each bounded context in its own module & DB.
- Shared library for common cross-cutting models (common/).
- API Gateway (or Nginx reverse proxy) for routing and CORS.
- Service-to-service calls via Spring Cloud OpenFeign.
- Eventual consistency between Article Service and Search Service (via synchronous Feign).
- Real-time comms with WebFlux WebSocket in a separate service.
- Configuration & profiles for different environments.
- Containerization: Docker for each module, orchestrated via CI/CD.

##### Diagramming Conventions
- Use clear, descriptive labels on each node (e.g., “Article Service (SpringBoot+MyBatis)”).
- Frontend (blue)
- API Gateway (orange)
- Microservices (green shades)
- Datastores (red)
- Search (purple)
- Rectangles for services and frontend
- Parallelograms for API Gateway/Nginx

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        SPA["Vue3 SPA (UserWeb)"]:::frontend
        NGINX["Nginx Reverse Proxy"]:::gateway
    end

    %% Backend Services
    subgraph "Backend Services"
        direction TB
        USER["User Service<br/>(SpringBoot3, Sa-Token, MyBatis)"]:::service
        ARTICLE["Article Service<br/>(SpringBoot3, MyBatis)"]:::service2
        CHAT["Chat Service<br/>(WebFlux WebSocket)"]:::service
        SEARCH["Search Service<br/>(Elasticsearch)"]:::search
    end

    %% Data Stores
    subgraph "Data Stores"
        direction TB
        MySQL["MySQL<br/>(Users, Articles, Comments, Likes)"]:::db
        Redis["Redis<br/>(Sessions, Cache)"]:::cache
        ES["Elasticsearch<br/>(Article Index)"]:::es
    end

    %% Interactions
    SPA -->|"HTTP/REST"| NGINX
    NGINX -->|"REST"| USER
    NGINX -->|"REST"| ARTICLE
    NGINX -->|"REST"| SEARCH
    SPA -->|"WebSocket"| CHAT
    USER -->|"MyBatis"| MySQL
    USER -->|"Session/Cache"| Redis
    ARTICLE -->|"MyBatis"| MySQL
    ARTICLE -->|"Cache"| Redis
    ARTICLE ---|"Feign:UserInfo"| USER
    ARTICLE ---|"Feign:IndexArticle"| SEARCH
    SEARCH -->|"Elasticsearch API"| ES
    SEARCH ---|"Feign:FetchArticles"| ARTICLE
    CHAT -->|"WebSocket Sessions"| Redis

    %% Click Events
    click SPA "https://github.com/iggzq/ahut_forum/tree/main/UserWeb/forum/src/"
    click NGINX "https://github.com/iggzq/ahut_forum/blob/main/UserWeb/forum/nginx.conf"
    click USER "https://github.com/iggzq/ahut_forum/tree/main/user_mod/"
    click ARTICLE "https://github.com/iggzq/ahut_forum/tree/main/article_mod/"
    click CHAT "https://github.com/iggzq/ahut_forum/tree/main/chat_room/"
    click SEARCH "https://github.com/iggzq/ahut_forum/tree/main/search_mod/"

    %% Styles
    classDef frontend fill:#D0E6FF,stroke:#0366d6,color:#0366d6;
    classDef gateway fill:#FFE5B4,stroke:#E69500,color:#E69500;
    classDef service fill:#E6FFE6,stroke:#33A533,color:#2E8B57;
    classDef service2 fill:#CCFFCC,stroke:#2E8B57,color:#2E8B57;
    classDef search fill:#F0E6FF,stroke:#800080,color:#800080;
    classDef db fill:#FFE6E6,stroke:#CC0000,color:#CC0000;
    classDef cache fill:#FFE6E6,stroke:#CC0000,color:#CC0000;
    classDef es fill:#FFE6E6,stroke:#CC0000,color:#CC0000;
```
