Agent skill
analyzing-database-layer
Use when analyzing the database layer including schema, migrations, ORM configuration, and data access patterns
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/analyzing-database-layer
SKILL.md
Analyzing Database Layer
Output: docs/unwind/layers/database/ (folder with index.md + section files)
Principles: See analysis-principles.md - completeness, machine-readable, link to source, no commentary, incremental writes.
Output Structure
docs/unwind/layers/database/
├── index.md # Overview, table count, links to sections
├── schema.md # Current DDL for all tables
├── repositories.md # Data access patterns, queries
└── jsonb-schemas.md # Complex field type definitions (if any JSONB/JSON columns)
For large codebases (20+ tables), split by domain:
docs/unwind/layers/database/
├── index.md
├── users-domain.md # users, user_settings, user_roles tables
├── orders-domain.md # orders, order_items, shipments tables
└── ...
Process (Incremental Writes)
Step 1: Setup
mkdir -p docs/unwind/layers/database/
Write initial index.md:
# Database Layer
## Sections
- [Schema](schema.md) - _pending_
- [Repositories](repositories.md) - _pending_
- [JSONB Schemas](jsonb-schemas.md) - _pending_
## Summary
_Analysis in progress..._
Step 2: Analyze and write schema.md
- Find migration files (Flyway, Liquibase, Alembic, Prisma, Drizzle)
- Extract CURRENT schema state (not migration history)
- Document ALL tables, columns, indexes, constraints
- Write
schema.mdimmediately - Update
index.mdlink to remove "pending"
Step 3: Analyze and write repositories.md
- Find repository/DAO classes
- List ALL with GitHub links and method signatures
- Write
repositories.mdimmediately - Update
index.md
Step 4: Analyze and write jsonb-schemas.md (if applicable)
- Find JSONB/JSON columns
- Extract TypeScript interfaces or Zod schemas
- Write
jsonb-schemas.mdimmediately - Update
index.md
Step 5: Finalize index.md Update with final counts and summary
Output Format
index.md
# Database Layer
## Sections
- [Schema](schema.md) - 12 tables, 4 indexes
- [Repositories](repositories.md) - 8 repository classes
- [JSONB Schemas](jsonb-schemas.md) - 3 complex field types
## Migrations
**Location:** `src/db/migrations/`
Current schema state (result of all migrations) is documented in [schema.md](schema.md).
## Entity Relationships
```mermaid
erDiagram
users ||--o{ orders : places
orders ||--|{ order_items : contains
order_items }|--|| products : references
Summary
- Tables: 12
- Repositories: 8
- JSONB columns: 3
Unknowns
- [List anything unclear]
### schema.md
```markdown
# Database Schema
## Tables (12 total)
### users [MUST]
```sql
CREATE TABLE users (
id BIGINT PRIMARY KEY AUTO_INCREMENT,
email VARCHAR(255) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX idx_users_email ON users(email);
| Column | Type | Nullable | Default | Constraints |
|---|---|---|---|---|
| id | BIGINT | NO | auto | PRIMARY KEY |
| VARCHAR(255) | NO | - | UNIQUE |
[Continue for ALL tables...]
### repositories.md
```markdown
# Repositories
## UserRepository
[UserRepository.java](https://github.com/owner/repo/blob/main/src/repository/UserRepository.java)
```java
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByEmail(String email);
@Query("SELECT u FROM User u WHERE u.status = :status")
List<User> findByStatus(@Param("status") UserStatus status);
}
[Continue for ALL repositories...]
## Additional Requirements
### Field-Level Documentation [MUST]
For EVERY table, document ALL of the following:
- Column name and database type (VARCHAR, INTEGER, JSONB, etc.)
- NOT NULL constraints
- DEFAULT values
- UNIQUE constraints
- Foreign key relationships with ON DELETE behavior (CASCADE, SET NULL, RESTRICT)
**Example:**
```markdown
### users table [MUST]
| Column | Type | Nullable | Default | Constraints |
|--------|------|----------|---------|-------------|
| id | SERIAL | NO | auto | PRIMARY KEY |
| email | VARCHAR(255) | NO | - | UNIQUE |
| organisation | INTEGER | NO | - | FK → organisation.id ON DELETE CASCADE |
| created_at | TIMESTAMP | NO | NOW() | - |
JSONB Schema Extraction [MUST]
For every JSONB/JSON column:
- Search for TypeScript interfaces that type this field
- Search for Zod schemas that validate it
- If no explicit type, infer from usage in code
- Document the complete nested structure
Example:
### calculationData (JSONB) [MUST]
**Source:** Inferred from `snapshot-operations.ts:180-195`
```typescript
{
periodIntervals: number;
intervalType: 'hour' | 'day' | 'week' | 'month';
total: number;
capexPercentage: number; // 0-100
totalCapex: number;
totalOpex: number;
}
### Index Documentation [SHOULD]
Document ALL indexes with:
- Index name
- Columns covered
- Type (btree, gin, partial)
- Rationale (if apparent from naming or usage)
## Mandatory Tagging
**Every table, function, and schema must have a [MUST], [SHOULD], or [DON'T] tag in its heading.**
Default categorizations for database layer:
- **[MUST]**: All tables, core repository functions, JSONB schemas
- **[SHOULD]**: Audit/logging tables, test utilities, performance indexes
- **[DON'T]**: ORM-specific query patterns, migration-specific syntax
Example:
```markdown
### users [MUST]
### audit_logs [SHOULD]
### FindUserByEmail [MUST]
### GetTestDBPath [SHOULD]
See analysis-principles.md section 9 for full tagging rules.
Refresh Mode
If docs/unwind/layers/database/ exists, compare current state and add ## Changes Since Last Review section to index.md.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?