模块化原则 logo

模块化原则

Organization
microwind
模块化原则

将系统分解为独立、可替换的模块,每个模块高内聚低耦合,可独立开发、测试和部署。

Overview

Publishermicrowind
Repositoryai-skills
Skill name模块化原则
Stars
93
Forks
25
Bundled files
Instructions only
LicenseMIT
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 模块化原则 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/design-principles/modularity-principle
  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/design-principles/modularity-principle .claude/skills/microwind-46
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable 模块化原则 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 模块化原则 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 模块化原则 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.

模块化原则 (Modularity Principle)

概述

模块化是管理复杂性的核心手段:将系统分解为独立的模块,每个模块封装一组相关功能,通过明确的接口与外部交互。

核心指标:

  • 高内聚:模块内部元素紧密相关
  • 低耦合:模块之间依赖最小化
  • 可替换:模块可以独立替换而不影响其他模块

好的模块 vs 差的模块

java
// ❌ 低内聚高耦合:工具类
public class Utils {
    public static String formatDate(Date d) { /* ... */ }
    public static double calculateTax(double amount) { /* ... */ }
    public static void sendEmail(String to, String body) { /* ... */ }
    public static byte[] compressImage(byte[] data) { /* ... */ }
    // 完全不相关的功能放在一起
}

// ✅ 高内聚低耦合:按领域划分模块
// pricing 模块
public class PricingService {
    public double calculateSubtotal(List<Item> items) { /* ... */ }
    public double applyDiscount(double amount, Discount discount) { /* ... */ }
    public double calculateTax(double amount, TaxRegion region) { /* ... */ }
}

// notification 模块
public class NotificationService {
    public void sendEmail(String to, EmailTemplate template) { /* ... */ }
    public void sendSMS(String phone, String message) { /* ... */ }
}

模块边界设计

项目结构示例:

✅ 按功能/领域划分
src/
├── order/              # 订单模块
│   ├── OrderService.java
│   ├── OrderRepository.java
│   └── Order.java
├── payment/            # 支付模块
│   ├── PaymentService.java
│   └── PaymentGateway.java
├── shipping/           # 物流模块
│   ├── ShippingService.java
│   └── ShippingCalculator.java
└── notification/       # 通知模块
    ├── NotificationService.java
    └── EmailTemplate.java

❌ 按技术层划分(低内聚)
src/
├── controllers/        # 所有控制器混在一起
├── services/           # 所有服务混在一起
├── repositories/       # 所有仓储混在一起
└── models/             # 所有模型混在一起

模块间通信

python
# ✅ 通过接口通信,不直接依赖实现
from abc import ABC, abstractmethod

# 支付模块定义接口
class PaymentGateway(ABC):
    @abstractmethod
    def charge(self, amount: float, method: str) -> str: pass

# 订单模块通过接口使用支付
class OrderService:
    def __init__(self, payment: PaymentGateway):
        self.payment = payment

    def complete_order(self, order):
        tx_id = self.payment.charge(order.total, order.payment_method)
        order.confirm(tx_id)

# 模块间通过事件解耦
class EventBus:
    def publish(self, event: str, data: dict): pass

class OrderService:
    def __init__(self, event_bus: EventBus):
        self.event_bus = event_bus

    def complete_order(self, order):
        order.confirm()
        self.event_bus.publish("order.completed", {"order_id": order.id})
        # 通知模块、物流模块各自订阅处理

内聚度量

内聚类型程度说明
功能内聚最高 ✅所有元素完成同一功能
顺序内聚高一个元素的输出是另一个的输入
通信内聚中操作同一数据集
时间内聚低只是同时执行(如初始化)
逻辑内聚很低逻辑相似但功能不同
偶然内聚最低 ❌无关元素放在一起(Utils类)

耦合度量

耦合类型程度说明
消息耦合最低 ✅通过消息/事件通信
数据耦合低只传递简单数据
接口耦合中通过接口交互
控制耦合高传递控制标志影响行为
内容耦合最高 ❌直接访问内部数据

最佳实践

  1. 一个模块一个职责域 - 按业务能力划分,不按技术层划分
  2. 明确公开接口 - 只暴露必要的 API,隐藏实现细节
  3. 依赖接口不依赖实现 - 模块间通过抽象通信
  4. 独立可测试 - 每个模块可以独立运行单元测试

与其他原则的关系

原则关系
SRP模块级别的单一职责
封装模块封装内部实现
关注点分离每个模块处理一个关注点

总结

模块化核心:高内聚、低耦合、明确边界。

实践要点:

  • 按业务领域而非技术层划分模块
  • 模块通过接口或事件通信
  • 追求功能内聚,避免偶然内聚
  • 模块可独立开发、测试、部署

Frequently asked questions

What does the 模块化原则 AI skill do?

将系统分解为独立、可替换的模块,每个模块高内聚低耦合,可独立开发、测试和部署。

Why use 模块化原则 on TypingMind?

Because you install it once and use it with any model. 模块化原则 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 模块化原则 in TypingMind?

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

Which AI models can use 模块化原则?

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 模块化原则?

As many as you like. As long as a model supports skills, you can use 模块化原则 with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the 模块化原则 AI skill free?

Yes. It is published on GitHub by microwind under the MIT license. 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 👇