🤖 Automated Architecture Checks
CASCADA provides automated tools to enforce strict architecture rules.
✅ Available Checks
1. Architecture Validator Script
Custom script that checks layer violations
pnpm check:architectureWhat it checks:
- ❌ PLATFORM importing from CORE
- ❌ PLATFORM importing from GAME
- ❌ CORE importing from GAME
Example output (violations found):
🔍 Checking architecture rules...
📦 Checking PLATFORM layer (1 files)...
📦 Checking CORE layer (16 files)...
📦 Checking GAME layer (10 files)...
============================================================
❌ Architecture violations found: 1
1. CORE → GAME
File: src/core/ui/UIManager.ts:15
Import: @game/scenes/TerritoryScene
✗ CORE cannot import from GAME (Core must be game-agnostic)
Fix these violations before committing!
See: docs/technical/strict-architecture.mdExample output (all good):
🔍 Checking architecture rules...
📦 Checking PLATFORM layer (1 files)...
📦 Checking CORE layer (16 files)...
📦 Checking GAME layer (10 files)...
============================================================
✅ Architecture check PASSED!
All layers respect hierarchy rules.2. ESLint with Import Rules
Uses eslint-plugin-import for static analysis
pnpm lint:eslintConfiguration in eslint.config.js (ESLint 9+):
export default [
{
files: ["src/**/*.{ts,tsx}"],
rules: {
// ⚠️ Enforce strict architecture
"import/no-restricted-paths": [
"error",
{
zones: [
{
target: "./src/platform",
from: "./src/core",
message: "PLATFORM cannot import from CORE",
},
{
target: "./src/core",
from: "./src/game",
message: "CORE cannot import from GAME",
},
],
},
],
},
},
];Catches violations at lint time:
- IDE integration (VS Code shows errors)
- CI/CD integration
- Real-time feedback
3. Combined Lint Check
Runs architecture check + TypeScript check
pnpm lintThis runs:
pnpm check:architecture- layer violationstsc --noEmit- TypeScript errors
Use before committing!
🪝 Git Pre-Commit Hook
Automatic check on every commit
Husky runs architecture validation automatically:
# Pre-commit hook (.husky/pre-commit)
pnpm check:architecture || exit 1How it works:
# You commit
git commit -m "Add new feature"
# Hook runs automatically
🔍 Checking architecture rules...
📦 Checking PLATFORM layer...
📦 Checking CORE layer...
📦 Checking GAME layer...
# If violations found:
❌ Architecture violations found!
Commit BLOCKED!
# If all good:
✅ Architecture check passed!
Commit proceeds ✅You CANNOT commit code that violates architecture!
📋 Manual Checks (No Tools)
Quick Grep Checks
# Check PLATFORM for violations
grep -r "@core\|@game" src/platform/
# Should return: (nothing)
# Check CORE for violations
grep -r "@game" src/core/
# Should return: (nothing)
# If anything found → VIOLATION!Visual Studio Code
Install Dependency Cruiser extension:
pnpm install -g dependency-cruiserCreate .dependency-cruiser.js:
module.exports = {
forbidden: [
{
name: "platform-no-core",
from: { path: "^src/platform" },
to: { path: "^src/core" },
comment: "Platform cannot depend on Core",
},
{
name: "platform-no-game",
from: { path: "^src/platform" },
to: { path: "^src/game" },
},
{
name: "core-no-game",
from: { path: "^src/core" },
to: { path: "^src/game" },
comment: "Core must be game-agnostic",
},
],
};Run:
depcruise --validate .dependency-cruiser.js src🎯 CI/CD Integration
GitHub Actions
# .github/workflows/check-architecture.yml
name: Architecture Check
on: [push, pull_request]
jobs:
architecture:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
node-version: "20"
cache: "pnpm"
- run: ppnpm install
- run: pnpm check:architecture
- name: Comment on PR if violations
if: failure()
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '❌ Architecture violations detected! See logs for details.'
})📊 What Gets Checked
File Analysis
For each .ts file in src/:
- Extract layer (platform/core/game)
- Parse imports (from statements)
- Check violations:
- Platform file imports
@core/*→ ❌ ERROR - Platform file imports
@game/*→ ❌ ERROR - Core file imports
@game/*→ ❌ ERROR - Game file imports anything → ✅ OK
- Platform file imports
Import Patterns Detected
// All these patterns are checked:
import { X } from "@core/ui/UIManager";
import { Y } from "@game/scenes/MyScene";
import { Z } from "../core/systems/GameModeManager";
import { A } from "../../game/config/game.config";
// Even relative imports are caught!🛠️ How the Script Works
Source: scripts/check-architecture.cjs
// 1. Find all .ts files in src/platform, src/core, src/game
const platformFiles = findTsFiles("src/platform");
const coreFiles = findTsFiles("src/core");
const gameFiles = findTsFiles("src/game");
// 2. For each file, extract layer
function getLayer(filePath) {
if (filePath.includes("/platform/")) return "platform";
if (filePath.includes("/core/")) return "core";
if (filePath.includes("/game/")) return "game";
}
// 3. Check import statements
lines.forEach((line) => {
const importMatch = line.match(/import.*from ["']([^"']+)["']/);
if (layer === "platform" && importPath.includes("@core/")) {
violations.push({
message: "PLATFORM cannot import from CORE",
});
}
// ... similar checks
});
// 4. Report violations or success
if (violations.length > 0) {
console.log("❌ Architecture violations found");
process.exit(1); // Blocks commit!
} else {
console.log("✅ All good");
process.exit(0);
}🎓 Usage Examples
Before Committing
# Manual check
pnpm check:architecture
# Full lint (includes architecture)
pnpm lint
# If violations → fix them!
# If passed → safe to commitDuring Development
# Watch mode (manual)
pnpm check:architecture
# Re-run after fixing imports
pnpm check:architectureIn CI/CD
# In your CI pipeline
ppnpm install
pnpm check:architecture # Fails pipeline if violations
pnpm lint # Includes architecture check
pnpm build🚨 Common Violations & Fixes
Violation 1: Config in Wrong Layer
❌ Found:
File: src/platform/game.config.ts
Import: @game/scenes/BootScene
✗ PLATFORM cannot import from GAMEFix:
# Move game.config.ts to game layer
mv src/platform/game.config.ts src/game/config/phaser.config.ts
# Update imports in main.ts
# Before: import { gameConfig } from "@platform/game.config";
# After: import { gameConfig } from "@game/config/phaser.config";Why: Game config with scene imports = game-specific → belongs in GAME layer.
Violation 2: Core Using Game Types
❌ Found:
File: src/core/systems/EntityRegistry.ts
Import: @game/types
✗ CORE cannot import from GAMEFix:
# Move shared types to Core
mv src/game/types/Entity.ts src/core/types/Entity.ts
# Or create Core version
# core/types/Entity.ts (generic)
# game/types/Player.ts extends Entity (specific)Violation 3: Utility in Wrong Place
❌ Found:
File: src/platform/utils/math.ts
Import: @core/config/constants
✗ PLATFORM cannot import from COREFix:
# Math utilities are universal → move to Core
mv src/platform/utils/math.ts src/core/utils/math.ts📖 Integration with Documentation
All architecture rules documented in:
- Strict Architecture Rules - Full guide
- Layer Hierarchy - Deep dive
- Architecture Overview - Philosophy
Automated checks enforce what documentation teaches.
🎯 Benefits
For Developers
✅ Catch violations early - before code review
✅ Learn architecture - errors teach correct patterns
✅ Confidence - know your code won't break architecture
✅ Fast feedback - check runs in <1 second
For Projects
✅ Enforce standards - automation never forgets
✅ Prevent regressions - can't accidentally break architecture
✅ Team alignment - everyone follows same rules
✅ Documentation stays accurate - code matches docs
For CI/CD
✅ Block bad PRs - violations fail CI
✅ Automatic checks - no manual review needed
✅ Fast pipeline - architecture check is quick
✅ Clear feedback - exact file and line numbers
🔧 Commands Reference
# Check architecture only
pnpm check:architecture
# Full lint (architecture + TypeScript)
pnpm lint
# ESLint check
pnpm lint:eslint
# Install git hooks
pnpm prepare
# Test pre-commit hook
git commit -m "test" --dry-run🚀 Summary
Architecture validation is AUTOMATED:
- ✅ Custom script (
check-architecture.cjs) - ✅ ESLint rules (
.eslintrc.json) - ✅ Pre-commit hook (
.husky/pre-commit) - ✅ Integrated in
pnpm lint - ✅ Ready for CI/CD
You can't break architecture by accident anymore! 🎯