smart-cloud:基于 Spring Cloud 生态的微服务开发框架项目

一站式 Spring Cloud 微服务脚手架 —— 让微服务开发像搭积木一样简单。支持服务合并部署与拆分部署、接口加解密签名、日志数据 脱敏、接口数据mock、接口文档自动生成、请求幂等校验、接口日志&&sql日志切面打印、分表分库分布式事务、国际化语言、接口监控及服务监控等

Branch11Tags8
FilesLast commitLast update
9 months ago
1 year ago
1 year ago
4 months ago
8 months ago
1 year ago
8 months ago
8 months ago
8 months ago
1 year ago
1 year ago
6 months ago
6 months ago
7 years ago
4 months ago
4 months ago
4 years ago
4 years ago
8 months ago

☁️ Smart Cloud

A One-Stop Spring Cloud Microservices Scaffolding — Build Microservices Like Lego

Out-of-the-Box · Merge & Split · Security-Enhanced · Full-Stack Observability


build codecov license Maven Central GitHub stars EN doc CN doc


🌟 Why Smart Cloud?

Pain Point Smart Cloud Solution
Splitting microservices too early is costly; too late hurts performance Merge & Split — merge services by business domain in early stage to save costs; split them when traffic grows to handle high QPS. Merged deployment uses in-process calls; split deployment uses Feign RPC. Switch with one line in pom.xml
API docs are costly to maintain Auto-generate YAPI docs — upload to YAPI Server with one click via IDEA plugin
Frontend-backend integration is slow Built-in Mock Engine — auto-generate responses by type/rules
Sensitive data leak risks Full-stack desensitization — log masking + config encryption + field encryption (multi-key)
Production issues discovered late Real-time monitoring & alerts — slow APIs / error APIs / offline services, instant WeCom notifications
Infrastructure onboarding is tedious 20+ Starter components — assemble capabilities like Lego blocks

📦 Example project: smart-cloud-examples — up and running in 5 minutes


✨ Key Features

🚀 Developer Productivity

  • Auto API Documentation — IDEA YAPI plugin one-click upload to YAPI Server
  • Mock Data Engine — random data by return type, custom mock rules supported
  • Code Generation — auto-generate boilerplate code (VO/DTO/Mapper, etc.)
  • API Versioning — manage multiple API versions effortlessly

🔒 Security Enhancement

  • API Encryption & Signature — auto encrypt/decrypt requests/responses with tamper-proof signature
  • Config Encryption — encrypt configuration files via Jasypt
  • Field-Level Encryption — auto encrypt/decrypt privacy fields with multi-key support
  • Log Desensitization — annotation-driven, auto-mask sensitive data in log output

🏗️ Architecture Flexibility

  • Merge & Split Services — merge by business domain to save costs early on; split for high traffic later. Merged (in-process) ⇄ split (RPC), flexible switching
  • Multi-DataSource & Sharding — MyBatis-Plus + Dynamic-DataSource + ShardingSphere
  • Rate Limiting & Circuit Breaking — Sentinel integration with dynamic refresh via config center
  • MQ Retry on Failure — custom annotation for delayed queue re-consumption

📊 Full Observability

  • Service Monitoring — Spring Boot Admin (status/GC/threads/memory/CPU/Tomcat)
  • API Monitoring — slow API / error API real-time monitoring + consecutive failure circuit breaking
  • WeCom Alerts — instant notification for service offline / health check failure, supports @mention
  • Full-Stack Logging — Web/Feign/Method/MyBatis/MQ logs, configurable levels
  • Request Tracing — HTTP request input/output params & timing

🧪 Testing Friendly

  • Standalone Testing — disable Nacos/Sentinel, mock RPC interfaces, develop independently
  • Integration Test Suite — H2 database + Embedded Redis + RabbitMQ Mock
  • Unit Test Utilities — Mockito + Podam data mocking, improve coverage

🚀 Quick Start

1. Add Parent Dependency

<parent>
    <groupId>io.github.smart-cloud</groupId>
    <artifactId>smart-cloud</artifactId>
    <version>${latest-version}</version>
