Back to Skills

create-repository

majiayu000
Updated Today
1 views
58
9
58
View on GitHub
Metadata

About

This skill generates TypeScript repository interfaces for data access abstraction using the repository pattern. It creates CRUD interface definitions when adding new resources that need database operations. The output includes proper imports, method signatures, and follows project conventions for location and naming.

Quick Install

Claude Code

Recommended
Plugin CommandRecommended
/plugin add https://github.com/majiayu000/claude-skill-registry
Git CloneAlternative
git clone https://github.com/majiayu000/claude-skill-registry.git ~/.claude/skills/create-repository

Copy and paste this command in Claude Code to install this skill

Documentation

Create Repository Interface

Creates the repository interface that defines data access operations for an entity. Implementations (MockDB, MongoDB, etc.) will implement this interface.

Quick Reference

Location: src/repositories/{entity-name}.repository.ts Naming: Singular, kebab-case (e.g., note.repository.ts, course.repository.ts)

Instructions

Step 1: Create the Interface File

Create src/repositories/{entity-name}.repository.ts

Step 2: Import Schema Types

import type {
  {Entity}Type,
  Create{Entity}Type,
  Update{Entity}Type,
  {Entity}QueryParamsType,
  {Entity}IdType,
} from "@/schemas/{entity-name}.schema";
import type { PaginatedResultType } from "@/schemas/shared.schema";
import type { UserIdType } from "@/schemas/user.schemas";

Step 3: Define the Interface

export interface I{Entity}Repository {
  findAll(params: {Entity}QueryParamsType): Promise<PaginatedResultType<{Entity}Type>>;
  findById(id: {Entity}IdType): Promise<{Entity}Type | null>;
  create(data: Create{Entity}Type, createdByUserId: UserIdType): Promise<{Entity}Type>;
  update(id: {Entity}IdType, data: Update{Entity}Type): Promise<{Entity}Type | null>;
  remove(id: {Entity}IdType): Promise<boolean>;
}

Standard CRUD Methods

Every repository interface should include these standard CRUD methods:

MethodParametersReturnsDescription
findAllparams: QueryParamsTypePromise<PaginatedResultType<EntityType>>List with pagination/filtering
findByIdid: EntityIdTypePromise<EntityType | null>Single entity or null
createdata: CreateType, userIdPromise<EntityType>Create and return new entity
updateid, data: UpdateTypePromise<EntityType | null>Update and return, or null
removeid: EntityIdTypePromise<boolean>True if deleted

Patterns & Rules

Naming Conventions

  • Interface name: I{Entity}Repository (e.g., INoteRepository, ICourseRepository)
  • File name: {entity-name}.repository.ts (singular, kebab-case)

Return Type Patterns

  • Single entity lookups: Return EntityType | null (null if not found)
  • List operations: Return PaginatedResultType<EntityType> (always, even if empty)
  • Create operations: Return the created EntityType (with generated ID and timestamps)
  • Update operations: Return EntityType | null (null if entity doesn't exist)
  • Delete operations: Return boolean (true if deleted, false if not found)

Parameter Patterns

  • Create method: Takes Create{Entity}Type + createdByUserId: UserIdType
  • Update method: Takes id separately (from URL) + Update{Entity}Type (from body)
  • Query methods: Take {Entity}QueryParamsType for filtering/pagination

Import Rules

  • Always use path aliases: @/schemas/..., @/repositories/...
  • Import types with import type { ... } for type-only imports
  • Import from specific schema files, not barrel exports

Adding Custom Methods

Add custom methods based on your system's requirements. Common patterns include:

Query by Attribute (findByX)

Find entities by a specific attribute:

findByStatus(status: StatusType, params: {Entity}QueryParamsType): Promise<PaginatedResultType<{Entity}Type>>;
findByOwner(ownerId: UserIdType, params: {Entity}QueryParamsType): Promise<PaginatedResultType<{Entity}Type>>;
findByCategory(categoryId: CategoryIdType, params: {Entity}QueryParamsType): Promise<PaginatedResultType<{Entity}Type>>;

Batch Operations

Operate on multiple entities at once:

// Batch queries
findAllByIds(ids: {Entity}IdType[], params: {Entity}QueryParamsType): Promise<PaginatedResultType<{Entity}Type>>;
findAllByStatus(status: StatusType, params: {Entity}QueryParamsType): Promise<PaginatedResultType<{Entity}Type>>;

// Batch mutations
createMany(data: Create{Entity}Type[], createdByUserId: UserIdType): Promise<{Entity}Type[]>;
updateMany(ids: {Entity}IdType[], data: Update{Entity}Type): Promise<number>; // returns count updated
removeMany(ids: {Entity}IdType[]): Promise<number>; // returns count deleted
removeByOwner(ownerId: UserIdType): Promise<number>; // returns count deleted

Aggregation Operations

Get counts or summaries without fetching full entities:

countByStatus(status: StatusType): Promise<number>;
countByOwner(ownerId: UserIdType): Promise<number>;

Complete Example

import type {
  NoteType,
  CreateNoteType,
  UpdateNoteType,
  NoteQueryParamsType,
  NoteIdType,
} from "@/schemas/note.schema";
import type { PaginatedResultType } from "@/schemas/shared.schema";
import type { UserIdType } from "@/schemas/user.schemas";

export interface INoteRepository {
  // Standard CRUD
  findAll(params: NoteQueryParamsType): Promise<PaginatedResultType<NoteType>>;
  findById(id: NoteIdType): Promise<NoteType | null>;
  create(data: CreateNoteType, createdByUserId: UserIdType): Promise<NoteType>;
  update(id: NoteIdType, data: UpdateNoteType): Promise<NoteType | null>;
  remove(id: NoteIdType): Promise<boolean>;

  // Custom methods (assuming it was needed)
  findAllByIds(
    ids: NoteIdType[],
    params: NoteQueryParamsType,
  ): Promise<PaginatedResultType<NoteType>>;
}

Next Steps

After creating the interface, create an implementation:

  • For development/testing: Use create-mockdb-repository skill
  • For production: Use create-mongodb-repository skill

What NOT to Do

  • Do NOT include implementation details in the interface
  • Do NOT use concrete types (use the interface for dependency injection)
  • Do NOT add business logic - repositories only handle data access
  • Do NOT throw domain errors - return null/false and let the service handle it
  • Do NOT use plural naming (notes.repository.ts) - use singular (note.repository.ts)

GitHub Repository

majiayu000/claude-skill-registry
Path: skills/create-repository

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

llamaindex

Meta

LlamaIndex is a data framework for building RAG-powered LLM applications, specializing in document ingestion, indexing, and querying. It provides key features like vector indices, query engines, and agents, and supports over 300 data connectors. Use it for document Q&A, chatbots, and knowledge retrieval when building data-centric applications.

View skill

hybrid-cloud-networking

Meta

This skill configures secure hybrid cloud networking between on-premises infrastructure and cloud platforms like AWS, Azure, and GCP. Use it when connecting data centers to the cloud, building hybrid architectures, or implementing secure cross-premises connectivity. It supports key capabilities such as VPNs and dedicated connections like AWS Direct Connect for high-performance, reliable setups.

View skill

polymarket

Meta

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

View skill