guardian-framework 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +463 -0
  3. package/dist/cli.js +12958 -0
  4. package/dist/exports.js +12765 -0
  5. package/package.json +61 -0
  6. package/templates/languages/go-patterns.md +411 -0
  7. package/templates/languages/java-patterns.md +545 -0
  8. package/templates/languages/python-patterns.md +312 -0
  9. package/templates/languages/rust-patterns.md +232 -0
  10. package/templates/languages/typescript-patterns.md +313 -0
  11. package/templates/pi/INDEX.md +437 -0
  12. package/templates/pi/agent/AGENTS.md +166 -0
  13. package/templates/pi/agents/architecture-coordinator.md +40 -0
  14. package/templates/pi/agents/architecture-validator.md +36 -0
  15. package/templates/pi/agents/bootstrap-implementer.md +37 -0
  16. package/templates/pi/agents/issue-factory.md +31 -0
  17. package/templates/pi/agents/operations-validator.md +32 -0
  18. package/templates/pi/agents/security-validator.md +33 -0
  19. package/templates/pi/architecture/CHANGELOG.md +78 -0
  20. package/templates/pi/architecture/decisions/ADR-template.md +76 -0
  21. package/templates/pi/architecture/diagrams/system-overview.md +159 -0
  22. package/templates/pi/architecture/modules/module-template.md +152 -0
  23. package/templates/pi/context/checklists.md +91 -0
  24. package/templates/pi/context/domain-workflow.md +180 -0
  25. package/templates/pi/context/output-formats.md +135 -0
  26. package/templates/pi/context/patterns-base.md +47 -0
  27. package/templates/pi/context/patterns.md +38 -0
  28. package/templates/pi/context/project.md +88 -0
  29. package/templates/pi/domain/exploration.md +93 -0
  30. package/templates/pi/domain/ubiquitous-language.md +24 -0
  31. package/templates/pi/extensions/architect-lib/generators.ts +528 -0
  32. package/templates/pi/extensions/architect-lib/helpers.ts +344 -0
  33. package/templates/pi/extensions/architect-lib/types.ts +117 -0
  34. package/templates/pi/extensions/architect.ts +1425 -0
  35. package/templates/pi/extensions/ask-user-question.ts +579 -0
  36. package/templates/pi/extensions/bash-guard.ts +556 -0
  37. package/templates/pi/extensions/config-reload.ts +115 -0
  38. package/templates/pi/extensions/coordinator.ts +304 -0
  39. package/templates/pi/extensions/curator.ts +543 -0
  40. package/templates/pi/extensions/domain-explorer.ts +990 -0
  41. package/templates/pi/extensions/filechanges.ts +656 -0
  42. package/templates/pi/extensions/goal-loop.ts +717 -0
  43. package/templates/pi/extensions/hooks.ts +452 -0
  44. package/templates/pi/extensions/kanban.ts +547 -0
  45. package/templates/pi/extensions/pipeline.ts +1246 -0
  46. package/templates/pi/extensions/plan-mode.ts +209 -0
  47. package/templates/pi/extensions/project-scaffolder.ts +284 -0
  48. package/templates/pi/extensions/read-only-mode.ts +192 -0
  49. package/templates/pi/extensions/redaction.ts +128 -0
  50. package/templates/pi/extensions/session-persistence.ts +174 -0
  51. package/templates/pi/extensions/slash-commands.ts +229 -0
  52. package/templates/pi/extensions/snippets.ts +201 -0
  53. package/templates/pi/extensions/validation-runner.ts +100 -0
  54. package/templates/pi/github/agents/architecture-coordinator.agent.md +27 -0
  55. package/templates/pi/github/agents/architecture-validator.agent.md +20 -0
  56. package/templates/pi/github/agents/bootstrap-implementer.agent.md +20 -0
  57. package/templates/pi/github/agents/epic-planner.agent.md +70 -0
  58. package/templates/pi/github/agents/issue-factory.agent.md +20 -0
  59. package/templates/pi/github/agents/operations-validator.agent.md +20 -0
  60. package/templates/pi/github/agents/security-validator.agent.md +20 -0
  61. package/templates/pi/github/copilot/settings.json +16 -0
  62. package/templates/pi/github/copilot-instructions.md +155 -0
  63. package/templates/pi/github/instructions/architecture.instructions.md +71 -0
  64. package/templates/pi/github/instructions/validation.instructions.md +69 -0
  65. package/templates/pi/github/workflows/01-planning-workflow.md +75 -0
  66. package/templates/pi/github/workflows/02-issue-generation-workflow.md +69 -0
  67. package/templates/pi/github/workflows/03-implementation-workflow.md +80 -0
  68. package/templates/pi/github/workflows/04-validation-workflow.md +68 -0
  69. package/templates/pi/preflight_report.json +99 -0
  70. package/templates/pi/prompts/blueprint-update.md +262 -0
  71. package/templates/pi/prompts/blueprint-validate.md +218 -0
  72. package/templates/pi/prompts/bug-fix.md +50 -0
  73. package/templates/pi/prompts/ci-blueprint.md +131 -0
  74. package/templates/pi/prompts/context-refresh.md +258 -0
  75. package/templates/pi/prompts/epic-plan.md +356 -0
  76. package/templates/pi/prompts/epic-template.md +186 -0
  77. package/templates/pi/prompts/feature-development.md +131 -0
  78. package/templates/pi/prompts/git-issues.md +243 -0
  79. package/templates/pi/prompts/hotfix.md +71 -0
  80. package/templates/pi/prompts/issue-closeout.md +342 -0
  81. package/templates/pi/prompts/issue-draft.md +218 -0
  82. package/templates/pi/prompts/issue-implementation-series.md +173 -0
  83. package/templates/pi/prompts/issue-merge.md +372 -0
  84. package/templates/pi/prompts/issue-template-set.md +392 -0
  85. package/templates/pi/prompts/issue-template.md +207 -0
  86. package/templates/pi/prompts/pattern-extract.md +269 -0
  87. package/templates/pi/prompts/plan-to-issues.md +430 -0
  88. package/templates/pi/prompts/refactoring.md +82 -0
  89. package/templates/pi/prompts/scope-analyzer.md +254 -0
  90. package/templates/pi/prompts/sync-check.md +230 -0
  91. package/templates/pi/scripts/categorize-issues.sh +171 -0
  92. package/templates/pi/scripts/ci/check_architecture_conformance.sh +748 -0
  93. package/templates/pi/scripts/ci/check_planning_packet.py +228 -0
  94. package/templates/pi/scripts/ci/run_hardening_stages.sh +264 -0
  95. package/templates/pi/scripts/ci/run_preflight.sh +649 -0
  96. package/templates/pi/scripts/ci/run_stage.sh +193 -0
  97. package/templates/pi/scripts/ci/stage_docs_policy.sh +82 -0
  98. package/templates/pi/scripts/ci/stage_integration.sh +3 -0
  99. package/templates/pi/scripts/ci/stage_lint.sh +130 -0
  100. package/templates/pi/scripts/ci/stage_migration_verify.sh +3 -0
  101. package/templates/pi/scripts/ci/stage_package_build.sh +3 -0
  102. package/templates/pi/scripts/ci/stage_release_readiness.sh +3 -0
  103. package/templates/pi/scripts/ci/stage_remaining.sh +242 -0
  104. package/templates/pi/scripts/ci/stage_security.sh +3 -0
  105. package/templates/pi/scripts/ci/stage_static_analysis.sh +114 -0
  106. package/templates/pi/scripts/ci/stage_unit.sh +119 -0
  107. package/templates/pi/scripts/ci/validate_agent_output.py +181 -0
  108. package/templates/pi/scripts/ci/validate_agent_output.sh +243 -0
  109. package/templates/pi/scripts/create-feature-branch.sh +136 -0
  110. package/templates/pi/scripts/create-mr.sh +117 -0
  111. package/templates/pi/scripts/fetch-issues.sh +131 -0
  112. package/templates/pi/scripts/generate-architecture.sh +161 -0
  113. package/templates/pi/scripts/git/close-epic.sh +69 -0
  114. package/templates/pi/scripts/git/close-issue.sh +35 -0
  115. package/templates/pi/scripts/git/create-tracking-issue.sh +174 -0
  116. package/templates/pi/scripts/git/link-issue-to-epic.sh +51 -0
  117. package/templates/pi/scripts/git/update-tracking-issue.sh +66 -0
  118. package/templates/pi/scripts/languages/go/validate-architecture.sh +139 -0
  119. package/templates/pi/scripts/languages/go/validate-canonical.sh +129 -0
  120. package/templates/pi/scripts/languages/go/validate-ci.sh +132 -0
  121. package/templates/pi/scripts/languages/go/validate-integration.sh +156 -0
  122. package/templates/pi/scripts/languages/go/validate-operations.sh +146 -0
  123. package/templates/pi/scripts/languages/go/validate-security.sh +135 -0
  124. package/templates/pi/scripts/languages/go/validate-tests.sh +125 -0
  125. package/templates/pi/scripts/languages/java/validate-annotations.sh +185 -0
  126. package/templates/pi/scripts/languages/java/validate-architecture.sh +159 -0
  127. package/templates/pi/scripts/languages/java/validate-canonical.sh +114 -0
  128. package/templates/pi/scripts/languages/java/validate-ci.sh +269 -0
  129. package/templates/pi/scripts/languages/java/validate-integration.sh +149 -0
  130. package/templates/pi/scripts/languages/java/validate-operations.sh +142 -0
  131. package/templates/pi/scripts/languages/java/validate-security.sh +174 -0
  132. package/templates/pi/scripts/languages/java/validate-spring-architecture.sh +227 -0
  133. package/templates/pi/scripts/languages/java/validate-tests.sh +159 -0
  134. package/templates/pi/scripts/languages/python/validate-architecture.sh +99 -0
  135. package/templates/pi/scripts/languages/python/validate-canonical.sh +124 -0
  136. package/templates/pi/scripts/languages/python/validate-ci.sh +130 -0
  137. package/templates/pi/scripts/languages/python/validate-integration.sh +119 -0
  138. package/templates/pi/scripts/languages/python/validate-operations.sh +107 -0
  139. package/templates/pi/scripts/languages/python/validate-security.sh +68 -0
  140. package/templates/pi/scripts/languages/python/validate-tests.sh +102 -0
  141. package/templates/pi/scripts/languages/rust/validate-architecture.sh +188 -0
  142. package/templates/pi/scripts/languages/rust/validate-canonical.sh +146 -0
  143. package/templates/pi/scripts/languages/rust/validate-ci.sh +147 -0
  144. package/templates/pi/scripts/languages/rust/validate-integration.sh +149 -0
  145. package/templates/pi/scripts/languages/rust/validate-operations.sh +154 -0
  146. package/templates/pi/scripts/languages/rust/validate-security.sh +153 -0
  147. package/templates/pi/scripts/languages/rust/validate-tests.sh +150 -0
  148. package/templates/pi/scripts/languages/typescript/validate-architecture.sh +157 -0
  149. package/templates/pi/scripts/languages/typescript/validate-canonical.sh +135 -0
  150. package/templates/pi/scripts/languages/typescript/validate-ci.sh +244 -0
  151. package/templates/pi/scripts/languages/typescript/validate-integration.sh +166 -0
  152. package/templates/pi/scripts/languages/typescript/validate-operations.sh +162 -0
  153. package/templates/pi/scripts/languages/typescript/validate-security.sh +169 -0
  154. package/templates/pi/scripts/languages/typescript/validate-tests.sh +158 -0
  155. package/templates/pi/scripts/merge-mr.sh +95 -0
  156. package/templates/pi/scripts/mr-validation.sh +228 -0
  157. package/templates/pi/scripts/validate-architecture-readiness.sh +153 -0
  158. package/templates/pi/scripts/validate-architecture.sh +22 -0
  159. package/templates/pi/scripts/validate-canonical.sh +22 -0
  160. package/templates/pi/scripts/validate-ci.sh +37 -0
  161. package/templates/pi/scripts/validate-integration.sh +22 -0
  162. package/templates/pi/scripts/validate-operations.sh +22 -0
  163. package/templates/pi/scripts/validate-security.sh +22 -0
  164. package/templates/pi/scripts/validate-tests.sh +22 -0
  165. package/templates/pi/scripts/validate-ubiquitous-language.sh +291 -0
  166. package/templates/pi/scripts/validation-cache.sh +139 -0
  167. package/templates/pi/skills/agents/architecture-coordinator.md +178 -0
  168. package/templates/pi/skills/agents/architecture-generator.md +79 -0
  169. package/templates/pi/skills/agents/architecture-validator.md +74 -0
  170. package/templates/pi/skills/agents/ci-mr-validator.md +46 -0
  171. package/templates/pi/skills/agents/code-developer.md +76 -0
  172. package/templates/pi/skills/agents/commit.md +46 -0
  173. package/templates/pi/skills/agents/curator.md +71 -0
  174. package/templates/pi/skills/agents/debug.md +59 -0
  175. package/templates/pi/skills/agents/documentation-maintainer.md +36 -0
  176. package/templates/pi/skills/agents/goal-loop.md +125 -0
  177. package/templates/pi/skills/agents/hooks.md +122 -0
  178. package/templates/pi/skills/agents/integration-validator.md +35 -0
  179. package/templates/pi/skills/agents/issue-creator.md +75 -0
  180. package/templates/pi/skills/agents/issue-factory.md +143 -0
  181. package/templates/pi/skills/agents/kanban.md +85 -0
  182. package/templates/pi/skills/agents/land.md +59 -0
  183. package/templates/pi/skills/agents/operations-validator.md +43 -0
  184. package/templates/pi/skills/agents/pipeline.md +113 -0
  185. package/templates/pi/skills/agents/plan-mode.md +77 -0
  186. package/templates/pi/skills/agents/pull.md +40 -0
  187. package/templates/pi/skills/agents/push.md +41 -0
  188. package/templates/pi/skills/agents/security-validator.md +85 -0
  189. package/templates/pi/skills/agents/session-persistence.md +119 -0
  190. package/templates/pi/skills/agents/slash-commands.md +117 -0
  191. package/templates/pi/skills/agents/snippets.md +99 -0
  192. package/templates/pi/skills/agents/subagent-registry.md +78 -0
  193. package/templates/pi/skills/agents/test-validator.md +42 -0
  194. package/templates/pi/skills/validators/architecture-validator.md +43 -0
  195. package/templates/pi/skills/validators/ci-validator.md +27 -0
  196. package/templates/pi/skills/validators/context-compaction.md +73 -0
  197. package/templates/pi/skills/validators/integration-validator.md +38 -0
  198. package/templates/pi/skills/validators/model-registry.md +96 -0
  199. package/templates/pi/skills/validators/operations-validator.md +34 -0
  200. package/templates/pi/skills/validators/security-guards.md +72 -0
  201. package/templates/pi/skills/validators/security-validator.md +41 -0
  202. package/templates/pi/skills/validators/system-prompt-tiers.md +69 -0
  203. package/templates/pi/skills/validators/test-validator.md +33 -0
  204. package/templates/pi/types.ts +62 -0
  205. package/templates/pi/validators/README.md +93 -0
  206. package/templates/pi/validators/default.toml +209 -0
  207. package/templates/pi/validators/spring.toml +142 -0
  208. package/templates/pi/workpad.md +53 -0
  209. package/templates/project/java/Dockerfile +14 -0
  210. package/templates/project/java/README.md +40 -0
  211. package/templates/project/java/pom.xml +132 -0
  212. package/templates/project/typescript/Dockerfile +15 -0
  213. package/templates/project/typescript/README.md +29 -0
  214. package/templates/project/typescript/package.json +23 -0
  215. package/templates/project/typescript/tsconfig.json +21 -0
  216. package/templates/workflow.md +123 -0