</parent>

2. Add Starters as Needed

<!-- Web Service -->
<dependency>
    <groupId>io.github.smart-cloud</groupId>
    <artifactId>smart-cloud-starter-web</artifactId>
</dependency>

<!-- MyBatis-Plus ORM -->
<dependency>
    <groupId>io.github.smart-cloud</groupId>
    <artifactId>smart-cloud-starter-mybatis-plus</artifactId>
</dependency>

<!-- Redis Cache & Distributed Lock -->
<dependency>
    <groupId>io.github.smart-cloud</groupId>
    <artifactId>smart-cloud-starter-redis</artifactId>
</dependency>

3. Full Working Example

👉 Head to smart-cloud-examples for a complete, ready-to-run example project.


🧩 Module Structure

smart-cloud
├── smart-api-core                          # API permissions, encryption, signature annotations & user context
│   ├── smart-api-annotation                #   API permissions, encryption, signature annotations
│   └── smart-user-context                  #   User context
├── smart-code-generate                     # Code generation
├── smart-common-pojo                       # Common objects (VO, DTO, BO, DO)
├── smart-common-web                        # Web module common processing
├── smart-constants                         # Constants
├── smart-exception                         # Exception module
├── smart-design-pattern-utility            # Design pattern utilities
├── smart-utility                           # Common utilities
├── smart-test                              # Testing utilities
│   ├── smart-cloud-starter-test            #   Test base
│   ├── smart-cloud-starter-test-mock-rabbitmq  # RabbitMQ Mock
│   ├── smart-cloud-starter-test-mock-redis     # Redis Mock
│   └── smart-cloud-test-core               #   Unit / integration test utilities
└── smart-cloud-starter                     # 🧱 Starter Components
    ├── smart-cloud-starter-api-version     #   API versioning
    ├── smart-cloud-starter-configure       #   Framework config properties
    ├── smart-cloud-starter-core            #   Core (annotations, exceptions, request/response)
    ├── smart-cloud-starter-elasticsearch-dynamic-datasource  # ES dynamic datasource
    ├── smart-cloud-starter-feign           #   Feign (merge/split, aspects)
    ├── smart-cloud-starter-global-id       #   Distributed ID generator
    ├── smart-cloud-starter-job             #   Scheduled tasks (XXL-Job)
    ├── smart-cloud-starter-locale          #   Internationalization
    ├── smart-cloud-starter-log4j2          #   Log4j2 logging (with desensitization)
    ├── smart-cloud-starter-log-mask        #   Log desensitization
    ├── smart-cloud-starter-logback         #   Logback logging (with desensitization)
    ├── smart-cloud-starter-method-log      #   Method aspect logging
    ├── smart-cloud-starter-mock            #   Mock (utilities, strategies, interceptors)
    ├── smart-cloud-starter-mp-shardingjdbc #   MyBatis-Plus + sharding
    ├── smart-cloud-starter-mybatis-plus    #   MyBatis-Plus + multi-datasource
    ├── smart-cloud-starter-rabbitmq        #   RabbitMQ (auto-retry on failure)
    ├── smart-cloud-starter-rate-limit      #   Rate limiting (Sentinel)
    ├── smart-cloud-starter-redis           #   Redis + distributed lock
    ├── smart-cloud-starter-static-discovery    # Static service discovery
    ├── smart-cloud-starter-trace-debug     #   Request tracing (I/O + timing)
    ├── smart-cloud-starter-web             #   Web (logging aspect, exception handling, validation)
    └── smart-cloud-starter-monitor         #   📊 Monitoring
        ├── smart-cloud-monitor-common      #     Common monitoring code
        ├── smart-cloud-starter-monitor-api #     Slow API / error API monitoring
        └── smart-cloud-starter-monitor-admin   # Spring Boot Admin + WeCom alerts

🛠️ Tech Stack

