Safe By Default Architect
Overview
This skill converts recurring dangerous implementation patterns into safe architectural defaults and enforceable standards. Rather than catching unsafe code during review, it designs the codebase so that the safe way is the easy way and the dangerous way requires deliberate effort.
The core philosophy: If a developer can accidentally write dangerous code, the architecture has failed.
Scope Boundary: This skill designs standards, abstractions, and rules. For reviewing existing code against those standards, use critical-code-reviewer. For investigating incidents caused by unsafe patterns, use incident-rca-specialist.
When to Use
- Repeated defects of the same class appear across multiple PRs or services
- Raw SQL, opt-in authorization, or direct file path construction appears in controller/route layers
- No common service layer exists for cross-cutting concerns (auth, file I/O, datetime handling)
- You need to convert RCA findings into enforceable coding standards
- Static analysis rules (lint/semgrep/custom checks) need to be designed
- A "forbidden patterns" list needs to be paired with approved alternatives
- Architecture Decision Records need to codify safe defaults
- A new project or module needs safe-by-default foundations from day one
Inputs
- RCA reports, bug tickets, or critical review findings
- Coding guidelines and architecture documents (if any)
- Technology stack information (language, framework, ORM, tooling)
- Static analysis / lint configuration (if any)
- Relevant code fragments showing dangerous patterns
Outputs
- Safe Pattern Catalog -- approved patterns per category with rationale
- Forbidden Pattern List -- anti-patterns with danger classification and alternatives
- Common Layer Design -- shared services and abstraction recommendations
- Static Rule Candidate List -- lint/semgrep rule proposals with false positive assessment
- Exception Handling Rule -- when and how to approve deviations
- Review Checklist Addendum -- additions to existing code review checklists
Prerequisites
- Defect/RCA data available: Bug reports, RCA findings, or review findings that reveal recurring unsafe patterns
- Technology stack identified: Language, framework, ORM, and tooling context
- Existing standards accessible: Current coding guidelines, lint configuration, and architecture documents (if any)
- Stakeholder alignment: Agreement that architectural enforcement is needed (not just documentation)
Workflows
Workflow 1: Recurring Pattern Aggregation (再発パターン集約)
Collect and consolidate recurring dangerous patterns from defect data.
- Gather inputs: RCA reports, bug tickets, critical review findings, security scan results
- Extract each distinct dangerous pattern with:
- Pattern name: Short identifier (e.g., "raw-sql-concatenation")
- Frequency: How often this pattern has caused issues
- Example code: Representative code snippet from actual incidents
- Affected components: Which modules, layers, or services are impacted
- Deduplicate patterns that are variations of the same root issue
- Load
references/safe_pattern_catalog.md and check if existing safe patterns cover the identified dangers
- Output: Consolidated pattern inventory (aim for 10-30 distinct patterns)
Workflow 2: Danger Classification (危険理由分類)
Classify each dangerous pattern by its threat mechanism.
- Load
references/forbidden_patterns.md for the classification taxonomy
- Assign each pattern to one or more danger categories:
- Injection / Bypass / Traversal: Attacker-controlled input reaches sensitive operations
- Silent Corruption: Data is modified or lost without error or notification
- Environment Divergence: Behavior differs between dev/staging/production
- Hidden Dependency: Implicit coupling that breaks under change
- Human Error Amplification: Design makes mistakes easy and recovery hard
- Unverifiable Behavior: Cannot confirm correctness through testing alone
- Rank patterns by:
frequency x blast_radius x detection_difficulty
- Identify patterns that span multiple danger categories (highest priority)
- Output: Classified and ranked danger inventory
Workflow 3: Safe Standard Definition (標準パターン定義)
Define the approved safe replacement for each forbidden pattern.
- Load
references/safe_pattern_catalog.md for reference patterns
- For each dangerous pattern, define:
- Forbidden practice: What is explicitly prohibited
- Approved pattern: The safe alternative developers must use
- Required abstraction: Common layer, wrapper, or service that enforces safety
- Minimum contract test: The test that proves the safe pattern is used
- Static rule candidate: How to detect violations automatically
- Review checkpoint: What reviewers must verify
- Use
assets/safe_standard_template.md to document each standard
- Use
assets/forbidden_to_safe_mapping_template.md to create the mapping table
- Validate that every forbidden pattern has a concrete, usable alternative
Workflow 4: Safe Default Decision (安全デフォルト決定)
Establish the project-wide safe defaults that apply universally.
- Load
references/boundary_hardening_guide.md for boundary-specific guidance
- Define safe defaults for each boundary:
- Query construction: ORM / parameterized queries only; raw SQL prohibited by default
- Authorization: Deny-by-default; every endpoint requires explicit permission grant
- File operations: Service-layer abstraction only; no direct path construction
- Persistence confirmation: UI success message only after persistence is confirmed
- DateTime handling: UTC-aware normalization at persistence boundary
- Row/data access: Named/object access preferred; positional access prohibited
- Dependency loading: Explicit injection; no implicit service locator or global state
- Idempotency: All write operations must be idempotent or explicitly marked non-idempotent
- For each default, document:
- The default behavior (what happens when developer does nothing special)
- The escape hatch (how to override when genuinely needed)
- The enforcement mechanism (lint rule, wrapper API, framework constraint)
- Output: Safe defaults specification document
Workflow 5: Common Layer and Exception Design (共通層+例外条件)
Design the shared infrastructure that makes safe defaults easy and define exception policies.
- Load
references/exception_policy.md for exception handling guidance
- Design common layer placement:
- Which abstraction layer hosts each safe wrapper (middleware, service, repository, utility)
- Interface contracts that enforce safe usage
- Extension points for legitimate edge cases
- Define exception conditions:
- When raw SQL is allowed: Performance-critical reporting, database-specific migrations, vendor-mandated queries
- When deny-by-default can be relaxed: Public-facing read-only endpoints with explicit annotation
- When direct file access is permitted: Build scripts, CLI tools, infrastructure automation
- Classify exceptions by approval level:
- Review-required: Peer review with documented justification in code comment
- Approval-required: Tech lead or security team sign-off with ADR
- Prohibited: No exception allowed (e.g., SQL concatenation with user input)
- Use
assets/architecture_decision_record_template.md to document each decision
- Output: Common layer design + exception policy document
Workflow 6: Operational Rule Deployment (ルール運用化)
Convert standards into enforceable, operational rules.
- Load
references/static_rule_design_guide.md for rule design guidance
- Create static analysis rule candidates:
- Use
assets/static_rule_candidate_template.md for each rule
- Classify by tool suitability: lint, semgrep, regex, custom AST checker
- Assess false positive risk and design suppression mechanisms
- Create coding standard document entries:
- Rule ID, severity, rationale, examples (good and bad)
- Link to corresponding safe pattern and forbidden pattern
- Create review checklist addendum:
- Checklist items that map to each safe default
- Explicit connection to
critical-code-reviewer skill checkpoints
- Plan rollout strategy:
- Phase 1: Warning-only rules on new code
- Phase 2: Error-level rules on new code
- Phase 3: Codebase-wide enforcement with legacy migration
- Output: Static rule candidates + coding standard entries + review checklist + rollout plan
Resources
| Resource |
Type |
Purpose |
When to Load |
references/safe_pattern_catalog.md |
Reference |
Safe patterns by category (query, auth, file, datetime, etc.) |
Workflow 1, 3 |
references/forbidden_patterns.md |
Reference |
Forbidden patterns with danger classification and alternatives |
Workflow 2, 3 |
references/boundary_hardening_guide.md |
Reference |
Boundary-specific hardening techniques (controller, API, DB, file, time, env) |
Workflow 4 |
references/static_rule_design_guide.md |
Reference |
Lint/semgrep/regex rule design, false positive reduction |
Workflow 6 |
references/exception_policy.md |
Reference |
Exception conditions, approval levels, documentation requirements |
Workflow 5 |
assets/safe_standard_template.md |
Template |
Per-rule documentation (forbidden/approved/abstraction/test/review) |
Workflow 3 |
assets/forbidden_to_safe_mapping_template.md |
Template |
Anti-pattern to safe replacement mapping table |
Workflow 3 |
assets/static_rule_candidate_template.md |
Template |
Static analysis rule specification |
Workflow 6 |
assets/architecture_decision_record_template.md |
Template |
ADR for safe default decisions and exceptions |
Workflow 5 |
Best Practices
Safe Defaults Philosophy
- Make the safe way the easy way: If the safe pattern requires more code or effort than the dangerous one, adoption will fail. Design wrappers and abstractions that are more convenient than raw access.
- Forbid, do not discourage: "Prefer ORM" is ignored; "Raw SQL triggers CI failure" is enforced. Use enforcement mechanisms, not suggestions.
- Pair every prohibition with an alternative: A forbidden pattern list without approved alternatives creates frustration and workarounds. Every "don't" needs a "do this instead."
Incremental Adoption
- Start with the highest-frequency, highest-impact patterns (typically 3-5 rules cover 80% of recurring defects)
- Roll out as warnings first, then errors, then codebase-wide enforcement
- Provide migration tooling or codemods for existing violations
- Track adoption metrics: violation count over time, exception request frequency
Exception Governance
- Exceptions are expected and healthy; zero exceptions usually means the rules are too loose
- Every exception must be documented in code (comment with justification) and tracked (ADR or ticket)
- Distinguish between "review-required" (peer review suffices) and "approval-required" (tech lead/security sign-off)
- Periodically review exception patterns; frequent exceptions to the same rule may indicate the rule needs refinement
Connection to Review Process
- Safe default rules should map directly to
critical-code-reviewer checklist items
- Reviewers should verify not just correctness but also standard compliance
- Automated checks should run before human review to reduce reviewer burden
- Review findings that reveal new unsafe patterns should feed back into Workflow 1
Static Rule Quality
- Prioritize precision over recall: a rule with many false positives will be disabled
- Design rules that are auto-fixable when possible (provide the safe replacement automatically)
- Include suppression mechanisms with mandatory justification comments
- Test rules against the existing codebase before enabling enforcement
1---2name: safe-by-default-architect3description: 再発しやすい危険な実装パターンを、安全側に倒れる標準パターン・禁止事項・共通層・静的ルール候補へ 変換するスキル。ORM強制、deny-by-default認可、サービス経由I/O、永続化確認後の成功表示などを設計する。 レビューで危険コードを見つけるのではなく、危険コードを書きにくくする設計標準を作ることが目的。 Use when turning repeated defect patterns into safe architectural defaults, forbidden-to-safe mapping tables, common layer designs, and enforceable static analysis rules.4---56# Safe By Default Architect78## Overview910This skill converts recurring dangerous implementation patterns into safe architectural defaults and enforceable standards. Rather than catching unsafe code during review, it designs the codebase so that **the safe way is the easy way** and the dangerous way requires deliberate effort.1112The core philosophy: **If a developer can accidentally write dangerous code, the architecture has failed.**1314**Scope Boundary**: This skill designs standards, abstractions, and rules. For reviewing existing code against those standards, use `critical-code-reviewer`. For investigating incidents caused by unsafe patterns, use `incident-rca-specialist`.1516## When to Use1718- Repeated defects of the same class appear across multiple PRs or services19- Raw SQL, opt-in authorization, or direct file path construction appears in controller/route layers20- No common service layer exists for cross-cutting concerns (auth, file I/O, datetime handling)21- You need to convert RCA findings into enforceable coding standards22- Static analysis rules (lint/semgrep/custom checks) need to be designed23- A "forbidden patterns" list needs to be paired with approved alternatives24- Architecture Decision Records need to codify safe defaults25- A new project or module needs safe-by-default foundations from day one2627## Inputs2829- RCA reports, bug tickets, or critical review findings30- Coding guidelines and architecture documents (if any)31- Technology stack information (language, framework, ORM, tooling)32- Static analysis / lint configuration (if any)33- Relevant code fragments showing dangerous patterns3435## Outputs36371. **Safe Pattern Catalog** -- approved patterns per category with rationale382. **Forbidden Pattern List** -- anti-patterns with danger classification and alternatives393. **Common Layer Design** -- shared services and abstraction recommendations404. **Static Rule Candidate List** -- lint/semgrep rule proposals with false positive assessment415. **Exception Handling Rule** -- when and how to approve deviations426. **Review Checklist Addendum** -- additions to existing code review checklists4344## Prerequisites4546- **Defect/RCA data available**: Bug reports, RCA findings, or review findings that reveal recurring unsafe patterns47- **Technology stack identified**: Language, framework, ORM, and tooling context48- **Existing standards accessible**: Current coding guidelines, lint configuration, and architecture documents (if any)49- **Stakeholder alignment**: Agreement that architectural enforcement is needed (not just documentation)5051## Workflows5253### Workflow 1: Recurring Pattern Aggregation (再発パターン集約)5455Collect and consolidate recurring dangerous patterns from defect data.56571. Gather inputs: RCA reports, bug tickets, critical review findings, security scan results582. Extract each distinct dangerous pattern with:59 - **Pattern name**: Short identifier (e.g., "raw-sql-concatenation")60 - **Frequency**: How often this pattern has caused issues61 - **Example code**: Representative code snippet from actual incidents62 - **Affected components**: Which modules, layers, or services are impacted633. Deduplicate patterns that are variations of the same root issue644. Load `references/safe_pattern_catalog.md` and check if existing safe patterns cover the identified dangers655. Output: Consolidated pattern inventory (aim for 10-30 distinct patterns)6667### Workflow 2: Danger Classification (危険理由分類)6869Classify each dangerous pattern by its threat mechanism.70711. Load `references/forbidden_patterns.md` for the classification taxonomy722. Assign each pattern to one or more danger categories:73 - **Injection / Bypass / Traversal**: Attacker-controlled input reaches sensitive operations74 - **Silent Corruption**: Data is modified or lost without error or notification75 - **Environment Divergence**: Behavior differs between dev/staging/production76 - **Hidden Dependency**: Implicit coupling that breaks under change77 - **Human Error Amplification**: Design makes mistakes easy and recovery hard78 - **Unverifiable Behavior**: Cannot confirm correctness through testing alone793. Rank patterns by: `frequency x blast_radius x detection_difficulty`804. Identify patterns that span multiple danger categories (highest priority)815. Output: Classified and ranked danger inventory8283### Workflow 3: Safe Standard Definition (標準パターン定義)8485Define the approved safe replacement for each forbidden pattern.86871. Load `references/safe_pattern_catalog.md` for reference patterns882. For each dangerous pattern, define:89 - **Forbidden practice**: What is explicitly prohibited90 - **Approved pattern**: The safe alternative developers must use91 - **Required abstraction**: Common layer, wrapper, or service that enforces safety92 - **Minimum contract test**: The test that proves the safe pattern is used93 - **Static rule candidate**: How to detect violations automatically94 - **Review checkpoint**: What reviewers must verify953. Use `assets/safe_standard_template.md` to document each standard964. Use `assets/forbidden_to_safe_mapping_template.md` to create the mapping table975. Validate that every forbidden pattern has a concrete, usable alternative9899### Workflow 4: Safe Default Decision (安全デフォルト決定)100101Establish the project-wide safe defaults that apply universally.1021031. Load `references/boundary_hardening_guide.md` for boundary-specific guidance1042. Define safe defaults for each boundary:105 - **Query construction**: ORM / parameterized queries only; raw SQL prohibited by default106 - **Authorization**: Deny-by-default; every endpoint requires explicit permission grant107 - **File operations**: Service-layer abstraction only; no direct path construction108 - **Persistence confirmation**: UI success message only after persistence is confirmed109 - **DateTime handling**: UTC-aware normalization at persistence boundary110 - **Row/data access**: Named/object access preferred; positional access prohibited111 - **Dependency loading**: Explicit injection; no implicit service locator or global state112 - **Idempotency**: All write operations must be idempotent or explicitly marked non-idempotent1133. For each default, document:114 - The default behavior (what happens when developer does nothing special)115 - The escape hatch (how to override when genuinely needed)116 - The enforcement mechanism (lint rule, wrapper API, framework constraint)1174. Output: Safe defaults specification document118119### Workflow 5: Common Layer and Exception Design (共通層+例外条件)120121Design the shared infrastructure that makes safe defaults easy and define exception policies.1221231. Load `references/exception_policy.md` for exception handling guidance1242. Design common layer placement:125 - Which abstraction layer hosts each safe wrapper (middleware, service, repository, utility)126 - Interface contracts that enforce safe usage127 - Extension points for legitimate edge cases1283. Define exception conditions:129 - **When raw SQL is allowed**: Performance-critical reporting, database-specific migrations, vendor-mandated queries130 - **When deny-by-default can be relaxed**: Public-facing read-only endpoints with explicit annotation131 - **When direct file access is permitted**: Build scripts, CLI tools, infrastructure automation1324. Classify exceptions by approval level:133 - **Review-required**: Peer review with documented justification in code comment134 - **Approval-required**: Tech lead or security team sign-off with ADR135 - **Prohibited**: No exception allowed (e.g., SQL concatenation with user input)1365. Use `assets/architecture_decision_record_template.md` to document each decision1376. Output: Common layer design + exception policy document138139### Workflow 6: Operational Rule Deployment (ルール運用化)140141Convert standards into enforceable, operational rules.1421431. Load `references/static_rule_design_guide.md` for rule design guidance1442. Create static analysis rule candidates:145 - Use `assets/static_rule_candidate_template.md` for each rule146 - Classify by tool suitability: lint, semgrep, regex, custom AST checker147 - Assess false positive risk and design suppression mechanisms1483. Create coding standard document entries:149 - Rule ID, severity, rationale, examples (good and bad)150 - Link to corresponding safe pattern and forbidden pattern1514. Create review checklist addendum:152 - Checklist items that map to each safe default153 - Explicit connection to `critical-code-reviewer` skill checkpoints1545. Plan rollout strategy:155 - Phase 1: Warning-only rules on new code156 - Phase 2: Error-level rules on new code157 - Phase 3: Codebase-wide enforcement with legacy migration1586. Output: Static rule candidates + coding standard entries + review checklist + rollout plan159160## Resources161162| Resource | Type | Purpose | When to Load |163|----------|------|---------|--------------|164| `references/safe_pattern_catalog.md` | Reference | Safe patterns by category (query, auth, file, datetime, etc.) | Workflow 1, 3 |165| `references/forbidden_patterns.md` | Reference | Forbidden patterns with danger classification and alternatives | Workflow 2, 3 |166| `references/boundary_hardening_guide.md` | Reference | Boundary-specific hardening techniques (controller, API, DB, file, time, env) | Workflow 4 |167| `references/static_rule_design_guide.md` | Reference | Lint/semgrep/regex rule design, false positive reduction | Workflow 6 |168| `references/exception_policy.md` | Reference | Exception conditions, approval levels, documentation requirements | Workflow 5 |169| `assets/safe_standard_template.md` | Template | Per-rule documentation (forbidden/approved/abstraction/test/review) | Workflow 3 |170| `assets/forbidden_to_safe_mapping_template.md` | Template | Anti-pattern to safe replacement mapping table | Workflow 3 |171| `assets/static_rule_candidate_template.md` | Template | Static analysis rule specification | Workflow 6 |172| `assets/architecture_decision_record_template.md` | Template | ADR for safe default decisions and exceptions | Workflow 5 |173174## Best Practices175176### Safe Defaults Philosophy177178- **Make the safe way the easy way**: If the safe pattern requires more code or effort than the dangerous one, adoption will fail. Design wrappers and abstractions that are more convenient than raw access.179- **Forbid, do not discourage**: "Prefer ORM" is ignored; "Raw SQL triggers CI failure" is enforced. Use enforcement mechanisms, not suggestions.180- **Pair every prohibition with an alternative**: A forbidden pattern list without approved alternatives creates frustration and workarounds. Every "don't" needs a "do this instead."181182### Incremental Adoption183184- Start with the highest-frequency, highest-impact patterns (typically 3-5 rules cover 80% of recurring defects)185- Roll out as warnings first, then errors, then codebase-wide enforcement186- Provide migration tooling or codemods for existing violations187- Track adoption metrics: violation count over time, exception request frequency188189### Exception Governance190191- Exceptions are expected and healthy; zero exceptions usually means the rules are too loose192- Every exception must be documented in code (comment with justification) and tracked (ADR or ticket)193- Distinguish between "review-required" (peer review suffices) and "approval-required" (tech lead/security sign-off)194- Periodically review exception patterns; frequent exceptions to the same rule may indicate the rule needs refinement195196### Connection to Review Process197198- Safe default rules should map directly to `critical-code-reviewer` checklist items199- Reviewers should verify not just correctness but also standard compliance200- Automated checks should run before human review to reduce reviewer burden201- Review findings that reveal new unsafe patterns should feed back into Workflow 1202203### Static Rule Quality204205- Prioritize precision over recall: a rule with many false positives will be disabled206- Design rules that are auto-fixable when possible (provide the safe replacement automatically)207- Include suppression mechanisms with mandatory justification comments208- Test rules against the existing codebase before enabling enforcement