@@ -0,0 +1,125 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-tests.sh — Go
4
+ # ============================================================================
5
+ set -euo pipefail
6
+
7
+ ERRORS=()
8
+ WARNINGS=()
9
+ PASS_COUNT=0
10
+
11
+ RED='\033[0;31m'
12
+ GREEN='\033[0;32m'
13
+ YELLOW='\033[1;33m'
14
+ NC='\033[0m'
15
+
16
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
17
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERRORS+=("$1"); }
18
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARNINGS+=("$1"); }
19
+
20
+ echo "============================================"
21
+ echo " Test Validation (Go)"
22
+ echo "============================================"
23
+ echo ""
24
+
25
+ # ---------------------------------------------------------------------------
26
+ # Unit Tests
27
+ # ---------------------------------------------------------------------------
28
+ echo "--- Unit Tests ---"
29
+ if [ -f "go.mod" ]; then
30
+ # Prefer internal/ and pkg/ if they exist; fall back to ./...
31
+ if [ -d "internal" ] || [ -d "pkg" ]; then
32
+ TEST_PATHS=""
33
+ [ -d "internal" ] && TEST_PATHS="./internal/..."
34
+ [ -d "pkg" ] && TEST_PATHS="${TEST_PATHS:+$TEST_PATHS }./pkg/..."
35
+ if go test ${TEST_PATHS} -count=1 -v 2>/dev/null; then
36
+ pass "Unit tests passed"
37
+ else
38
+ fail "Unit tests failed"
39
+ fi
40
+ else
41
+ if go test ./... -count=1 -v 2>/dev/null; then
42
+ pass "Unit tests passed"
43
+ else
44
+ fail "Unit tests failed"
45
+ fi
46
+ fi
47
+ else
48
+ pass "No go.mod (skipping unit tests)"
49
+ fi
50
+
51
+ # ---------------------------------------------------------------------------
52
+ # Integration Tests
53
+ # ---------------------------------------------------------------------------
54
+ echo ""
55
+ echo "--- Integration Tests ---"
56
+ if [ -f "go.mod" ]; then
57
+ HAS_INTEGRATION=false
58
+ if [ -d "tests/integration" ]; then
59
+ HAS_INTEGRATION=true
60
+ fi
61
+ # Also check for _test.go files with build tag "integration"
62
+ if grep -rl '//go:build integration' --include="*_test.go" . 2>/dev/null | grep -q .; then
63
+ HAS_INTEGRATION=true
64
+ fi
65
+ if [ "$HAS_INTEGRATION" = true ]; then
66
+ if go test -tags=integration ./... -count=1 -v 2>/dev/null; then
67
+ pass "Integration tests passed"
68
+ else
69
+ fail "Integration tests failed"
70
+ fi
71
+ else
72
+ pass "No integration tests found (skipped)"
73
+ fi
74
+ else
75
+ pass "No go.mod (skipping integration tests)"
76
+ fi
77
+
78
+ # ---------------------------------------------------------------------------
79
+ # Coverage
80
+ # ---------------------------------------------------------------------------
81
+ echo ""
82
+ echo "--- Coverage ---"
83
+ if [ -f "go.mod" ]; then
84
+ COVERAGE_OUTPUT=$(go test -coverprofile=coverage.out ./... 2>&1 || true)
85
+ if [ -f "coverage.out" ]; then
86
+ COVERAGE_PCT=$(go tool cover -func=coverage.out 2>/dev/null | grep "^total:" | awk '{print $3}' | tr -d '%' || echo "0")
87
+ if [ -z "$COVERAGE_PCT" ] || [ "$COVERAGE_PCT" = "0.0" ]; then
88
+ COVERAGE_PCT="0"
89
+ fi
90
+ # Compare coverage percentage (use awk for float comparison)
91
+ MEETS_THRESHOLD=$(echo "$COVERAGE_PCT" | awk '{if ($1 >= 80) print 1; else print 0}')
92
+ if [ "$MEETS_THRESHOLD" -eq 1 ]; then
93
+ pass "Coverage: ${COVERAGE_PCT}% (≥ 80%)"
94
+ else
95
+ fail "Coverage: ${COVERAGE_PCT}% (< 80%)"
96
+ fi
97
+ rm -f coverage.out
98
+ else
99
+ warn "No coverage output generated"
100
+ fi
101
+ else
102
+ warn "go.mod not found, skipping coverage"
103
+ fi
104
+
105
+ # ---------------------------------------------------------------------------
106
+ # Summary
107
+ # ---------------------------------------------------------------------------
108
+ echo ""
109
+ echo "============================================"
110
+ echo " Summary"
111
+ echo "============================================"
112
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
113
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
114
+ echo ""
115
+
116
+ if [ ${#ERRORS[@]} -gt 0 ]; then
117
+ echo "FAILURES:"
118
+ for err in "${ERRORS[@]}"; do
119
+ echo " - $err"
120
+ done
121
+ exit 1
122
+ fi
123
+
124
+ echo -e "${GREEN}Test validation passed.${NC}"
125
+ exit 0
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-annotations.sh — Spring Boot Annotation Enforcement
4
+ # ============================================================================
5
+ # Checks:
6
+ # 1. @Transactional on @Service public methods
7
+ # 2. @PostConstruct allowed only in service/config/component packages
8
+ # 3. Field injection (@Autowired on fields) — constructor injection required
9
+ # 4. Layering: web/ must not import repository/ directly
10
+ # 5. Package naming: enforce com.{project}.{layer}.{component}
11
+ # ============================================================================
12
+ set -euo pipefail
13
+
14
+ PASS_COUNT=0; ERRORS=(); WARNINGS=()
15
+ RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
16
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
17
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERRORS+=("$1"); }
18
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARNINGS+=("$1"); }
19
+
20
+ echo "============================================"
21
+ echo " Spring Annotation Validation"
22
+ echo "============================================"
23
+ echo ""
24
+
25
+ SRC_DIR="${1:-src/main/java}"
26
+
27
+ # ============================================================================
28
+ # Check 1: @Transactional on @Service public methods
29
+ # ============================================================================
30
+ echo "--- @Transactional Coverage ---"
31
+ if [ -d "$SRC_DIR" ]; then
32
+ SERVICE_FILES=$(find "$SRC_DIR" -name "*.java" -exec grep -l "@Service" {} \; 2>/dev/null)
33
+ if [ -n "$SERVICE_FILES" ]; then
34
+ MISSING_TRANSACTIONAL=0
35
+ for f in $SERVICE_FILES; do
36
+ # Find public methods in @Service classes
37
+ PUBLIC_METHODS=$(grep -c "public\s" "$f" 2>/dev/null || echo "0")
38
+ TRANSACTIONAL_METHODS=$(grep -c "@Transactional" "$f" 2>/dev/null || echo "0")
39
+ if [ "$PUBLIC_METHODS" -gt 0 ] && [ "$TRANSACTIONAL_METHODS" -eq 0 ]; then
40
+ warn "Service class without @Transactional: $f ($PUBLIC_METHODS public methods, 0 @Transactional)"
41
+ MISSING_TRANSACTIONAL=$((MISSING_TRANSACTIONAL + 1))
42
+ fi
43
+ done
44
+ if [ "$MISSING_TRANSACTIONAL" -eq 0 ]; then
45
+ pass "All @Service classes have @Transactional annotations"
46
+ else
47
+ fail "$MISSING_TRANSACTIONAL @Service classes missing @Transactional"
48
+ fi
49
+ else
50
+ pass "No @Service classes found, skipping @Transactional check"
51
+ fi
52
+ else
53
+ pass "No source directory found, skipping @Transactional check"
54
+ fi
55
+
56
+ # ============================================================================
57
+ # Check 2: @PostConstruct placement
58
+ # ============================================================================
59
+ echo ""
60
+ echo "--- @PostConstruct Placement ---"
61
+ if [ -d "$SRC_DIR" ]; then
62
+ PC_IN_CONTROLLER=$(grep -r "@PostConstruct" "$SRC_DIR" --include="*.java" -l 2>/dev/null | xargs grep -l "@RestController\|@Controller" 2>/dev/null || true)
63
+ if [ -n "$PC_IN_CONTROLLER" ]; then
64
+ for f in $PC_IN_CONTROLLER; do
65
+ fail "@PostConstruct found in controller: $f (only allowed in service/config/component)"
66
+ done
67
+ else
68
+ pass "No @PostConstruct found in controller classes"
69
+ fi
70
+
71
+ # Also check @PostConstruct is in valid packages
72
+ PC_FILES=$(grep -r "@PostConstruct" "$SRC_DIR" --include="*.java" -l 2>/dev/null || true)
73
+ if [ -n "$PC_FILES" ]; then
74
+ for f in $PC_FILES; do
75
+ if echo "$f" | grep -qE "(/service/|/config/|/component/)"; then
76
+ : # Valid location
77
+ else
78
+ warn "@PostConstruct in unexpected package: $f (expected service/config/component)"
79
+ fi
80
+ done
81
+ fi
82
+ else
83
+ pass "No source directory found, skipping @PostConstruct check"
84
+ fi
85
+
86
+ # ============================================================================
87
+ # Check 3: Field injection (@Autowired on fields)
88
+ # ============================================================================
89
+ echo ""
90
+ echo "--- Field Injection Detection ---"
91
+ if [ -d "$SRC_DIR" ]; then
92
+ FIELD_AUTOWIRED=$(grep -rn "@Autowired" "$SRC_DIR" --include="*.java" 2>/dev/null || true)
93
+ CONSTRUCTOR_AUTOWIRED=$(grep -rn "@Autowired" "$SRC_DIR" --include="*.java" -B1 2>/dev/null | grep -E "\s*(public|protected|private)\s+\w+\(" || true)
94
+
95
+ if [ -n "$FIELD_AUTOWIRED" ]; then
96
+ # Count field-level @Autowired (not constructor)
97
+ FIELD_COUNT=$(echo "$FIELD_AUTOWIRED" | wc -l | tr -d ' ')
98
+ CONSTRUCTOR_COUNT=$(grep -rn "@Autowired\s*$" "$SRC_DIR" --include="*.java" 2>/dev/null | grep -v "//\|/\*" | wc -l | tr -d ' ')
99
+
100
+ # Heuristic: more field injections than constructor injections
101
+ if [ "$FIELD_COUNT" -gt "$CONSTRUCTOR_COUNT" ]; then
102
+ fail "Field-level @Autowired found ($FIELD_COUNT occurrences) — prefer constructor injection"
103
+ else
104
+ warn "Field-level @Autowired found ($FIELD_COUNT occurrences) — review for constructor injection migration"
105
+ fi
106
+ else
107
+ pass "No field-level @Autowired found (constructor injection used)"
108
+ fi
109
+ else
110
+ pass "No source directory found, skipping field injection check"
111
+ fi
112
+
113
+ # ============================================================================
114
+ # Check 4: Layering — web/ must not import repository/
115
+ # ============================================================================
116
+ echo ""
117
+ echo "--- Layering Violations ---"
118
+ WEB_DIRS=$(find "$SRC_DIR" -type d -name "web" -o -type d -name "controller" -o -type d -name "interfaces" 2>/dev/null)
119
+ if [ -n "$WEB_DIRS" ]; then
120
+ VIOLATIONS=0
121
+ for webdir in $WEB_DIRS; do
122
+ REPO_IMPORTS=$(grep -r "import.*\.repository\.\|import.*\.infrastructure\." "$webdir" --include="*.java" 2>/dev/null || true)
123
+ if [ -n "$REPO_IMPORTS" ]; then
124
+ fail "Web layer imports repository/infrastructure directly:"
125
+ echo "$REPO_IMPORTS"
126
+ VIOLATIONS=$((VIOLATIONS + 1))
127
+ fi
128
+ done
129
+ if [ "$VIOLATIONS" -eq 0 ]; then
130
+ pass "Web layer has no direct repository imports (correct layering)"
131
+ fi
132
+ else
133
+ pass "No web/controller directory found, skipping layering check"
134
+ fi
135
+
136
+ # ============================================================================
137
+ # Check 5: Package naming convention
138
+ # ============================================================================
139
+ echo ""
140
+ echo "--- Package Naming Convention ---"
141
+ if [ -d "$SRC_DIR" ]; then
142
+ BAD_PACKAGE_FILES=0
143
+ for f in $(find "$SRC_DIR" -name "*.java" 2>/dev/null); do
144
+ # Check if package declaration follows com.{project}.{layer}.{component}
145
+ PACKAGE_DECL=$(grep "^package " "$f" 2>/dev/null || true)
146
+ if [ -n "$PACKAGE_DECL" ]; then
147
+ # Must start with a domain that has at least 3 parts (com.example.layer)
148
+ if echo "$PACKAGE_DECL" | grep -qE "^package\s+[a-z][a-z0-9]*(\.[a-z][a-z0-9]*){2,};$"; then
149
+ : # Good package structure: com.example.layer
150
+ elif echo "$PACKAGE_DECL" | grep -qE "^package\s+org\.[a-z]|[a-z]+\.example"; then
151
+ : # Common patterns: org.example, com.example
152
+ else
153
+ warn "Unusual package naming in $f: $PACKAGE_DECL"
154
+ BAD_PACKAGE_FILES=$((BAD_PACKAGE_FILES + 1))
155
+ fi
156
+ fi
157
+ done
158
+ if [ "$BAD_PACKAGE_FILES" -eq 0 ]; then
159
+ pass "Package naming conventions look correct"
160
+ fi
161
+ else
162
+ pass "No source directory found, skipping package naming check"
163
+ fi
164
+
165
+ # ============================================================================
166
+ # Summary
167
+ # ============================================================================
168
+ echo ""
169
+ echo "============================================"
170
+ echo " Summary"
171
+ echo "============================================"
172
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
173
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
174
+ echo ""
175
+
176
+ if [ ${#ERRORS[@]} -gt 0 ]; then
177
+ echo "FAILURES:"
178
+ for err in "${ERRORS[@]}"; do
179
+ echo " - $err"
180
+ done
181
+ exit 1
182
+ fi
183
+
184
+ echo -e "${GREEN}Spring annotation validation passed.${NC}"
185
+ exit 0
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-architecture.sh — Java (Spring Boot Clean Architecture)
4
+ # ============================================================================
5
+ set -euo pipefail
6
+
7
+ PASS_COUNT=0; ERRORS=(); WARNINGS=()
8
+ RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
9
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
10
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERRORS+=("$1"); }
11
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARNINGS+=("$1"); }
12
+
13
+ echo "============================================"
14
+ echo " Architecture Validation (Java)"
15
+ echo "============================================"
16
+ echo ""
17
+
18
+ SRC_DIR="${1:-src/main/java}"
19
+
20
+ ARCH_MODE="strict"
21
+ if [ -f "guardian-manifest.json" ]; then
22
+ ARCH_MODE=$(jq -r '.archMode // "strict"' guardian-manifest.json 2>/dev/null || echo "strict")
23
+ fi
24
+
25
+ # ---------------------------------------------------------------------------
26
+ # Layer Structure
27
+ # ---------------------------------------------------------------------------
28
+ echo "--- Layer Structure ---"
29
+ if [ -d "$SRC_DIR" ]; then
30
+ # Check for Clean Architecture layers
31
+ HAS_DOMAIN=$(find "$SRC_DIR" -type d -name "domain" 2>/dev/null | head -1)
32
+ HAS_APPLICATION=$(find "$SRC_DIR" -type d -name "application" 2>/dev/null | head -1)
33
+ HAS_INFRASTRUCTURE=$(find "$SRC_DIR" -type d -name "infrastructure" 2>/dev/null | head -1)
34
+ HAS_WEB=$(find "$SRC_DIR" -type d -name "web" -o -type d -name "interfaces" 2>/dev/null | head -1)
35
+
36
+ LAYER_COUNT=0
37
+ [ -n "$HAS_DOMAIN" ] && LAYER_COUNT=$((LAYER_COUNT + 1))
38
+ [ -n "$HAS_APPLICATION" ] && LAYER_COUNT=$((LAYER_COUNT + 1))
39
+ [ -n "$HAS_INFRASTRUCTURE" ] && LAYER_COUNT=$((LAYER_COUNT + 1))
40
+
41
+ if [ "$LAYER_COUNT" -ge 3 ]; then
42
+ pass "Clean Architecture layers present ($LAYER_COUNT of 3)"
43
+ elif [ "$LAYER_COUNT" -ge 1 ]; then
44
+ pass "Some architecture layers present ($LAYER_COUNT of 3)"
45
+ else
46
+ warn "No Clean Architecture layers found in $SRC_DIR"
47
+ fi
48
+ else
49
+ warn "No source directory found at $SRC_DIR"
50
+ fi
51
+
52
+ # ---------------------------------------------------------------------------
53
+ # Package Naming Convention
54
+ # ---------------------------------------------------------------------------
55
+ echo ""
56
+ echo "--- Package Naming ---"
57
+ if [ -d "$SRC_DIR" ]; then
58
+ PACKAGE_DIRS=$(find "$SRC_DIR" -type d -mindepth 3 2>/dev/null | head -5)
59
+ if [ -n "$PACKAGE_DIRS" ]; then
60
+ BAD_NAMES=0
61
+ for dir in $(find "$SRC_DIR" -type d 2>/dev/null); do
62
+ BASENAME=$(basename "$dir")
63
+ if echo "$BASENAME" | grep -qE '^[a-z]+$'; then
64
+ : # valid package name
65
+ elif [ "$BASENAME" = "java" ] || [ "$BASENAME" = "main" ] || [ "$BASENAME" = "src" ]; then
66
+ : # standard directory names
67
+ else
68
+ BAD_NAMES=$((BAD_NAMES + 1))
69
+ fi
70
+ done
71
+ if [ "$BAD_NAMES" -eq 0 ]; then
72
+ pass "Package naming convention looks correct"
73
+ else
74
+ warn "Some directory names may not follow Java package conventions"
75
+ fi
76
+ else
77
+ pass "No deep package structure to validate"
78
+ fi
79
+ else
80
+ warn "No source directory found"
81
+ fi
82
+
83
+ # ---------------------------------------------------------------------------
84
+ # Canonical References
85
+ # ---------------------------------------------------------------------------
86
+ echo ""
87
+ echo "--- Canonical References ---"
88
+ if [ -d ".pi/architecture/modules" ]; then
89
+ MODULE_COUNT=$(find .pi/architecture/modules -name "*.md" 2>/dev/null | wc -l | tr -d ' ')
90
+ pass "Canonical architecture documents found ($MODULE_COUNT modules)"
91
+ else
92
+ warn "No .pi/architecture/modules directory found"
93
+ fi
94
+
95
+ # ---------------------------------------------------------------------------
96
+ # Dependency Direction
97
+ # ---------------------------------------------------------------------------
98
+ echo ""
99
+ echo "--- Dependency Direction ---"
100
+ if [ -n "$HAS_DOMAIN" ]; then
101
+ # Domain must NOT import infrastructure or web
102
+ DOMAIN_BAD_IMPORTS=0
103
+ for f in $(find "$HAS_DOMAIN" -name "*.java" 2>/dev/null); do
104
+ if grep -qE "import\s+.*\.infrastructure\." "$f" 2>/dev/null || grep -qE "import\s+.*\.web\." "$f" 2>/dev/null; then
105
+ if [ "$ARCH_MODE" = "strict" ]; then
106
+ fail "Domain layer imports from infrastructure/web: $f"
107
+ else
108
+ warn "Domain layer imports from infrastructure/web: $f (allowed in simplified mode)"
109
+ fi
110
+ DOMAIN_BAD_IMPORTS=$((DOMAIN_BAD_IMPORTS + 1))
111
+ fi
112
+ done
113
+ if [ "$DOMAIN_BAD_IMPORTS" -eq 0 ]; then
114
+ pass "Domain layer has no infrastructure or web imports"
115
+ fi
116
+ else
117
+ pass "No domain directory, skipping dependency direction check"
118
+ fi
119
+
120
+ # ---------------------------------------------------------------------------
121
+ # Spring Boot Specific
122
+ # ---------------------------------------------------------------------------
123
+ echo ""
124
+ echo "--- Spring Boot Structure ---"
125
+ SPRING_BOOT_APP=$(find "$SRC_DIR" -name "*Application.java" 2>/dev/null | head -1)
126
+ if [ -n "$SPRING_BOOT_APP" ]; then
127
+ pass "Spring Boot main application class found: $(basename "$SPRING_BOOT_APP")"
128
+ else
129
+ warn "No *Application.java Spring Boot entry point found"
130
+ fi
131
+
132
+ CONFIG_FILES=$(find . -name "application.yml" -o -name "application.yaml" -o -name "application.properties" 2>/dev/null | head -5)
133
+ if [ -n "$CONFIG_FILES" ]; then
134
+ pass "Spring Boot configuration files found ($(echo "$CONFIG_FILES" | wc -l | tr -d ' ') files)"
135
+ else
136
+ warn "No Spring Boot configuration files found (application.yml/properties)"
137
+ fi
138
+
139
+ # ---------------------------------------------------------------------------
140
+ # Summary
141
+ # ---------------------------------------------------------------------------
142
+ echo ""
143
+ echo "============================================"
144
+ echo " Summary"
145
+ echo "============================================"
146
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
147
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
148
+ echo ""
149
+
150
+ if [ ${#ERRORS[@]} -gt 0 ]; then
151
+ echo "FAILURES:"
152
+ for err in "${ERRORS[@]}"; do
153
+ echo " - $err"
154
+ done
155
+ exit 1
156
+ fi
157
+
158
+ echo -e "${GREEN}Architecture validation passed.${NC}"
159
+ exit 0
@@ -0,0 +1,114 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # validate-canonical.sh — Java (language-agnostic, same pattern as others)
4
+ # ============================================================================
5
+ set -euo pipefail
6
+
7
+ PASS_COUNT=0; ERRORS=(); WARNINGS=()
8
+ RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[1;33m'; NC='\033[0m'
9
+ pass() { echo -e "${GREEN}✅ PASS${NC} $1"; PASS_COUNT=$((PASS_COUNT + 1)); }
10
+ fail() { echo -e "${RED}❌ FAIL${NC} $1"; ERRORS+=("$1"); }
11
+ warn() { echo -e "${YELLOW}⚠️ WARN${NC} $1"; WARNINGS+=("$1"); }
12
+
13
+ echo "============================================"
14
+ echo " Canonical Reference Validation (Java)"
15
+ echo "============================================"
16
+ echo ""
17
+
18
+ SRC_DIR="${1:-src/main/java}"
19
+
20
+ # ---------------------------------------------------------------------------
21
+ # Architecture Module References
22
+ # ---------------------------------------------------------------------------
23
+ echo "--- Architecture Module References ---"
24
+ if [ -d ".pi/architecture/modules" ]; then
25
+ MODULE_FILES=$(find .pi/architecture/modules -name "*.md" -not -name "module-template.md" 2>/dev/null)
26
+ MODULE_COUNT=$(echo "$MODULE_FILES" | wc -l | tr -d ' ')
27
+ if [ "$MODULE_COUNT" -gt 0 ]; then
28
+ pass "Architecture module docs found ($MODULE_COUNT modules)"
29
+ else
30
+ warn "No architecture module docs found"
31
+ fi
32
+ else
33
+ warn "No .pi/architecture/modules directory found"
34
+ fi
35
+
36
+ # ---------------------------------------------------------------------------
37
+ # Implementation File References
38
+ # ---------------------------------------------------------------------------
39
+ echo ""
40
+ echo "--- Implementation File References ---"
41
+ if [ -d "$SRC_DIR" ]; then
42
+ JAVA_FILES=$(find "$SRC_DIR" -name "*.java" 2>/dev/null | wc -l | tr -d ' ')
43
+ if [ "$JAVA_FILES" -gt 0 ]; then
44
+ # Check for canonical reference headers in Java files
45
+ WITH_REFS=0
46
+ for f in $(find "$SRC_DIR" -name "*.java" 2>/dev/null); do
47
+ if grep -q "Canonical Reference\|Canonical Reference:" "$f" 2>/dev/null; then
48
+ WITH_REFS=$((WITH_REFS + 1))
49
+ fi
50
+ done
51
+ if [ "$WITH_REFS" -gt 0 ]; then
52
+ pass "$WITH_REFS of $JAVA_FILES Java files have canonical reference headers"
53
+ else
54
+ fail "No canonical reference headers found in Java source files"
55
+ fi
56
+ else
57
+ pass "No Java source files found"
58
+ fi
59
+ else
60
+ warn "No source directory found, skipping implementation reference check"
61
+ fi
62
+
63
+ # ---------------------------------------------------------------------------
64
+ # README References
65
+ # ---------------------------------------------------------------------------
66
+ echo ""
67
+ echo "--- README / Documentation References ---"
68
+ if [ -f "README.md" ]; then
69
+ if grep -qi "architecture\|canonical\|reference" README.md 2>/dev/null; then
70
+ pass "README.md references architecture documentation"
71
+ else
72
+ warn "README.md does not reference architecture documentation"
73
+ fi
74
+ else
75
+ warn "No README.md found"
76
+ fi
77
+
78
+ # ---------------------------------------------------------------------------
79
+ # ADR References
80
+ # ---------------------------------------------------------------------------
81
+ echo ""
82
+ echo "--- ADR References ---"
83
+ if [ -d ".pi/architecture/decisions" ]; then
84
+ ADR_COUNT=$(find .pi/architecture/decisions -name "*.md" -not -name "ADR-template.md" 2>/dev/null | wc -l | tr -d ' ')
85
+ if [ "$ADR_COUNT" -gt 0 ]; then
86
+ pass "Architecture Decision Records found ($ADR_COUNT ADRs)"
87
+ else
88
+ warn "No ADRs found in .pi/architecture/decisions/"
89
+ fi
90
+ else
91
+ warn "No .pi/architecture/decisions/ directory found"
92
+ fi
93
+
94
+ # ---------------------------------------------------------------------------
95
+ # Summary
96
+ # ---------------------------------------------------------------------------
97
+ echo ""
98
+ echo "============================================"
99
+ echo " Summary"
100
+ echo "============================================"
101
+ echo -e " Passed: ${GREEN}${PASS_COUNT}${NC}"
102
+ echo -e " Failed: ${RED}${#ERRORS[@]}${NC}"
103
+ echo ""
104
+
105
+ if [ ${#ERRORS[@]} -gt 0 ]; then
106
+ echo "FAILURES:"
107
+ for err in "${ERRORS[@]}"; do
108
+ echo " - $err"
109
+ done
110
+ exit 1
111
+ fi
112
+
113
+ echo -e "${GREEN}Canonical reference validation passed.${NC}"
114
+ exit 0