add-api-endpoint

Create API layer components for a new entity. Includes usecase interactors (internal/usecase/), proto definitions (schema/proto/), gRPC handlers (internal/infrastructure/grpc/), and DI registration. Use when adding CRUD endpoints or Step 3 of CRUD workflow (after add-domain-entity).

16 stars

Best use case

add-api-endpoint is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Create API layer components for a new entity. Includes usecase interactors (internal/usecase/), proto definitions (schema/proto/), gRPC handlers (internal/infrastructure/grpc/), and DI registration. Use when adding CRUD endpoints or Step 3 of CRUD workflow (after add-domain-entity).

Teams using add-api-endpoint should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/add-api-endpoint/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/backend/add-api-endpoint/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/add-api-endpoint/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How add-api-endpoint Compares

Feature / Agentadd-api-endpointStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Create API layer components for a new entity. Includes usecase interactors (internal/usecase/), proto definitions (schema/proto/), gRPC handlers (internal/infrastructure/grpc/), and DI registration. Use when adding CRUD endpoints or Step 3 of CRUD workflow (after add-domain-entity).

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Add API Endpoint

Create complete API layer: usecase interactors, proto definitions, gRPC handlers, and DI registration.

## Prerequisites

- Domain entity created (use **add-domain-entity** skill first)
- Repository interface and implementation ready
- SQLBoiler models generated (`make migrate.up`)

## Workflow Overview

```
1. Usecase Input/Output  -->  internal/usecase/input/, output/
2. Interactor Interface  -->  internal/usecase/{actor}_{entity}.go
3. Interactor Impl       -->  internal/usecase/{actor}_{entity}_impl.go
4. Proto Definition      -->  schema/proto/rapid/{actor}_api/v1/
5. Generate Proto        -->  make generate.buf
6. Handler Marshaller    -->  handler/{actor}/marshaller/{entity}.go
7. Handler Methods       -->  handler/{actor}/{entity}.go
8. Update Handler Struct -->  handler/{actor}/handler.go
9. Register in DI        -->  dependency/dependency.go
10. Generate & Test      -->  make generate.mock && make test
```

## Step 1: Create Usecase Input/Output

Location: `internal/usecase/input/{actor}_{entity}.go`

Create input structs for each operation (Create, Get, List, Update, Delete).
Each struct needs a `Validate()` method.

