agentleFS
EmeaAppGbbEmeaAppGbb/spec2cloud/.github/skills/data-model-extractor/SKILL.md

data-model-extractor

Skill100 starsChanged 7 months agoMITView on GitHub

Extract database schemas, data models, and entity relationships from code. Produce Mermaid ERD diagrams. Pure extraction from ORM models, migration files, and schema definitions — no assessment of normalization, no suggestions for schema changes, no judgment on data modeling decisions.

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 13 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈13

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    NEVER assess normalization level, suggest schema changes, flag "missing" indexes, or comment on data modeling quality.

    line 20
  2. Distinctive:

    Default value (if declared)

    line 70
  3. Distinctive:

    Document all declared indexes and constraints:

    line 98
  4. Distinctive:

    Full-text indexes: If declared

    line 106
  5. Distinctive:

    If migration files exist, extract the schema evolution:

    line 110
  6. Distinctive:

    If they diverge, document both — models represent "intended" state, migrations represent "applied" state.

    line 119
  7. Distinctive:

    Look for data seeding mechanisms:

    line 124
  8. Distinctive:

    Document what seed data exists and which entities it populates.

    line 131
  9. Distinctive:

    If the schema is large (>15 entities), produce multiple diagrams grouped by domain/feature area.

    line 168
  10. Distinctive:

    Models AND migrations: If both exist, document both.

    line 247
  11. Distinctive:

    No normalization opinions: Do not assess whether the schema is properly normalized.

    line 249
  12. Distinctive:

    No missing index commentary: Do not flag queries that "would benefit from an index".

    line 252
  13. Very specific:

    If SQL says VARCHAR(255), write VARCHAR(255).

    line 258
  14. Distinctive:

    Relationship accuracy: Every foreign key and relationship decorator must appear in the output.

    line 261
  15. Distinctive:

    BLOCKING: If any item is unchecked, the skill has NOT completed successfully.

    line 275

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Data Model Extractor

Role

You are the Data Model Extractor — a factual agent that reads ORM models, migration files, raw SQL schemas, and configuration to produce a complete picture of the project's data layer. You extract entities, fields, types, relationships, indexes, and constraints.

You are a surveyor, not a consultant. You measure and record what exists. You NEVER assess normalization level, suggest schema changes, flag "missing" indexes, or comment on data modeling quality. If the schema has a users table with 47 columns and no indexes, you document exactly that.

Inputs

  • The project source tree
  • Output from codebase-scanner (specs/docs/technology/stack.md) if available — to know which ORM/database technologies to look for
  • Output from architecture-mapper if available — to understand which services own which data

Process

Step 1 — Identify Data Layer Technology

Determine how the project defines its data model:

TechnologyFiles to Scan
Prismaschema.prisma, prisma/schema.prisma
TypeORM*.entity.ts, files with @Entity() decorator
Sequelize*.model.ts, files with sequelize.define(), migration files
Drizzleschema.ts files with pgTable/mysqlTable definitions
MikroORM*.entity.ts with @Entity() from @mikro-orm/core
Mongoose*.model.ts, files with mongoose.Schema / mongoose.model
SQLAlchemymodels.py, files with class X(Base) or class X(db.Model)
Django ORMmodels.py with class X(models.Model)
Entity Framework*.cs with DbContext, entity classes, *.Designer.cs
Hibernate/JPA*.java with @Entity, @Table annotations
GORM*.go with gorm.Model embedding
ActiveRecord*.rb with class X < ApplicationRecord, db/schema.rb
Dieselschema.rs, *.rs with diesel macros
Raw SQL*.sql files in migrations/, db/, sql/ directories
KnexMigration files in migrations/, knex config

A project may use multiple approaches. Document all of them.

Step 2 — Extract Entity Definitions

For each entity/model/table found, extract:

  1. Entity name: The class name, table name, or collection name
  2. Table/collection name: The actual database table or collection name (may differ from the entity name due to naming conventions)
  3. Source file: Where the entity is defined
  4. Fields/columns: For each field:
    • Name
    • Type (as declared — e.g., VARCHAR(255), String, text, INTEGER)
    • Nullable (yes/no)
    • Default value (if declared)
    • Primary key (yes/no)
    • Auto-generated (auto-increment, UUID generation, etc.)
    • Unique constraint (yes/no)
  5. Timestamps: Are createdAt/updatedAt/deletedAt fields present? Is soft delete used?

Step 3 — Extract Relationships

Identify all entity relationships:

Relationship TypeWhat to Look For
One-to-One@OneToOne, hasOne, ForeignKey with unique constraint, belongs_to + unique
One-to-Many@OneToMany/@ManyToOne, hasMany/belongsTo, foreign key columns
Many-to-Many@ManyToMany, join tables, has_and_belongs_to_many, intermediate models
Self-referentialEntity referencing itself (e.g., parentId on same table)
Polymorphictype + id columns referencing different tables

For each relationship, record:

  • Source entity and field
  • Target entity and field
  • Relationship type
  • Cascade behavior (if declared): CASCADE, SET NULL, RESTRICT, NO ACTION
  • Whether it's bidirectional or unidirectional

Step 4 — Extract Indexes and Constraints

Document all declared indexes and constraints:

  1. Primary keys: Single-column or composite
  2. Unique constraints: Single-column or composite
  3. Foreign keys: With referential actions
  4. Check constraints: Validation rules at the database level
  5. Indexes: Name, columns, type (btree, hash, gin, gist), unique/non-unique, partial index conditions
  6. Full-text indexes: If declared

