重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
modular-architecture by melodic-software/claude-code-plugins
npx skills add https://github.com/melodic-software/claude-code-plugins --skill modular-architecture在以下情况下使用此技能:
关键词: 模块化单体,模块,限界上下文,端口与适配器,六边形架构,模块通信,数据隔离,独立的 DbContext,MediatR,领域事件,内部事件,模块边界
按模块(业务能力) 而非层级来组织代码。每个模块都是一个自包含的垂直切片,拥有自己的:
src/
├── Modules/
│ ├── Ordering/
│ │ ├── Ordering.Core/ # 领域 + 应用层
│ │ │ ├── Domain/ # 实体、值对象、事件
│ │ │ ├── Application/ # 命令、查询、处理器
│ │ │ └── Ports/ # 接口(驱动端/被驱动端)
│ │ ├── Ordering.Infrastructure/ # 外部依赖
│ │ │ ├── Persistence/ # EF Core, DbContext
│ │ │ └── Adapters/ # 外部服务实现
│ │ └── Ordering.DataTransfer/ # 用于模块间通信的 DTO
│ ├── Inventory/
│ │ ├── Inventory.Core/
│ │ ├── Inventory.Infrastructure/
│ │ └── Inventory.DataTransfer/
│ └── Shared/ # 真正共享的内核(最小化)
│ └── Shared.Kernel/ # 公共值对象、接口
└── Host/ # 组合根、启动项
└── Api/ # 控制器、中间件
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
六边形架构通过端口(接口)和适配器(实现)将业务逻辑与外部关注点分离。
详细指南: 参见 references/ports-adapters-guide.md
┌─────────────────────────────────────────────────────────────┐
│ 驱动端 (Primary) │
│ 控制器、CLI、消息处理器、测试 │
│ │ │
│ ┌──────▼──────┐ │
│ │ 端口 │ (输入接口) │
│ │ IOrderService│ │
│ └──────┬──────┘ │
│ │ │
│ ┌────────────▼────────────┐ │
│ │ 应用层 │ │
│ │ (用例/处理器) │ │
│ └────────────┬────────────┘ │
│ │ │
│ ┌────────────▼────────────┐ │
│ │ 领域层 │ │
│ │ (实体、值对象) │ │
│ └────────────┬────────────┘ │
│ │ │
│ ┌──────▼──────┐ │
│ │ 端口 │ (输出接口) │
│ │IOrderRepository│ │
│ └──────┬──────┘ │
│ │ │
│ 被驱动端 (Secondary) │
│ 数据库、外部 API、文件系统、队列 │
└─────────────────────────────────────────────────────────────┘
驱动端口: 应用暴露的接口(由应用层实现) 被驱动端口: 应用需要的接口(由适配器实现)
模块必须在不产生紧耦合的情况下进行通信。主要有两种模式:
详细指南: 参见 references/module-communication.md
用于需要立即响应的查询操作:
// 在 Inventory 模块中 - 需要检查产品可用性
public class CheckStockHandler
{
private readonly IOrderingModuleApi _orderingApi;
public async Task<StockStatus> Handle(CheckStockQuery query)
{
// 通过 DataTransfer DTO 获取订单信息
var orderDto = await _orderingApi.GetOrderSummary(query.OrderId);
// orderDto 来自 Ordering.DataTransfer 项目
}
}
用于其他模块需要响应的状态变更:
// 在 Ordering 模块中 - 下单后发布事件
public class PlaceOrderHandler
{
private readonly IMediator _mediator;
public async Task Handle(PlaceOrderCommand command)
{
// ... 创建订单 ...
// 发布集成事件(由其他模块处理)
await _mediator.Publish(new OrderPlacedIntegrationEvent(
order.Id, order.Items.Select(i => i.ProductId)));
}
}
// 在 Inventory 模块中 - 处理事件
public class OrderPlacedHandler : INotificationHandler<OrderPlacedIntegrationEvent>
{
public async Task Handle(OrderPlacedIntegrationEvent notification, CancellationToken ct)
{
// 为订单预留库存
await _inventoryService.ReserveStock(notification.ProductIds);
}
}
每个模块应拥有自己的数据,以防止数据库层面的紧耦合。
详细指南: 参见 references/data-patterns.md
// Ordering 模块的 DbContext
public class OrderingDbContext : DbContext
{
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
// 仅配置 Ordering 实体
builder.ApplyConfigurationsFromAssembly(typeof(OrderingDbContext).Assembly);
}
}
// Inventory 模块的 DbContext
public class InventoryDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<StockLevel> StockLevels { get; set; }
}
MediatR 为模块内的 CQRS 和跨模块的集成事件提供了消息传递基础设施。
详细指南: 参见 references/mediatr-integration.md
// 在每个模块的注册中
public static class OrderingModule
{
public static IServiceCollection AddOrderingModule(this IServiceCollection services)
{
services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(typeof(OrderingModule).Assembly));
services.AddScoped<IOrderingModuleApi, OrderingModuleApi>();
services.AddDbContext<OrderingDbContext>();
return services;
}
}
| 类型 | 范围 | 用例 |
|---|---|---|
| 领域事件 | 模块内 | 聚合状态变更 |
| 集成事件 | 跨模块 | 通知其他模块变更 |
此技能可与 event-storming 技能结合,用于发现限界上下文:
工作流程:
事件风暴 (发现"是什么")
↓
识别限界上下文
↓
模块化架构 (实现"在哪里")
↓
创建模块结构
↓
适应度函数 (强制边界)
使用 fitness-functions 技能来强制模块边界:
开始一个新的模块化单体项目时:
references/ports-adapters-guide.md - 详细的六边形架构模式references/module-communication.md - 同步和异步通信模式references/data-patterns.md - 数据库隔离策略references/mediatr-integration.md - MediatR 配置和模式日期: 2025-12-22 模型: claude-opus-4-5-20251101
每周安装量
56
代码仓库
GitHub 星标数
40
首次出现
2026年1月24日
安全审计
安装于
codex48
gemini-cli47
opencode47
github-copilot46
cursor42
kimi-cli42
Use this skill when you need to:
Keywords: modular monolith, modules, bounded contexts, ports and adapters, hexagonal architecture, module communication, data isolation, separate DbContext, MediatR, domain events, internal events, module boundaries
Organize code by modules (business capabilities) , not layers. Each module is a self-contained vertical slice with its own:
src/
├── Modules/
│ ├── Ordering/
│ │ ├── Ordering.Core/ # Domain + Application
│ │ │ ├── Domain/ # Entities, Value Objects, Events
│ │ │ ├── Application/ # Commands, Queries, Handlers
│ │ │ └── Ports/ # Interfaces (driven/driving)
│ │ ├── Ordering.Infrastructure/ # External dependencies
│ │ │ ├── Persistence/ # EF Core, DbContext
│ │ │ └── Adapters/ # External service implementations
│ │ └── Ordering.DataTransfer/ # DTOs for module-to-module communication
│ ├── Inventory/
│ │ ├── Inventory.Core/
│ │ ├── Inventory.Infrastructure/
│ │ └── Inventory.DataTransfer/
│ └── Shared/ # Truly shared kernel (minimal)
│ └── Shared.Kernel/ # Common value objects, interfaces
└── Host/ # Composition root, startup
└── Api/ # Controllers, middleware
The hexagonal architecture separates business logic from external concerns through ports (interfaces) and adapters (implementations).
Detailed guide: See references/ports-adapters-guide.md
┌─────────────────────────────────────────────────────────────┐
│ DRIVING SIDE (Primary) │
│ Controllers, CLI, Message Handlers, Tests │
│ │ │
│ ┌──────▼──────┐ │
│ │ PORTS │ (Input interfaces) │
│ │ IOrderService│ │
│ └──────┬──────┘ │
│ │ │
│ ┌────────────▼────────────┐ │
│ │ APPLICATION │ │
│ │ (Use Cases/Handlers) │ │
│ └────────────┬────────────┘ │
│ │ │
│ ┌────────────▼────────────┐ │
│ │ DOMAIN │ │
│ │ (Entities, Value Objs) │ │
│ └────────────┬────────────┘ │
│ │ │
│ ┌──────▼──────┐ │
│ │ PORTS │ (Output interfaces) │
│ │IOrderRepository│ │
│ └──────┬──────┘ │
│ │ │
│ DRIVEN SIDE (Secondary) │
│ Databases, External APIs, File Systems, Queues │
└─────────────────────────────────────────────────────────────┘
Driving Ports: Interfaces the application exposes (implemented by the application) Driven Ports: Interfaces the application needs (implemented by adapters)
Modules must communicate without creating tight coupling. Two primary patterns:
Detailed guide: See references/module-communication.md
For query operations where immediate response is needed:
// In Inventory module - needs to check product availability
public class CheckStockHandler
{
private readonly IOrderingModuleApi _orderingApi;
public async Task<StockStatus> Handle(CheckStockQuery query)
{
// Get order info through DataTransfer DTO
var orderDto = await _orderingApi.GetOrderSummary(query.OrderId);
// orderDto is from Ordering.DataTransfer project
}
}
For state changes that other modules need to react to:
// In Ordering module - publishes event after order is placed
public class PlaceOrderHandler
{
private readonly IMediator _mediator;
public async Task Handle(PlaceOrderCommand command)
{
// ... create order ...
// Publish integration event (handled by other modules)
await _mediator.Publish(new OrderPlacedIntegrationEvent(
order.Id, order.Items.Select(i => i.ProductId)));
}
}
// In Inventory module - handles the event
public class OrderPlacedHandler : INotificationHandler<OrderPlacedIntegrationEvent>
{
public async Task Handle(OrderPlacedIntegrationEvent notification, CancellationToken ct)
{
// Reserve inventory for the order
await _inventoryService.ReserveStock(notification.ProductIds);
}
}
Each module should own its data to prevent tight coupling at the database level.
Detailed guide: See references/data-patterns.md
// Ordering module's DbContext
public class OrderingDbContext : DbContext
{
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
// Only configure Ordering entities
builder.ApplyConfigurationsFromAssembly(typeof(OrderingDbContext).Assembly);
}
}
// Inventory module's DbContext
public class InventoryDbContext : DbContext
{
public DbSet<Product> Products { get; set; }
public DbSet<StockLevel> StockLevels { get; set; }
}
MediatR provides the messaging infrastructure for both in-module CQRS and cross-module integration events.
Detailed guide: See references/mediatr-integration.md
// In each module's registration
public static class OrderingModule
{
public static IServiceCollection AddOrderingModule(this IServiceCollection services)
{
services.AddMediatR(cfg =>
cfg.RegisterServicesFromAssembly(typeof(OrderingModule).Assembly));
services.AddScoped<IOrderingModuleApi, OrderingModuleApi>();
services.AddDbContext<OrderingDbContext>();
return services;
}
}
| Type | Scope | Use Case |
|---|---|---|
| Domain Event | Within module | Aggregate state changes |
| Integration Event | Cross-module | Notify other modules of changes |
This skill works with the event-storming skill for bounded context discovery:
Workflow:
Event Storming (discover "what")
↓
Bounded Contexts identified
↓
Modular Architecture (implement "where")
↓
Module structure created
↓
Fitness Functions (enforce boundaries)
Use the fitness-functions skill to enforce module boundaries:
When starting a new modular monolith:
references/ports-adapters-guide.md - Detailed hexagonal architecture patternsreferences/module-communication.md - Sync and async communication patternsreferences/data-patterns.md - Database isolation strategiesreferences/mediatr-integration.md - MediatR configuration and patternsDate: 2025-12-22 Model: claude-opus-4-5-20251101
Weekly Installs
56
Repository
GitHub Stars
40
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex48
gemini-cli47
opencode47
github-copilot46
cursor42
kimi-cli42
Laravel架构模式指南:生产级开发模式与最佳实践
1,400 周安装
Reddit自动化工具:通过Rube MCP和Composio实现帖子搜索、发布与评论管理
70 周安装
Jira助手:AI驱动项目管理工具,自动化Jira任务与问题处理
70 周安装
Salesforce B2C Commerce Web Services 集成指南:Service Framework 配置与调用
69 周安装
VueUse Integrations 集成库:Vue 3.5+ 实用工具与第三方库封装
69 周安装
Todoist自动化教程:通过Rube MCP和Composio实现任务与项目管理
69 周安装
小红书视频下载器 - 一键下载视频/音频/字幕并生成AI摘要 | 开源工具
69 周安装