See: [references/usecase-patterns.md](references/usecase-patterns.md#input-structs)

Location: `internal/usecase/output/{actor}_{entity}.go`

Create output struct only for List operations (returns slice + count).

See: [references/usecase-patterns.md](references/usecase-patterns.md#output-structs)

## Step 2: Create Interactor Interface

Location: `internal/usecase/{actor}_{entity}.go`

Define interface with `//go:generate` directive for mock generation.

See: [references/usecase-patterns.md](references/usecase-patterns.md#interactor-interface)

## Step 3: Implement Interactor

Location: `internal/usecase/{actor}_{entity}_impl.go`

Implement CRUD methods following transaction patterns:
- **Create**: Validate -> Create entity -> RWTx -> Get with Preload
- **Get**: Validate -> Get with Preload
- **List**: Validate -> List + Count with Preload
- **Update**: Validate -> RWTx(Get ForUpdate -> Update) -> Get with Preload
- **Delete**: Validate -> RWTx(Get ForUpdate -> Delete)

See: [references/usecase-patterns.md](references/usecase-patterns.md#interactor-implementation)

## Step 4: Define Protocol Buffers

Create two files:
- Model/Enum: `schema/proto/rapid/{actor}_api/v1/model_{entity}.proto`
- Request/Response: `schema/proto/rapid/{actor}_api/v1/api_{entity}.proto`

Then add RPCs to: `schema/proto/rapid/{actor}_api/v1/api.proto`

See: [references/proto-patterns.md](references/proto-patterns.md)

## Step 5: Generate Proto Code

```bash
make generate.buf
```

## Step 6: Create Handler Marshaller

Location: `internal/infrastructure/grpc/internal/handler/{actor}/marshaller/{entity}.go`

Convert between domain models and proto messages.

See: [references/handler-patterns.md](references/handler-patterns.md#marshaller)

## Step 7: Create Handler Methods

Location: `internal/infrastructure/grpc/internal/handler/{actor}/{entity}.go`

Implement gRPC handler methods that delegate to interactors.

See: [references/handler-patterns.md](references/handler-patterns.md#handler-methods)

## Step 8: Update Handler Struct

Location: `internal/infrastructure/grpc/internal/handler/{actor}/handler.go`

Add new interactor field and constructor parameter.

See: [references/handler-patterns.md](references/handler-patterns.md#handler-struct)

## Step 9: Register in DI

Location: `internal/infrastructure/dependency/dependency.go`

1. Add interactor field to `Dependency` struct
2. Initialize repository and interactor in `Inject()` method
3. Update `grpc/run.go` to pass interactor to handler constructor

See: [references/handler-patterns.md](references/handler-patterns.md#di-registration)

## Step 10: Generate Mocks & Test

```bash
make generate.mock
make test
```

## Checklist

- [ ] Input structs with `Validate()` method
- [ ] Output struct for List operation
- [ ] Interactor interface with `//go:generate`
- [ ] Interactor implementation with proper transaction handling
- [ ] Proto model/enum definitions
- [ ] Proto request/response messages with `openapiv2_schema`
- [ ] Proto service RPCs with HTTP annotations
- [ ] Proto code generated (`make generate.buf`)
- [ ] Handler marshaller (both directions + enums)
- [ ] Handler methods
- [ ] Handler struct updated
- [ ] DI configuration updated
- [ ] Mocks generated (`make generate.mock`)
- [ ] Tests passing (`make test`)

## Common Errors

| Error | Solution |
|-------|----------|
| `undefined: pb.Example` | Run `make generate.buf` |
| `undefined: mock_usecase.MockAdminExampleInteractor` | Run `make generate.mock` |
| Handler method not found | Check handler struct field name and interface registration |

Related Skills

api-endpoint

16
from diegosouzapw/awesome-omni-skill

Create or modify API endpoints in IdeaForge backend. Triggers: new route, controller, service, repository, CRUD operation, Zod validation, API debugging. Pattern: Routes → Controller → Service → Repository.

api-endpoint-scaffold

16
from diegosouzapw/awesome-omni-skill

Scaffold new Next.js API endpoints with authentication, rate limiting, and tests. Use when creating new API routes, adding endpoints, or building API features.

api-endpoint-pattern

16
from diegosouzapw/awesome-omni-skill

Standards for creating and organizing HTTP API endpoints using the Echo framework

api-endpoint-generator

16
from diegosouzapw/awesome-omni-skill

Generates CRUD REST API endpoints with request validation, TypeScript types, consistent response formats, error handling, and documentation. Includes route handlers, validation schemas (Zod/Joi), typed responses, and usage examples. Use when building "REST API", "CRUD endpoints", "API routes", or "backend endpoints".

api-endpoint-design

16
from diegosouzapw/awesome-omni-skill

API endpoint design and testing for vehicle insurance data platform. Use when designing new API endpoints, testing existing ones, validating response formats, or debugging API issues. Covers 11 core endpoints including 3 new pie chart distribution endpoints, parameter validation, error handling, and integration patterns.

api-endpoint-creator

16
from diegosouzapw/awesome-omni-skill

Guides standardized REST API endpoint creation following team conventions. Use when creating new API endpoints.

api-endpoint-builder

16
from diegosouzapw/awesome-omni-skill

Build REST API endpoints when designing or implementing API routes with security best practices. Not for client-side fetching or non-API logic.

Add Admin API Endpoint

16
from diegosouzapw/awesome-omni-skill

Add a new endpoint or endpoints to Ghost's Admin API at `ghost/api/admin/**`.

bgo

10
from diegosouzapw/awesome-omni-skill

Automates the complete Blender build-go workflow, from building and packaging your extension/add-on to removing old versions, installing, enabling, and launching Blender for quick testing and iteration.

Coding & Development

mcp-create-declarative-agent

16
from diegosouzapw/awesome-omni-skill

Skill converted from mcp-create-declarative-agent.prompt.md

MCP Architecture Expert

16
from diegosouzapw/awesome-omni-skill

Design and implement Model Context Protocol servers for standardized AI-to-data integration with resources, tools, prompts, and security best practices

mathem-shopping

16
from diegosouzapw/awesome-omni-skill

Automatiserar att logga in på Mathem.se, söka och lägga till varor från en lista eller recept, hantera ersättningar enligt policy och reservera leveranstid, men lämnar varukorgen redo för manuell checkout.