跳到正文
Skillpedia
API 与服务器(后端)8.1k · #12583

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/webiny/webiny-js/blob/next/skills/user-skills/api/api-architect/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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}/ or features/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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能