AGENT SKILL

backend

Go backend patterns for the api app — covering dependency injection, services, repositories, handlers, use cases, plugins, service registry, and TDD unit testing

License 许可
Apache-2.0
最近更新
2026-11-04
Stars
★ 41
Forks
0

01 前言 Front Matter

name
backend
description
Go backend patterns for the api app — covering dependency injection, services, repositories, handlers, use cases, plugins, service registry, and TDD unit testing

03 SKILL.md 正文

Backend Patterns

Reusable patterns for the Go backend (apps/api). These skills cover the layered architecture: repositories → services → use cases → handlers, wired via constructor-based dependency injection and organized around a plugin system.

Architecture Overview

Dependencies flow bottom-up and are wired in bootstrap.go:

  • Repositories accept bun.IDB and return interfaces — data access only
  • Services accept repositories and return interfaces — business logic
  • Use cases accept services — orchestrate multi-service workflows
  • Handlers accept use cases — HTTP boundary only
  • Plugins accept a PluginContext, retrieve services from the registry, and expose routes/migrations

Skills

Dependency Injection

Constructor-based DI — dependencies passed via parameters, interface-based, wired at bootstrap time. No service locators or global state.

Repositories & Data Access

One repository interface per domain model, implemented with Bun ORM. CRUD only, WithTx support, context-aware, no business logic.

Services & Interfaces

Services encapsulate business logic — interfaces exported from interfaces.go, implemented by concrete structs with constructors that inject repositories.

Use Cases & Orchestration

Orchestrate multiple services for application-level workflows. Single Execute method, pure domain, no HTTP concerns.

Handlers & HTTP

Thin HTTP boundary — parse/validate requests, delegate to use cases, map errors to status codes via constants/errors.go, format responses with reqCtx.SetJSONResponse.

Plugin Architecture

Self-contained pluggable features (OAuth2, JWT, email-password) with metadata, Init, optional Routes/Migrations/Middleware, and lifecycle cleanup.

Service Registry

Thread-safe registry for runtime service discovery between plugins. Register in Init, retrieve with type assertions, using models.ServiceXxx constants.

TDD & Unit Testing

Red-Green-Refactor testing — mocked dependencies, table-driven tests, AAA pattern, real SQLite for repositories, httptest for handlers.

04 同仓库更多 Skills

CliqRelay
CliqRelay/cliqrelay

typst

Typst document creation and package development. Use when: (1) Working with .typ files, (2) User mentions typst, typst.toml, or typst-cli, (3) Creating or using Typst packages, (4) Developing document templates, (5) Converting Markdown/LaTeX to Typst

★ 41
CliqRelay
CliqRelay/cliqrelay

shadcn

Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".

★ 41
CliqRelay
CliqRelay/cliqrelay

handoff

Compact the current conversation into a handoff document for another agent to pick up.

★ 41
CliqRelay
CliqRelay/cliqrelay

grilling

Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.

★ 41
CliqRelay
CliqRelay/cliqrelay

grill-me

A relentless interview to sharpen a plan or design.

★ 41
CliqRelay
CliqRelay/cliqrelay

dont-waffle

Use this skill when answering questions, explaining concepts, writing technical responses, reviewing code, or helping with development tasks. Communicate in clear, simple, standard English. Keep answers concise and focused, remove unnecessary filler and repetition, explain technical ideas in plain language, and structure information so it is easy to read and understand. When showing code, present it clearly with enough context for the developer to understand what it does and where it belongs.

★ 41