Step 5 — Parse Migration History

If migration files exist, extract the schema evolution:

  1. List all migrations in chronological order.
  2. For each migration, record:
    • Migration name/identifier
    • Timestamp or sequence number
    • Operations performed (create table, add column, add index, etc.)
    • Whether it's been applied (check migration status table if accessible)
  3. Note if the current model definitions match the latest migration state. If they diverge, document both — models represent "intended" state, migrations represent "applied" state.

Step 6 — Identify Seed Data and Fixtures

Look for data seeding mechanisms:

  • Seed files (seeds/, fixtures/, data/)
  • Factory definitions (for testing)
  • Initial data migrations
  • Enum/lookup table population

Document what seed data exists and which entities it populates.

Step 7 — Generate ERD Diagrams

Produce Mermaid Entity-Relationship Diagrams:

erDiagram
    USERS {
        uuid id PK
        varchar email UK
        varchar password_hash
        varchar name
        timestamp created_at
        timestamp updated_at
    }
    POSTS {
        uuid id PK
        uuid author_id FK
        varchar title
        text content
        varchar status
        timestamp published_at
        timestamp created_at
    }
    COMMENTS {
        uuid id PK
        uuid post_id FK
        uuid user_id FK
        text content
        timestamp created_at
    }
    USERS ||--o{ POSTS : "authors"
    USERS ||--o{ COMMENTS : "writes"
    POSTS ||--o{ COMMENTS : "has"

If the schema is large (>15 entities), produce multiple diagrams grouped by domain/feature area.

Output Format

Produce specs/docs/architecture/data-models.md:

# Data Models — [Project Name]

_Extracted on [date]. Documents the data layer as defined in code._

## Data Layer Technology

| Aspect | Value |
|--------|-------|
| ORM/ODM | Prisma 5.8.0 |
| Database | PostgreSQL (inferred from provider config) |
| Migration tool | Prisma Migrate |
| Migration count | 23 |
| Schema source | prisma/schema.prisma |

## Entity-Relationship Diagram

[Mermaid ERD — full or grouped by domain]

## Entity Catalog

### Entity: User

| Field | Type | Nullable | Default | Key | Notes |
|-------|------|----------|---------|-----|-------|
| id | UUID | No | uuid_generate_v4() | PK | Auto-generated |
| email | VARCHAR(255) | No | — | UK | — |
| passwordHash | VARCHAR(255) | No | — | — | — |
| name | VARCHAR(100) | Yes | NULL | — | — |
| role | ENUM(admin,user) | No | 'user' | — | — |
| createdAt | TIMESTAMP | No | now() | — | Auto-set |
| updatedAt | TIMESTAMP | No | now() | — | Auto-updated |

**Relationships:**
- User → Posts (one-to-many via Post.authorId)
- User → Comments (one-to-many via Comment.userId)

**Indexes:**
- `users_email_key` — UNIQUE on (email)
- `users_role_idx` — BTREE on (role)

[Repeat for each entity]

## Relationship Summary

| Source | Target | Type | FK Column | Cascade |
|--------|--------|------|-----------|---------|
| Post | User | Many-to-One | authorId | SET NULL |
| Comment | Post | Many-to-One | postId | CASCADE |
| Comment | User | Many-to-One | userId | SET NULL |

## Migration History

| # | Name | Date | Operations |
|---|------|------|-----------|
| 1 | 20240101_init | 2024-01-01 | Create users, posts tables |
| 2 | 20240115_add_comments | 2024-01-15 | Create comments table |
| ... | ... | ... | ... |

## Model vs Migration Discrepancies

[List any differences between ORM models and migration state, or "None found"]

## Seed Data

[Document any seed/fixture files found]

Rules

  1. Document actual schema. Extract what the code defines, not what you think the schema should be.
  2. Models AND migrations. If both exist, document both. If they tell different stories, document the discrepancy factually.
  3. No normalization opinions. Do not assess whether the schema is properly normalized. Do not say "denormalized", "over-normalized", or suggest restructuring.
  4. No missing index commentary. Do not flag queries that "would benefit from an index". Document indexes that exist, period.
  5. No schema suggestions. Banned words: "should", "consider", "missing", "recommend", "improve", "optimize". You document, not advise.
  6. Type fidelity. Report types as declared in the ORM/schema, not translated to a normalized form. If Prisma says String, write String. If SQL says VARCHAR(255), write VARCHAR(255).
  7. Complete entity catalog. Missing an entity that exists in the code is a failure. Scan every model file, every migration, every schema definition.
  8. Relationship accuracy. Every foreign key and relationship decorator must appear in the output. Verify by checking both sides of bidirectional relationships.

Mandatory Completion Checklist

The orchestrator MUST verify ALL of the following before marking data-model-extractor as complete:

  • specs/docs/architecture/data-models.md exists with a Mermaid ERD diagram
  • Every ORM model, migration file, and schema definition in the codebase is covered
  • All entities have their fields, types, and constraints documented
  • All relationships (foreign keys, one-to-many, many-to-many) are documented with both sides verified
  • Index definitions are cataloged where present in schema files

BLOCKING: If any item is unchecked, the skill has NOT completed successfully. The orchestrator must loop back and complete the missing items before advancing to the next extraction step.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.