skills_all/backend-models-standards/SKILL.md
Define database models with clear naming, appropriate data types, constraints, relationships, and validation at multiple layers. Use this skill when creating or modifying database model files, ORM classes, schema definitions, or data model relationships. Apply when working with model files (e.g., models.py, models/, ActiveRecord classes, Prisma schema, Sequelize models), defining table structures, setting up foreign keys and relationships, configuring cascade behaviors, implementing model validations, adding timestamps, or working with database constraints (NOT NULL, UNIQUE, foreign keys). Use for any task involving data integrity enforcement, relationship definitions, or model-level data validation.
npx skillsauth add activer007/ordinary-claude-skills Backend Models StandardsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Core Rule: Models define data structure and integrity. Keep them focused on data representation, not business logic.
This Skill provides Claude Code with specific guidance on how to adhere to coding standards as they relate to how it should handle backend models.
Models: Singular, PascalCase (User, OrderItem, PaymentMethod)
Tables: Plural, snake_case (users, order_items, payment_methods)
Relationships: Descriptive and clear
user.orders (one-to-many)order.items (one-to-many)product.categories (many-to-many)Avoid generic names: data, info, record, entity
Timestamps on every model:
created_at = Column(DateTime, nullable=False, default=datetime.utcnow)
updated_at = Column(DateTime, nullable=False, default=datetime.utcnow, onupdate=datetime.utcnow)
Primary keys: Always explicit, prefer UUIDs for distributed systems or auto-incrementing integers for simplicity
Why: Auditing, debugging, data lineage tracking, soft deletes
Use constraints, not just application validation:
# NOT NULL for required fields
email = Column(String(255), nullable=False)
# UNIQUE constraints
email = Column(String(255), unique=True, nullable=False)
# CHECK constraints for business rules
age = Column(Integer, CheckConstraint('age >= 18'))
# Foreign keys with explicit cascade behavior
user_id = Column(Integer, ForeignKey('users.id', ondelete='CASCADE'))
Why: Database enforces rules even if application code bypassed. Defense in depth.
| Data | Type | Avoid | | ---------- | ------------------ | ----------- | | Email, URL | VARCHAR(255) | TEXT | | Short text | VARCHAR(n) | TEXT | | Long text | TEXT | VARCHAR | | Money | DECIMAL(10,2) | FLOAT | | Boolean | BOOLEAN | TINYINT | | Timestamps | TIMESTAMP/DATETIME | VARCHAR | | JSON data | JSON/JSONB | TEXT | | UUIDs | UUID | VARCHAR(36) |
Why: Correct types enable database optimizations, constraints, and prevent data corruption.
Always index:
Example:
class Order(Base):
__tablename__ = 'orders'
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey('users.id'), index=True)
status = Column(String(50), index=True) # Frequently filtered
created_at = Column(DateTime, index=True) # Frequently sorted
Don't over-index: Each index slows writes. Index only queried columns.
Define both sides of relationships:
# One-to-many
class User(Base):
orders = relationship('Order', back_populates='user', cascade='all, delete-orphan')
class Order(Base):
user_id = Column(Integer, ForeignKey('users.id'))
user = relationship('User', back_populates='orders')
Cascade behaviors:
CASCADE: Delete related records (user deleted → orders deleted)SET NULL: Nullify foreign key (category deleted → product.category_id = NULL)RESTRICT: Prevent deletion if related records existNO ACTION: Database default, usually same as RESTRICTChoose based on business logic, not convenience.
Model-level validation (application):
@validates('email')
def validate_email(self, key, email):
if not re.match(r'^[^@]+@[^@]+\.[^@]+$', email):
raise ValueError('Invalid email format')
return email
Database-level constraints (see Data Integrity section)
Why both: Model validation provides clear error messages. Database constraints prevent data corruption if application bypassed.
YES:
@property def full_name)NO:
Models represent data structure, not behavior.
Normalize when:
Denormalize when:
Default to normalized. Denormalize only with evidence of performance issues.
Soft deletes:
deleted_at = Column(DateTime, nullable=True, index=True)
# Query only active records
query = session.query(User).filter(User.deleted_at.is_(None))
Polymorphic associations:
# Avoid if possible - complex and hard to maintain
# Prefer separate relationship fields or inheritance
Enums for fixed values:
from enum import Enum
class OrderStatus(str, Enum):
PENDING = 'pending'
PAID = 'paid'
SHIPPED = 'shipped'
DELIVERED = 'delivered'
status = Column(Enum(OrderStatus), nullable=False, default=OrderStatus.PENDING)
Test constraints and validation:
def test_user_email_required():
with pytest.raises(IntegrityError):
user = User(name='Test')
session.add(user)
session.commit()
def test_user_email_unique():
user1 = User(email='[email protected]')
user2 = User(email='[email protected]')
session.add(user1)
session.commit()
with pytest.raises(IntegrityError):
session.add(user2)
session.commit()
Test relationships:
def test_user_orders_cascade_delete():
user = User(email='[email protected]')
order = Order(user=user)
session.add(user)
session.commit()
session.delete(user)
session.commit()
assert session.query(Order).count() == 0
created_at and updated_at timestampstools
Generate typed TypeScript SDKs for AI agents to interact with MCP servers. Converts verbose JSON-RPC curl commands to clean function calls (docs.createDocument() vs curl). Auto-detects MCP tools from server modules, generates TypeScript types and client methods, creates runnable example scripts. Use when: building MCP-enabled applications, need typed programmatic access to MCP tools, want Claude Code to manage apps via scripts, eliminating manual JSON-RPC curl commands, validating MCP inputs/outputs, or creating reusable agent automation.
testing
Generate structured task lists from specs or requirements. IMPORTANT: After completing ANY spec via ExitSpecMode, ALWAYS ask the user: "Would you like me to generate a task list for this spec?" Use when user confirms or explicitly requests task generation from a plan/spec/PRD.
tools
Create compelling story-format summaries using UltraThink to find the best narrative framing. Support multiple formats - 3-part narrative, n-length with inline links, abridged 5-line, or comprehensive via Foundry MCP. USE WHEN user says 'create story explanation', 'narrative summary', 'explain as a story', or wants content in Daniel's conversational first-person voice.
testing
Navigate through the original three-world shamanic technology. Deploy when soul retrieval, power animal guidance, or journey between realms emerges. Deeply respectful of Tungus, Buryat, Yakut, Evenki traditions. Use for consciousness navigation, NOT cultural appropriation.