Skip to content

Rules Examples

The example-daimyo-rules/ directory contains working examples demonstrating best practices for rule organization.

python-general

Parent: None (base scope)

Foundation scope demonstrating proper category organization:

  • Universal categories: general, security, development.coding.python.implementation, development.coding.python.quality, development.coding.python.security
    • Apply across all scopes when writing Python code
    • This scope provides mandatory rules for these universal categories
    • Defined in commandments.yml
  • Conditional categories: development.coding.python.testing, development.coding.python.documentation
    • Apply across all scopes only when performing specific activities
    • This scope provides recommended rules for these universal categories
    • Defined in suggestions.yml
  • Aggregator categories: development.coding, development.coding.python
    • Marked with "DO NOT USE DIRECTLY" warnings
    • Provide hierarchical organization without forcing over-fetching

Key patterns demonstrated:

  • Separation of universal vs conditional categories
  • Top-level security category for critical security mindset
  • Clear "when" descriptions stating applicability
  • Actionable, specific rules (not vague guidelines)

team-backend

Parent: python-general

Team-specific scope demonstrating use of domain-specific categories:

  • Domain-specific categories: development.domain_specific.web_api, development.domain_specific.web_api.security, development.domain_specific.database
    • Universal rules for backend development contexts
    • Defined in commandments.yml
  • Lifecycle categories: development.lifecycle.deployment, development.lifecycle.monitoring
    • Phase-specific recommendations
    • Defined in suggestions.yml
  • Appending to parent: Uses +development.coding.python.testing to extend parent's testing rules

Key patterns demonstrated:

  • Domain-specific vs language-specific separation
  • Lifecycle phase organization
  • Using + prefix to append suggestions from parent scope
  • Security as both commandments (mandatory) and domain-specific rules

python-fastapi

Parent: python-general

Framework-specific scope demonstrating use of architecture pattern categories:

  • Architecture pattern categories: development.architecture_patterns.fastapi.*
    • Marked with "ONLY apply when implementing FastAPI applications"
    • Emphasizes conditional nature with bold warnings
    • Includes routing, async operations, dependencies, performance, testing
  • Clear conditional boundaries: All categories explicitly state they ONLY apply when using FastAPI

Key patterns demonstrated:

  • Architecture patterns as conditional categories
  • Consistent naming: development.architecture_patterns.{framework}.{aspect}
  • Bold "ONLY apply when..." warnings to prevent misapplication
  • Separating mandatory patterns (commandments) from optimization suggestions

project-api

Parents: [team-backend, python-fastapi] (multiple inheritance)

Project-specific scope demonstrating practical composition:

  • Multiple parent inheritance: Inherits from both team and framework scopes
  • Project-specific overrides: Refines parent rules for specific project requirements
    • Example: Mandates UUID v4, RFC 7807 errors, request ID tracing
  • Appending to multiple parent categories:
    • +development.coding.python.testing (extends both parents' testing rules)
    • +development.architecture_patterns.fastapi.performance (adds project-specific performance targets)
  • New project categories: development.lifecycle.review for code review checklist

Key patterns demonstrated:

  • Composing team rules + framework rules + project specifics
  • Priority-based merging (team-backend = first parent = higher priority)
  • Using + prefix to append to inherited suggestions
  • Project-specific enforcement levels (e.g., authentication requirements)
  • Practical combination of universal, conditional, and domain-specific rules

Hierarchy Summary

project-api (project-level specifics)
  ├─ team-backend (context: web API development, databases)
  │   └─ python-general (context: Python development)
  └─ python-fastapi (context: FastAPI framework)
      └─ python-general (context: Python development)

Exploring the Examples

# View category index for any scope
daimyo show python-general

# See merged rules with inheritance
curl http://localhost:8000/api/v1/scopes/project-api/rules

# Filter by specific categories
curl "http://localhost:8000/api/v1/scopes/project-api/rules?categories=development.coding.python.testing,development.domain_specific.web_api"