webiny-api-architect
它能做什么
这项技能为你的 AI 提供在 Webiny API 上构建后端代码的主要规则。适合为 Webiny 项目编写添加业务逻辑的扩展的开发者。
适用场景
- ✓当你为 Webiny API 构建任何后端功能或扩展的时候。
- ✓当你需要为某段逻辑决定使用服务还是用例的时候。
- ✓当你想把一个新的后端功能组织到正确的文件夹并完成注册的时候。
技能链接
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/api-architect/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请在 Webiny 中构建一个计算运费的后端功能,并遵循项目的架构规则。”
每周 5 个新技能,1 分钟读完。
工作原理
技能解释服务与用例的区别,功能如何按业务用途命名,以及它们如何在依赖容器中注册。它还列出了需要避免的常见错误。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
API Architecture Patterns
TL;DR
API extensions use createFeature to register features into the DI container. Each feature is a vertical slice with abstractions, implementations, and a feature.ts registration file. The key abstractions are Services (multi-method, singleton) and UseCases (single-method orchestrators, transient). Repositories handle persistence via CMS. Features are named by business capability, files inside by technical responsibility.
Working Context
This skill applies to both extension developers (working in extensions/) and core developers (working in packages/). The architecture patterns are identical — only imports and registration differ.
Extensions (extensions/) |
Core (packages/) |
|
|---|---|---|
| Imports | webiny/api, webiny/api/cms/model, etc. |
@webiny/feature/api, @webiny/api-headless-cms/..., etc. |
| Catalog paths | Use the Import: path |
Use the Source: path |
| Entry point | export default createFeature(...) in a file targeted by <Api.Extension src={...}> |
createFeature registered by the package initializer |
| GraphQL schemas | export default GraphQLSchemaFactory.createImplementation(...) — registered via container.register() inside the entry point's createFeature |
Same pattern, but imported from @webiny/handler-graphql |
Detect which context you're in by checking the file path: extensions/ → extension mode, packages/ → core mode.
Architecture Overview
Extension (root) ── registers ──> Features + GraphQL Schemas + Models
Feature ── registers ──> UseCase | Service | EventHandler + Repository
UseCase ── depends on ──> Service | Repository (+ EventPublisher)
Repository ── depends on ──> CMS Use Cases (GetModel, CreateEntry, etc.)
Service ── depends on ──> external APIs, other Services
- Extension: Top-level entry point. Registers all features, GraphQL schemas, and CMS models.
- Feature: A vertical slice. Registers its use cases, services, repositories, and event handlers.
- UseCase: Single-method orchestrator (
execute()). Coordinates services, repositories, and events. Transient scope. - Service: Multi-method abstraction for external API calls or cohesive domain logic. Singleton scope.
- Repository: Persistence layer using CMS as storage. Singleton scope.
- EventHandler: Thin orchestrator reacting to domain events. Delegates to services/use cases.
- GraphQL Schema: Defines types, inputs, queries, and mutations. Resolvers delegate to use cases.
- CMS Model: Defines the data schema stored in headless CMS.
Services vs UseCases
Services
Multi-method abstractions for external API calls or cohesive domain logic. A service groups related operations that belong together.
// abstractions.ts
export interface ILingotekService {
translate(documentId: string, targetLocale: string): Promise<Result<void, Error>>;
getTranslationStatus(documentId: string): Promise<Result<TranslationStatus, Error>>;
deleteProject(projectId: string): Promise<Result<void, Error>>;
}
export const LingotekService = createAbstraction<ILingotekService>("MyExt/LingotekService");
export namespace LingotekService {
export type Interface = ILingotekService;
}
- Registered in singleton scope (
.inSingletonScope()) - Located in:
features/{serviceName}/orfeatures/services/{serviceName}/ - One service per external system or cohesive domain area
- If async bootstrap is needed (loading settings from CMS, fetching remote config): use the ServiceProvider pattern — a provider abstraction with
async getService()that lazily initializes and caches the service. Consumers inje
常见问题
服务和用例有什么区别?
服务包含多个方法并被共享,而用例只有一个方法,用于单一操作。
功能如何命名?
功能按业务能力命名,其中的文件则按技术角色命名。
它涵盖管理端吗?
不涵盖。管理端模式由单独的 Webiny 管理端技能负责。
详情
作者的原始描述
The hub skill for all API/backend architecture in Webiny. Covers architecture overview, Services vs UseCases, feature naming and organization, feature structure templates, DI decision tree, anti-patterns, createFeature, createAbstraction, container registration, domain errors, entity patterns, naming conventions, scoping rules, and code conventions. Use this skill for ANY backend API work — it references sub-skills for deep implementation details.
repo: webiny/webiny-js
热度
- GitHub 星标
- 8.1k
- 排名
- #12583
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
prd-to-plan
8.1k帮你的智能体把产品需求文档转化为分阶段的计划,由许多小的端到端切片组成,并保存为 Markdown 文件。
webiny-admin-architect
8.1k教你的智能体如何为 Webiny 平台构建管理界面,使用其业务逻辑层和呈现器模式。
webiny-admin-permissions
8.1k教你的智能体为 Webiny 管理界面添加权限控制,包括自动生成的权限表单以及显示或隐藏检查。
webiny-form-model
8.1k教你的智能体使用声明式字段构建器、布局、校验和条件规则,在 Webiny 中构建表单。