微服务中的DDD logo

微服务中的DDD

Organization
microwind
微服务中的DDD

将DDD战略设计应用于微服务架构,限界上下文指导服务拆分,领域事件实现服务间通信。

Overview

Publishermicrowind
Repositoryai-skills
Skill name微服务中的DDD
Stars
93
Forks
25
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by microwind on GitHub. Read the source before you install it.

Installation

Install the 微服务中的DDD AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/microwind/ai-skills/tree/main/domain-driven-design/ddd-in-microservices
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/microwind/ai-skills.git /tmp/ai-skills
mkdir -p .claude/skills
cp -r /tmp/ai-skills/domain-driven-design/ddd-in-microservices .claude/skills/microwind-ddd
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable 微服务中的DDD in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads 微服务中的DDD on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so 微服务中的DDD is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

微服务中的 DDD (DDD in Microservices)

概述

DDD 的战略设计天然适合微服务架构:一个限界上下文 = 一个微服务。

┌──────────┐  事件  ┌──────────┐  API  ┌──────────┐
│ 订单服务  │──────→│ 库存服务  │←─────│ 商品服务  │
│ Order BC │       │ Stock BC │      │Catalog BC│
│          │       │          │      │          │
│ 独立DB   │       │ 独立DB   │      │ 独立DB   │
└──────────┘       └──────────┘      └──────────┘
      │ 事件
      ▼
┌──────────┐       ┌──────────┐
│ 支付服务  │       │ 通知服务  │
│Payment BC│       │Notify BC │
└──────────┘       └──────────┘

服务拆分原则

✅ 按限界上下文拆分(推荐)
- 每个服务有独立的领域模型
- 每个服务有独立的数据库
- 服务边界 = 上下文边界 = 团队边界

❌ 按技术层拆分(不推荐)
- 用户服务、数据库服务、消息服务
- 一个业务变更需要改多个服务

从单体到微服务

java
// 单体中的模块边界 → 未来的微服务边界

// module: order(未来的订单服务)
package com.shop.order;
public class OrderService { }
public interface OrderRepository { }  // 仓储接口
public class OrderPlacedEvent { }     // 领域事件

// module: inventory(未来的库存服务)
package com.shop.inventory;
public class InventoryService { }
public interface StockRepository { }

// 模块间通过接口通信,而非直接调用
// 迁移为微服务时,接口变为 API 调用

服务间通信

同步:API 调用(通过 ACL)

java
// 订单服务调用库存服务
public class InventoryClient implements InventoryPort {
    private final RestTemplate rest;

    @Override
    public boolean checkStock(String sku, int quantity) {
        StockResponse response = rest.getForObject(
            "http://inventory-service/api/stock/{sku}", StockResponse.class, sku);
        return response.getAvailable() >= quantity;
    }
}

异步:领域事件(推荐)

python
# 订单服务发布事件
class OrderService:
    def place_order(self, order):
        order.place()
        self.repo.save(order)
        self.message_broker.publish("order.placed", {
            "order_id": order.id,
            "items": [{"sku": i.sku, "qty": i.qty} for i in order.items]
        })

# 库存服务订阅事件
class InventoryEventHandler:
    def on_order_placed(self, event):
        for item in event["items"]:
            self.stock_service.reserve(item["sku"], item["qty"])

数据一致性

策略说明适用场景
事件驱动发布事件,订阅方最终一致大多数场景
Saga 模式编排/协同补偿事务跨服务事务
同步调用API 直接调用强一致性要求

微服务 DDD 检查清单

□ 每个服务对应一个限界上下文
□ 每个服务有独立的数据库(Database per Service)
□ 服务间不共享数据库表
□ 服务间通过 API 或事件通信,不直接访问对方数据
□ 每个服务有自己的领域模型,不共享领域对象
□ 使用防腐层隔离外部服务的模型
□ 分布式事务用 Saga 模式处理

与其他DDD概念的关系

概念关系
限界上下文一个上下文 = 一个微服务
上下文映射指导服务间的集成模式
领域事件服务间异步通信的主要方式
Saga模式解决跨服务的分布式事务
六边形架构每个微服务内部用六边形架构

总结

核心:限界上下文指导服务拆分,领域事件驱动服务通信,每个服务独立数据库。

实践:先在单体中划清模块边界(限界上下文),再按需拆分为微服务。

Frequently asked questions

What does the 微服务中的DDD AI skill do?

将DDD战略设计应用于微服务架构,限界上下文指导服务拆分,领域事件实现服务间通信。

Why use 微服务中的DDD on TypingMind?

Because you install it once and use it with any model. 微服务中的DDD is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install 微服务中的DDD in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/microwind/ai-skills/tree/main/domain-driven-design/ddd-in-microservices. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use 微服务中的DDD?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with 微服务中的DDD?

As many as you like. As long as a model supports skills, you can use 微服务中的DDD with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the 微服务中的DDD AI skill free?

It is published on GitHub by microwind. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