Skip to content

后端技术栈 ​

Molan Cloud 后端基于 Molan Core,采用成熟的企业级技术栈,支持单体/微服务双模部署。

核心技术 ​

Spring Boot ​

  • 版本:3.5.6
  • 特性:
    • 自动配置
    • 内嵌容器
    • 生产级监控
    • 快速开发

MyBatis Plus ​

  • 版本:3.5.12
  • 特性:
    • 强大的 CRUD 操作
    • 代码生成器
    • 分页插件
    • 多租户支持

Spring Cloud(微服务模式) ​

  • 版本:2025.0.0
  • 组件:
    • OpenFeign:声明式 HTTP 客户端
    • Gateway:API 网关(WebFlux)
    • LoadBalancer:客户端负载均衡

Spring AI ​

  • 版本:1.1.2
  • 特性:
    • AI 能力集成
    • 多模型支持

Lucene ​

  • 版本:9.12.3
  • 特性:
    • 全文检索
    • 知识库搜索

中间件 ​

  • Redis:6.0+

    • 缓存
    • 分布式锁
    • 字典数据
  • RabbitMQ:3.12+(微服务模式)

    • 服务间异步通信
    • 事件总线
    • 消息队列
  • Nacos:2.3+(微服务模式)

    • 服务注册与发现
    • 配置中心
    • 动态配置

Molan Core(backend/core) ​

同仓单模块核心库,按包提供能力:

  • util / spring / web / db:工具与 Spring/MyBatis 约定
  • rpc / event:双模 RPC 与事件总线
  • lock:Memory / Redisson 锁(默认随 molandev.mode 推断)
  • file:local / s3(配置 molandev.file.type 即启用)
  • encrypt / datasource:加解密与动态数据源

项目结构 ​

backend/
├── core/                  # 双模驱动核心库
├── apis/                  # API 接口定义
├── base-service/          # 基础服务
├── knowledge-service/     # 知识库服务
├── xiuxian-service/       # AI 修仙服务
├── gateway-service/       # 微服务网关
└── standalone-service/    # 单体模式启动入口

部署脚本与中间件在仓库根目录 scripts/(docker / sql / cloud / standalone)。

核心依赖 ​

xml
<dependencies>
    <!-- Spring Boot -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>3.5.6</version>
    </dependency>

    <!-- MyBatis Plus -->
    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
        <version>3.5.12</version>
    </dependency>

    <!-- Spring Cloud(微服务模式) -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

    <!-- Spring AI -->
    <dependency>
        <groupId>org.springframework.ai</groupId>
        <artifactId>spring-ai-bom</artifactId>
        <version>1.1.2</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>

    <!-- Lucene 全文检索 -->
    <dependency>
        <groupId>org.apache.lucene</groupId>
        <artifactId>lucene-core</artifactId>
        <version>9.12.3</version>
    </dependency>

    <!-- Molan Core:双模内核(同仓模块) -->
    <dependency>
        <groupId>com.molandev</groupId>
        <artifactId>core</artifactId>
    </dependency>
</dependencies>

双模部署 ​

单体模式 ​

yaml
# application-local.yml
molandev:
  mode: standalone        # 单体模式
  lock:
    type: memory          # 使用内存锁
  security:
    mode: LOCAL           # 本地认证模式
  datasource:
    sys:
      url: jdbc:postgresql://localhost:5432/molandev_base
      username: postgres
      password: 123456
  • 特点:
    • 本地方法调用
    • 多数据源事务统一
    • 简单部署
    • 快速开发

微服务模式 ​

yaml
# application.yml
molandev:
  mode: microservice         # 微服务模式
  security:
    mode: CLOUD           # 云端认证模式

spring:
  cloud:
    nacos:
      discovery:
        server-addr: localhost:8848
  • 特点:
    • HTTP 远程调用
    • 服务独立部署
    • 弹性扩展
    • 故障隔离

核心特性 ​

1. 双模部署 ​

详见 双模部署

2. 认证授权 ​

详见 认证授权

3. 字典管理 ​

详见 字典管理

4. 操作日志 ​

详见 操作日志

5. 定时任务 ​

详见 定时任务

6. 文件管理 ​

详见 文件管理

7. 消息服务 ​

详见 消息服务

8. 事件驱动 ​

详见 事件驱动

开发规范 ​

包结构 ​

com.molandev.{module}
├── controller/          # 控制器
├── service/             # 服务类(直接继承 ServiceImpl)
├── mapper/              # MyBatis Mapper
├── entity/              # 实体类
└── dto/                 # 数据传输对象

命名规范 ​

  • 实体类:SysUserEntity
  • 服务类:SysUserService
  • Mapper:SysUserMapper
  • Controller:SysUserController

接口规范 ​

  • 使用 RESTful 风格
  • 统一返回 JsonResult<T> 结果
  • 统一异常处理
  • 统一参数校验

代码注释 ​

  • 类注释:说明类的功能
  • 方法注释:说明参数、返回值、异常
  • 业务注释:说明复杂业务逻辑

下一步 ​