Skip to content

micro-java 架构与请求链路

整体拓扑

text
                         contracts/openapi + schema.sql


              ┌─────────────────────────────────────────────┐
              │           gateway (:8080)                   │
              │  Spring Cloud Gateway + Resilience4j        │
              │  /api/v1/auth/**     → auth-service         │
              │  /api/v1/system/**   → system-service       │
              │  /api/v1/monitor/**  → monitor-service      │
              └──────┬──────────────┬──────────────┬──────┘
                     │              │              │
            Nacos 服务发现          │              │
                     │              │              │
         ┌───────────▼──┐  ┌────────▼────────┐  ┌──▼──────────────┐
         │ auth-service │  │ system-service   │  │ monitor-service │
         │ (:8081)      │  │ (:8082)          │  │ (:8083)         │
         │ 登录/Token   │  │ RBAC+平台+init   │  │ 日志+Quartz     │
         │ 写登录日志   │  │ Seata / MQ       │  │                 │
         └──────┬───────┘  └────────┬─────────┘  └────────┬────────┘
                └───────────────────┼─────────────────────┘

                              MySQL (:3306)

模块职责

xichen-domain

19 个 Entity、对应 Mapper、auth/system/monitor DTO。被 common 与各业务服务依赖。

xichen-common

JWT、Security、ApiResponse、OperLog AOP、CustomUserDetailsService。被三个业务服务 @Import

auth-service

  • /api/v1/auth/*/api/v1/health
  • 直连 MySQL;登录日志 写入SysLogininforService

system-service

  • /api/v1/system/* — 12 个 Controller(RBAC + 平台 + database init)
  • spring.datasource 直连 MySQL
  • UserEventPublisher(RabbitMQ/Kafka)
  • assignRoles — Seata @GlobalTransactional

详见 System

monitor-service

  • /api/v1/monitor/* — 操作/登录日志、定时任务
  • Quartz 启动加载 sys_job
  • 登录日志 只读管理(写入在 auth-service)

详见 Monitor

gateway

  • 对外 8080;不做 JWT 校验
  • Resilience4j 熔断 + GET 重试 → /fallback

前端登录时序

mermaid
sequenceDiagram
    participant F as admin 前端
    participant G as gateway :8080
    participant A as auth-service
    participant S as system-service
    participant M as monitor-service
    participant DB as MySQL

    F->>G: POST /api/v1/auth/login
    G->>A: 转发
    A->>DB: 校验用户、写 logininfor
    A-->>F: LoginResponse

    F->>G: GET /api/v1/system/users (Bearer)
    G->>S: 转发 + JWT 校验

    F->>G: GET /api/v1/monitor/operlogs (Bearer)
    G->>M: 转发 + JWT 校验

网关路由表

路由 id路径目标
auth-service/api/v1/auth/**/api/v1/healthlb://auth-service
system-service/api/v1/system/**lb://system-service
monitor-service/api/v1/monitor/**lb://monitor-service
*-swagger/auth-service/.../system-service/.../monitor-service/...对应服务 StripPrefix=1

默认端口

组件端口环境变量
gateway8080SERVER_PORT
auth-service8081SERVER_PORT
system-service8082SERVER_PORT
monitor-service8083SERVER_PORT
Nacos8848NACOS_ADDR
RabbitMQ5672RABBITMQ_HOST
Seata8091SEATA_SERVER

Monorepo 构建

  • 不纳入 Turbo build
  • xichen-domain / xichen-common 后:mvn install -DskipTests
  • 与 server-java 同步:scripts/sync-from-server-java.ps1

相关文档

Xichen Full Stack 内部文档