Skip to content
check-repository-pattern logo

Check Repository Pattern Skill

check-repository-pattern

Validates database access follows repository pattern, detects god-trait regression, ensures focused repositories

SKILL.md

Full skill instructions

Check Repository Pattern Skill

Purpose

Quick validation that database access follows the repository pattern (commit 6f3efef). Detects god-trait regression and ensures proper use of focused repositories.

CLAUDE.md Compliance

  • ✅ Enforces SOLID principles (Single Responsibility)
  • ✅ Validates focused repository usage
  • ✅ Prevents monolithic database patterns

Usage

Run this skill:

  • Before committing database changes
  • Daily pre-commit validation
  • After adding new repositories
  • When reviewing database-related PRs

Prerequisites

  • ripgrep (rg)

Commands

Quick Check (Fast)

# Check for repository pattern compliance
echo "🔍 Checking repository pattern..."

# 1. Check for DatabaseProvider god-trait (FORBIDDEN)
if rg "trait DatabaseProvider|impl DatabaseProvider" src/ --type rust --quiet; then
    echo "❌ FAIL: DatabaseProvider god-trait detected!"
    rg "DatabaseProvider" src/ --type rust -n | head -10
    exit 1
else
    echo "✓ PASS: No DatabaseProvider god-trait"
fi

# 2. Verify repository directory exists
if [ -d "src/​database/​repositories" ]; then
    REPO_COUNT=$(ls -1 src/​database/​repositories/​*_repository.rs 2>/​dev/​null | wc -l)
    echo "✓ PASS: $REPO_COUNT repository files found"
else
    echo "❌ FAIL: Repository directory missing!"
    exit 1
fi

# 3. Check for direct database access in routes (anti-pattern)
if rg "sqlx::query|\.execute\(|\.fetch" src/​routes/ --type rust --quiet; then
    echo "⚠️  WARNING: Direct database access in routes detected"
    rg "sqlx::query" src/​routes/ --type rust -n | head -5
else
    echo "✓ PASS: No direct database access in routes"
fi

# 4. Verify repository usage
REPO_USAGE=$(rg "Repository" src/​routes/ src/​protocols/ --type rust | wc -l)
echo "✓ Repository usage: $REPO_USAGE references"

echo ""
echo "✅ Repository pattern check PASSED"

Success Criteria

  • ✅ Zero DatabaseProvider trait references
  • ✅ All 13 repository files exist
  • ✅ Repository files have <25 methods each
  • ✅ No direct database access in routes/​protocols
  • ✅ Repository usage > 50 references

Expected Output (Success)

🔍 Checking repository pattern...
✓ PASS: No DatabaseProvider god-trait
✓ PASS: 13 repository files found
✓ PASS: No direct database access in routes
✓ Repository usage: 127 references

✅ Repository pattern check PASSED

Fixing Violations

Remove god-trait usage

// ❌ Before
async fn handler(
    Extension(db): Extension<Arc<dyn DatabaseProvider>>,
) -> AppResult<Json<User>> {
    let user = db.get_user(id).await?;
    Ok(Json(user))
}

// ✅ After
async fn handler(
    Extension(user_repo): Extension<Arc<dyn UserRepository>>,
) -> AppResult<Json<User>> {
    let user = user_repo.get_by_id(id).await?
        .ok_or(AppError::new(
            ErrorCode::ResourceNotFound,
            format!("User {} not found", id)
        ))?;
    Ok(Json(user))
}

Replace direct database access

// ❌ Before (direct sqlx usage in route)
async fn get_user(
    Extension(pool): Extension<Arc<Pool<Database>>>,
    Path(id): Path<Uuid>,
) -> AppResult<Json<User>> {
    let user = sqlx::query_as::<_, User>(
        "SELECT * FROM users WHERE id = $1"
    )
    .bind(id)
    .fetch_one(&*pool)
    .await?;
    Ok(Json(user))
}

// ✅ After (use repository)
async fn get_user(
    Extension(user_repo): Extension<Arc<dyn UserRepository>>,
    Path(id): Path<Uuid>,
) -> AppResult<Json<User>> {
    let user = user_repo.get_by_id(id).await?
        .ok_or(AppError::new(
            ErrorCode::ResourceNotFound,
            format!("User {} not found", id)
        ))?;
    Ok(Json(user))
}

Related Files

  • src/​database/​repositories/​mod.rs - Repository traits
  • src/​database/​repositories/​*_repository.rs - 13 implementations
  • Commit 6f3efef - Repository pattern migration

Related Agents

  • repository-pattern-guardian - Comprehensive repository validation

Quick Reference

# One-line check
rg "trait DatabaseProvider" src/ --type rust && echo "FAIL" || echo "PASS"

# Check repository count
ls -1 src/​database/​repositories/​*_repository.rs | wc -l

# Check for direct database access
rg "sqlx::query" src/​routes/ --type rust && echo "WARNING" || echo "PASS"

# Repository usage count
rg "Repository" src/​routes/ src/​protocols/ --type rust | wc -l

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View