Category Technology Purpose
Framework Spring Boot Scaffolding
Spring Cloud Gateway API Gateway
Nacos Service Registry & Config Center
Service Calls OpenFeign Declarative RPC
Sentinel Rate Limiting & Circuit Breaking
Data Layer MyBatis + MyBatis-Plus ORM
Dynamic-DataSource Multi-DataSource
ShardingSphere Sharding
Redis Cache & Distributed Lock
Messaging RabbitMQ Async Messaging
Monitoring Spring Boot Admin Service Monitoring
Sleuth Distributed Tracing
Tools XXL-Job Distributed Task Scheduling
EasyExcel Excel Import/Export
FastDFS Distributed File Storage
Jasypt Config Encryption
Lombok Code Simplification
Testing Mockito + Podam Unit Tests & Data Mock
H2 DB Integration Tests
Embedded Redis Redis Integration Tests
RabbitMQ Mock MQ Integration Tests
Docs YAPI + IDEA Plugin Auto API Documentation
Code Gen FreeMarker Template Engine

🔄 Service Merge & Split

Smart Cloud's most distinctive feature: services can be merged or split at will.

In the early stage of a new project, multiple services can be merged by business domain to save infrastructure costs. As the business grows with increasing users and higher QPS, services can be split for independent deployment and elastic scaling.

  • Merged deployment: add service dependencies in pom.xml — calls automatically switch to in-process
  • Split deployment: each service runs independently — communicates via Feign RPC
  • Auto switching: via SmartFeignClient annotation + condition check — no code changes needed

Key Problems Solved in Merged Deployment

Problem Solution
Bean name conflicts Custom bean name generation rules
RPC interface vs implementation conflicts SmartFeignClient conditional annotation — uses in-process calls when merged
YAML config auto-loading @YamlScan annotation + EnvironmentPostProcessor SPI
Startup class annotation conflicts SmartSpringCloudApplicationCondition conditional annotation
Maven packaging issues Maven Profiles to control dependency scope

📊 Monitoring & Alerts

Monitor service status via Spring Boot Admin, extend Actuator endpoints to track API health, and send WeCom notifications.

  • Service offline: check GitLab job history; if no tag jobs in the last 30 minutes (configurable), send notification and @mention
  • API errors: sliding window failure rate calculation; health check fails when threshold exceeded
  • Consecutive failure circuit breaking: trigger alert on consecutive API failures
Service Offline Health Check Failed Service Online

🔒 Log Desensitization

1. Custom desensitization tags — auto-trigger masking when logging
2. Custom Jackson serializer — dedicated serializer for log output
3. Reflect @MaskRule annotations — mask strings per annotation rules

📄 API Documentation

Upload to YAPI Server with one click via IDEA YAPI Upload Plugin.

Overview Detail

📖 Error Codes

Module Code Description
smart-constants 200 Success
101 Validation failed
102 Data not found
103 Data already exists
400 Signature error
401 Unauthorized access
404 Request URL error
408 Request timeout
409 Duplicate submission
412 Incomplete parameters
413 Attribute not configured
415 Request method not supported
416 Request type not supported
417 Failed to acquire lock
418 Upload file size exceeds limit
419 Session expired, please log in again
420 Request JSON parse error
421 Rate limit exceeded
500 Server error
501 Failed to get Request
502 Failed to get Response
503 RPC request failed
smart-cloud-starter-web 2001 Validation target cannot be null
smart-cloud-starter-elasticsearch-dynamic-datasource 3001 ES DS key not found
3002 ES data source not found
3003 ES dynamic datasource properties not configured

🤝 Contributing

Star ⭐, Fork 🍴, and PR 🔧 are welcome!

  1. Fork this repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

⭐ Star History

Star History Chart


📜 License

This project is licensed under the Apache License 2.0.

Introduction

一站式 Spring Cloud 微服务脚手架 —— 让微服务开发像搭积木一样简单。支持服务合并部署与拆分部署、接口加解密签名、日志数据 脱敏、接口数据mock、接口文档自动生成、请求幂等校验、接口日志&&sql日志切面打印、分表分库分布式事务、国际化语言、接口监控及服务监控等

Customize your domain
21688169Visit GitHub