Compliance Patterns
Common patterns for checking code compliance with Architectural Decision Records.
Technology Selection Compliance
Section titled “Technology Selection Compliance”Database Technology Checks
Section titled “Database Technology Checks”ADR Type: “Use {database} for data storage”
Grep Patterns:
# PostgreSQL compliance (should find)grep -r "pg\|postgres\|psycopg\|node-postgres" src/
# MySQL violation detection (should not find)grep -r "mysql\|mysql2\|pymysql" src/
# MongoDB violation detectiongrep -r "mongoose\|mongodb\|pymongo" src/Import Patterns:
// Compliantimport { Pool } from 'pg';import postgres from 'postgres';
// Violationimport mysql from 'mysql2';import { MongoClient } from 'mongodb';Message Queue Checks
Section titled “Message Queue Checks”ADR Type: “Use {queue} for async messaging”
Patterns for Kafka compliance:
# Should find Kafka usagegrep -r "kafkajs\|node-rdkafka\|kafka-python" src/
# Should NOT find alternativesgrep -r "amqplib\|rabbitmq\|bullmq\|aws-sdk.*sqs" src/Cache Technology Checks
Section titled “Cache Technology Checks”ADR Type: “Use Redis for caching”
# Should find Redisgrep -r "redis\|ioredis\|redis-py" src/
# Should NOT find alternativesgrep -r "memcached\|node-cache\|lru-cache" src/Pattern Adoption Compliance
Section titled “Pattern Adoption Compliance”Event-Driven Architecture
Section titled “Event-Driven Architecture”ADR Type: “Adopt event-driven architecture”
Compliance indicators:
# Event publishing (good)grep -r "emit\|publish\|dispatch.*event\|EventEmitter" src/
# Direct service calls (potential violation)grep -r "fetch\|axios\|http\.request" src/services/Code structure checks:
// Compliant - event-based communicationeventBus.publish('OrderCreated', order);await eventEmitter.emit('PaymentProcessed', payment);
// Violation - direct synchronous callconst result = await paymentService.process(order);const user = await userService.getById(userId);Microservices Boundaries
Section titled “Microservices Boundaries”ADR Type: “Services must not share databases”
# Check for cross-service database imports# Each service should only import its own db configgrep -r "import.*from.*other-service.*db" src/API Design Patterns
Section titled “API Design Patterns”ADR Type: “Use REST conventions for APIs”
# Should find RESTful patternsgrep -r "@Get\|@Post\|@Put\|@Delete\|router\.(get|post|put|delete)" src/
# GraphQL usage (violation if REST mandated)grep -r "graphql\|@Query\|@Mutation\|gql\`" src/Constraint Compliance
Section titled “Constraint Compliance”Authentication Requirements
Section titled “Authentication Requirements”ADR Type: “All external APIs must require authentication”
Check for unprotected endpoints:
# Find route definitionsgrep -rn "router\.\(get\|post\|put\|delete\)" src/routes/
# Check each has auth middlewaregrep -B2 "router\.\(get\|post\|put\|delete\)" src/routes/ | grep -v "authMiddleware\|requireAuth\|@Authorized"Decorator/middleware patterns:
// Compliant@UseGuards(AuthGuard)@Get('users')async getUsers() {}
// Violation - no auth guard@Get('public-data')async getPublicData() {}Input Validation
Section titled “Input Validation”ADR Type: “All API inputs must be validated”
# Check for validation decorators/middlewaregrep -r "@IsString\|@IsNumber\|@ValidateNested\|Joi\.object\|zod\.object" src/
# Find endpoints without validationgrep -rn "@Body()\|req\.body" src/ | grep -v "ValidationPipe\|validate"Error Handling
Section titled “Error Handling”ADR Type: “Use structured error responses”
# Check for consistent error patternsgrep -r "throw new.*Error\|res\.status.*json" src/
# Look for raw throws without wrappinggrep -r "throw new Error\(" src/ | grep -v "AppError\|HttpException\|ApiError"Security Compliance
Section titled “Security Compliance”Secrets Management
Section titled “Secrets Management”ADR Type: “No hardcoded secrets”
# Check for potential hardcoded secretsgrep -rn "password\s*=\s*['\"]" src/grep -rn "api[_-]?key\s*=\s*['\"]" src/grep -rn "secret\s*=\s*['\"]" src/
# Should use environment variablesgrep -r "process\.env\.\|os\.environ\|config\." src/SQL Injection Prevention
Section titled “SQL Injection Prevention”ADR Type: “Use parameterized queries”
# Potential SQL injection (string concatenation)grep -rn "query.*\+.*\+" src/grep -rn "execute.*f['\"]" src/ # Python f-strings in queries
# Compliant patternsgrep -r "\$1\|\$2\|:param\|?" src/ # Parameterized placeholdersCORS Configuration
Section titled “CORS Configuration”ADR Type: “Restrict CORS to approved origins”
# Check for overly permissive CORSgrep -r "origin:\s*['\"]?\*['\"]?" src/grep -r "Access-Control-Allow-Origin.*\*" src/Architecture Layer Compliance
Section titled “Architecture Layer Compliance”Layer Dependency Rules
Section titled “Layer Dependency Rules”ADR Type: “Controllers must not directly access repositories”
# Controllers should use services, not repositoriesgrep -r "import.*Repository" src/controllers/
# Services can use repositories (compliant)grep -r "import.*Repository" src/services/Import Path Rules
Section titled “Import Path Rules”# Check for violations of layer boundaries# UI should not import from data layergrep -r "import.*from.*data\|import.*from.*repository" src/ui/
# Domain should not import from infrastructuregrep -r "import.*from.*infrastructure" src/domain/Compliance Report Generation
Section titled “Compliance Report Generation”Summary Template
Section titled “Summary Template”## ADR Compliance Check Results
**Date**: {date}**Commit**: {commit_hash}**Files Scanned**: {count}
### Summary
| ADR | Status | Violations ||-----|--------|------------|| ADR-001 | ✅ Compliant | 0 || ADR-002 | ⚠️ Warning | 2 || ADR-003 | ❌ Violation | 5 |
### Violations Detail
#### ADR-002: Use PostgreSQL
**Warning**: Found potential MySQL imports- `src/legacy/data.js:45` - `require('mysql')`- `src/migrations/old.js:12` - `import mysql from 'mysql2'`
**Recommendation**: Migrate legacy code to PostgreSQLAutomated Compliance Scripts
Section titled “Automated Compliance Scripts”Basic Compliance Checker
Section titled “Basic Compliance Checker”#!/bin/bashVIOLATIONS=0
echo "Checking ADR-001: PostgreSQL Usage"if grep -rq "mysql\|mongodb" src/; then echo "❌ VIOLATION: Non-PostgreSQL database found" VIOLATIONS=$((VIOLATIONS + 1))else echo "✅ Compliant"fi
echo "Checking ADR-002: Event-Driven Architecture"if grep -rq "direct.*service.*call" src/services/; then echo "⚠️ WARNING: Direct service calls found"fi
exit $VIOLATIONSCI Integration
Section titled “CI Integration”# GitHub Actions example- name: ADR Compliance Check run: | ./scripts/compliance-check.sh continue-on-error: false