AgentSkillsCN

code-investigation

高效进行代码库调查,助力快速推进。在修改现有代码之前,了解代码现状、追踪从API到数据库的请求流程、定位功能实现位置,或在变更前分析影响时使用此功能。在修改现有代码、修复Bug或新增功能之前,务必先使用此功能。

SKILL.md
--- frontmatter
name: code-investigation
description: Efficient codebase investigation for rapid-go. Use when understanding existing code before modifications, tracing request flows from API to database, finding where functionality is implemented, or analyzing impact before changes. ALWAYS use before modifying existing code, fixing bugs, or adding features.

Code Investigation Guide

Quick Start

code
Proto (API contract) -> Handler -> Usecase -> Repository -> DB

Use this flow to trace any feature. Start from what you know.

Key Locations

WhatWhere
API contractsschema/proto/rapid/{admin_api,public_api,debug_api}/v1/
Handlersinternal/infrastructure/grpc/internal/handler/{admin,public,debug}/
Usecasesinternal/usecase/*_impl.go
Domain modelsinternal/domain/model/
Repository interfacesinternal/domain/repository/
Repository implementationsinternal/infrastructure/{mysql,postgresql,spanner}/repository/
DI wiringinternal/infrastructure/dependency/dependency.go
Auth interceptorsinternal/infrastructure/grpc/internal/interceptor/

Investigation Patterns

Find an API endpoint

bash
# Find by HTTP path
grep "/admin/v1/tenants" schema/proto/rapid/

# Find by RPC name
grep "CreateTenant" internal/infrastructure/grpc/internal/handler/admin/

Trace request flow

  1. Find RPC in schema/proto/rapid/**/api.proto
  2. Find handler in internal/infrastructure/grpc/internal/handler/{actor}/
  3. Find interactor in internal/usecase/*_impl.go
  4. Find repository in internal/domain/repository/ (interface) and internal/infrastructure/*/repository/ (impl)

Find all usages of a type

bash
# Find usages of a domain model
grep "model.Staff" internal/

# Find usages of a repository method
grep "staffRepository.Get" internal/usecase/

Check authorization logic

  • Session extraction: internal/infrastructure/grpc/internal/interceptor/session_interceptor/
  • Access control: internal/infrastructure/grpc/internal/interceptor/authorization_interceptor/
  • Role checks in usecase: look for param.AdminRole.IsRoot() patterns

Impact analysis before changes

  1. Find interface definition in internal/domain/repository/
  2. Find all implementations in internal/infrastructure/*/repository/
  3. Find all callers in internal/usecase/
  4. Check mock generation: internal/domain/repository/mock/

Common Search Patterns

GoalSearch
Find entity by namegrep "type Staff struct" internal/domain/model/
Find error definitiongrep "StaffNotFoundErr" internal/domain/errors/
Find input validationgrep "type AdminCreateStaff" internal/usecase/input/
Find marshallergrep "StaffToModel|StaffToPb" internal/
Find DI registrationgrep "AdminStaffInteractor" internal/infrastructure/dependency/

Tips

  • Start from proto for API-related investigation
  • Start from domain model for business logic investigation
  • Check dependency.go to understand how components are wired
  • Marshallers exist in two places: repository (DB<->domain) and handler (domain<->proto)