qualia-framework 2.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 (261) hide show
  1. package/README.md +50 -0
  2. package/bin/cli.js +519 -0
  3. package/framework/agents/architecture-strategist.md +53 -0
  4. package/framework/agents/backend-agent.md +150 -0
  5. package/framework/agents/code-simplicity-reviewer.md +86 -0
  6. package/framework/agents/frontend-agent.md +111 -0
  7. package/framework/agents/kieran-typescript-reviewer.md +96 -0
  8. package/framework/agents/performance-oracle.md +111 -0
  9. package/framework/agents/qualia-codebase-mapper.md +760 -0
  10. package/framework/agents/qualia-debugger.md +1203 -0
  11. package/framework/agents/qualia-executor.md +881 -0
  12. package/framework/agents/qualia-integration-checker.md +423 -0
  13. package/framework/agents/qualia-phase-researcher.md +453 -0
  14. package/framework/agents/qualia-plan-checker.md +699 -0
  15. package/framework/agents/qualia-planner.md +1241 -0
  16. package/framework/agents/qualia-project-researcher.md +602 -0
  17. package/framework/agents/qualia-research-synthesizer.md +236 -0
  18. package/framework/agents/qualia-roadmapper.md +605 -0
  19. package/framework/agents/qualia-verifier.md +685 -0
  20. package/framework/agents/team-orchestrator.md +228 -0
  21. package/framework/agents/teams/full-stack-team.md +48 -0
  22. package/framework/agents/teams/optimize-team.md +53 -0
  23. package/framework/agents/teams/review-team.md +62 -0
  24. package/framework/agents/teams/ship-team.md +86 -0
  25. package/framework/agents/test-agent.md +182 -0
  26. package/framework/askpass.sh +2 -0
  27. package/framework/commands/design.md +53 -0
  28. package/framework/commands/quick-db.md +22 -0
  29. package/framework/config/retention.json +35 -0
  30. package/framework/core/PRINCIPLES.md +77 -0
  31. package/framework/hooks/auto-format.sh +45 -0
  32. package/framework/hooks/block-env-edit.sh +42 -0
  33. package/framework/hooks/branch-guard.sh +46 -0
  34. package/framework/hooks/confirm-delete.sh +56 -0
  35. package/framework/hooks/migration-validate.sh +68 -0
  36. package/framework/hooks/notification-speak.sh +15 -0
  37. package/framework/hooks/pre-commit.sh +80 -0
  38. package/framework/hooks/pre-compact.sh +55 -0
  39. package/framework/hooks/pre-deploy-gate.sh +151 -0
  40. package/framework/hooks/qualia-colors.sh +32 -0
  41. package/framework/hooks/retention-cleanup.sh +43 -0
  42. package/framework/hooks/save-session-state.sh +153 -0
  43. package/framework/hooks/session-context-loader.sh +28 -0
  44. package/framework/hooks/session-learn.sh +30 -0
  45. package/framework/knowledge/claudecode-bible.md +1384 -0
  46. package/framework/knowledge/client-prefs.md +22 -0
  47. package/framework/knowledge/common-fixes.md +25 -0
  48. package/framework/knowledge/deployment-map.md +35 -0
  49. package/framework/knowledge/email-signature.html +1 -0
  50. package/framework/knowledge/employees.md +8 -0
  51. package/framework/knowledge/learned-patterns.md +51 -0
  52. package/framework/knowledge/optimization-research-2026.md +137 -0
  53. package/framework/knowledge/qualia-context.md +67 -0
  54. package/framework/knowledge/supabase-patterns.md +50 -0
  55. package/framework/knowledge/voice-agent-patterns.md +46 -0
  56. package/framework/qualia-engine/VERSION +1 -0
  57. package/framework/qualia-engine/bin/qualia-tools.js +2160 -0
  58. package/framework/qualia-engine/bin/qualia-tools.test.js +1054 -0
  59. package/framework/qualia-engine/references/checkpoints.md +775 -0
  60. package/framework/qualia-engine/references/continuation-format.md +249 -0
  61. package/framework/qualia-engine/references/decimal-phase-calculation.md +65 -0
  62. package/framework/qualia-engine/references/design-quality.md +56 -0
  63. package/framework/qualia-engine/references/git-integration.md +254 -0
  64. package/framework/qualia-engine/references/git-planning-commit.md +50 -0
  65. package/framework/qualia-engine/references/model-profile-resolution.md +32 -0
  66. package/framework/qualia-engine/references/model-profiles.md +73 -0
  67. package/framework/qualia-engine/references/phase-argument-parsing.md +61 -0
  68. package/framework/qualia-engine/references/planning-config.md +195 -0
  69. package/framework/qualia-engine/references/questioning.md +141 -0
  70. package/framework/qualia-engine/references/tdd.md +263 -0
  71. package/framework/qualia-engine/references/ui-brand.md +160 -0
  72. package/framework/qualia-engine/references/verification-patterns.md +612 -0
  73. package/framework/qualia-engine/templates/DEBUG.md +159 -0
  74. package/framework/qualia-engine/templates/DESIGN.md +81 -0
  75. package/framework/qualia-engine/templates/UAT.md +247 -0
  76. package/framework/qualia-engine/templates/codebase/architecture.md +255 -0
  77. package/framework/qualia-engine/templates/codebase/concerns.md +310 -0
  78. package/framework/qualia-engine/templates/codebase/conventions.md +307 -0
  79. package/framework/qualia-engine/templates/codebase/integrations.md +280 -0
  80. package/framework/qualia-engine/templates/codebase/stack.md +186 -0
  81. package/framework/qualia-engine/templates/codebase/structure.md +285 -0
  82. package/framework/qualia-engine/templates/codebase/testing.md +480 -0
  83. package/framework/qualia-engine/templates/config.json +35 -0
  84. package/framework/qualia-engine/templates/context.md +283 -0
  85. package/framework/qualia-engine/templates/continue-here.md +78 -0
  86. package/framework/qualia-engine/templates/debug-subagent-prompt.md +91 -0
  87. package/framework/qualia-engine/templates/discovery.md +146 -0
  88. package/framework/qualia-engine/templates/milestone-archive.md +123 -0
  89. package/framework/qualia-engine/templates/milestone.md +115 -0
  90. package/framework/qualia-engine/templates/phase-prompt.md +567 -0
  91. package/framework/qualia-engine/templates/planner-subagent-prompt.md +117 -0
  92. package/framework/qualia-engine/templates/project.md +184 -0
  93. package/framework/qualia-engine/templates/projects/ai-agent.md +156 -0
  94. package/framework/qualia-engine/templates/projects/mobile-app.md +181 -0
  95. package/framework/qualia-engine/templates/projects/voice-agent.md +134 -0
  96. package/framework/qualia-engine/templates/projects/website.md +137 -0
  97. package/framework/qualia-engine/templates/requirements.md +231 -0
  98. package/framework/qualia-engine/templates/research-project/ARCHITECTURE.md +204 -0
  99. package/framework/qualia-engine/templates/research-project/FEATURES.md +147 -0
  100. package/framework/qualia-engine/templates/research-project/PITFALLS.md +200 -0
  101. package/framework/qualia-engine/templates/research-project/STACK.md +120 -0
  102. package/framework/qualia-engine/templates/research-project/SUMMARY.md +170 -0
  103. package/framework/qualia-engine/templates/research.md +552 -0
  104. package/framework/qualia-engine/templates/roadmap.md +202 -0
  105. package/framework/qualia-engine/templates/state.md +176 -0
  106. package/framework/qualia-engine/templates/summary-complex.md +59 -0
  107. package/framework/qualia-engine/templates/summary-minimal.md +41 -0
  108. package/framework/qualia-engine/templates/summary-standard.md +48 -0
  109. package/framework/qualia-engine/templates/summary.md +246 -0
  110. package/framework/qualia-engine/templates/user-setup.md +311 -0
  111. package/framework/qualia-engine/templates/verification-report.md +322 -0
  112. package/framework/qualia-engine/workflows/add-phase.md +179 -0
  113. package/framework/qualia-engine/workflows/add-todo.md +157 -0
  114. package/framework/qualia-engine/workflows/audit-milestone.md +241 -0
  115. package/framework/qualia-engine/workflows/check-todos.md +176 -0
  116. package/framework/qualia-engine/workflows/complete-milestone.md +858 -0
  117. package/framework/qualia-engine/workflows/diagnose-issues.md +219 -0
  118. package/framework/qualia-engine/workflows/discovery-phase.md +289 -0
  119. package/framework/qualia-engine/workflows/discuss-phase.md +534 -0
  120. package/framework/qualia-engine/workflows/execute-phase.md +559 -0
  121. package/framework/qualia-engine/workflows/execute-plan.md +438 -0
  122. package/framework/qualia-engine/workflows/help.md +470 -0
  123. package/framework/qualia-engine/workflows/insert-phase.md +220 -0
  124. package/framework/qualia-engine/workflows/list-phase-assumptions.md +178 -0
  125. package/framework/qualia-engine/workflows/map-codebase.md +327 -0
  126. package/framework/qualia-engine/workflows/new-milestone.md +363 -0
  127. package/framework/qualia-engine/workflows/new-project.md +1037 -0
  128. package/framework/qualia-engine/workflows/pause-work.md +122 -0
  129. package/framework/qualia-engine/workflows/plan-milestone-gaps.md +256 -0
  130. package/framework/qualia-engine/workflows/plan-phase.md +422 -0
  131. package/framework/qualia-engine/workflows/progress.md +354 -0
  132. package/framework/qualia-engine/workflows/quick.md +252 -0
  133. package/framework/qualia-engine/workflows/remove-phase.md +326 -0
  134. package/framework/qualia-engine/workflows/research-phase.md +74 -0
  135. package/framework/qualia-engine/workflows/resume-project.md +306 -0
  136. package/framework/qualia-engine/workflows/set-profile.md +80 -0
  137. package/framework/qualia-engine/workflows/settings.md +145 -0
  138. package/framework/qualia-engine/workflows/transition.md +556 -0
  139. package/framework/qualia-engine/workflows/update.md +197 -0
  140. package/framework/qualia-engine/workflows/verify-phase.md +195 -0
  141. package/framework/qualia-engine/workflows/verify-work.md +625 -0
  142. package/framework/rules/context7.md +11 -0
  143. package/framework/rules/deployment.md +29 -0
  144. package/framework/rules/frontend.md +33 -0
  145. package/framework/rules/security.md +12 -0
  146. package/framework/rules/speed.md +20 -0
  147. package/framework/scripts/__pycache__/say.cpython-314.pyc +0 -0
  148. package/framework/scripts/apply-retention.sh +120 -0
  149. package/framework/scripts/bootstrap-pop-os.sh +354 -0
  150. package/framework/scripts/claude-voice +13 -0
  151. package/framework/scripts/cleanup.sh +131 -0
  152. package/framework/scripts/cowork-mode.sh +141 -0
  153. package/framework/scripts/generate-project-claude-md.sh +153 -0
  154. package/framework/scripts/load-test-webhook.js +172 -0
  155. package/framework/scripts/say.py +236 -0
  156. package/framework/scripts/showcase-video-recorder/ffmpeg-builder.js +167 -0
  157. package/framework/scripts/showcase-video-recorder/playwright-helpers.js +216 -0
  158. package/framework/scripts/speak.py +55 -0
  159. package/framework/scripts/speak.sh +18 -0
  160. package/framework/scripts/status.sh +138 -0
  161. package/framework/scripts/sync-to-framework.sh +65 -0
  162. package/framework/scripts/voice-hotkey.py +227 -0
  163. package/framework/scripts/voice-input.sh +51 -0
  164. package/framework/skills/animate/SKILL.md +202 -0
  165. package/framework/skills/bolder/SKILL.md +144 -0
  166. package/framework/skills/browser-qa/SKILL.md +536 -0
  167. package/framework/skills/clarify/SKILL.md +179 -0
  168. package/framework/skills/colorize/SKILL.md +170 -0
  169. package/framework/skills/critique/SKILL.md +126 -0
  170. package/framework/skills/deep-research/SKILL.md +271 -0
  171. package/framework/skills/delight/SKILL.md +329 -0
  172. package/framework/skills/deploy/SKILL.md +261 -0
  173. package/framework/skills/deploy-verify/SKILL.md +377 -0
  174. package/framework/skills/deploy-verify/scripts/canary-check.sh +206 -0
  175. package/framework/skills/deploy-verify/scripts/check-console-errors.js +147 -0
  176. package/framework/skills/deploy-verify/scripts/check-cwv.js +139 -0
  177. package/framework/skills/deploy-verify/scripts/project-detect.sh +84 -0
  178. package/framework/skills/deploy-verify/scripts/verify.sh +548 -0
  179. package/framework/skills/design-quieter/SKILL.md +130 -0
  180. package/framework/skills/distill/SKILL.md +149 -0
  181. package/framework/skills/docs-lookup/SKILL.md +78 -0
  182. package/framework/skills/fcm-notifications/SKILL.md +125 -0
  183. package/framework/skills/financial-ledger/SKILL.md +1039 -0
  184. package/framework/skills/frontend-master/NOTICE.md +4 -0
  185. package/framework/skills/frontend-master/SKILL.md +127 -0
  186. package/framework/skills/frontend-master/reference/color-and-contrast.md +132 -0
  187. package/framework/skills/frontend-master/reference/interaction-design.md +123 -0
  188. package/framework/skills/frontend-master/reference/motion-design.md +99 -0
  189. package/framework/skills/frontend-master/reference/responsive-design.md +114 -0
  190. package/framework/skills/frontend-master/reference/spatial-design.md +100 -0
  191. package/framework/skills/frontend-master/reference/typography.md +131 -0
  192. package/framework/skills/frontend-master/reference/ux-writing.md +107 -0
  193. package/framework/skills/harden/SKILL.md +357 -0
  194. package/framework/skills/i18n-rtl/SKILL.md +752 -0
  195. package/framework/skills/learn/SKILL.md +71 -0
  196. package/framework/skills/memory/SKILL.md +50 -0
  197. package/framework/skills/mobile-expo/SKILL.md +864 -0
  198. package/framework/skills/mobile-expo/references/store-checklist.md +550 -0
  199. package/framework/skills/nestjs-backend/README.md +73 -0
  200. package/framework/skills/nestjs-backend/SKILL.md +446 -0
  201. package/framework/skills/nestjs-backend/references/templates.md +1173 -0
  202. package/framework/skills/normalize/SKILL.md +79 -0
  203. package/framework/skills/onboard/SKILL.md +242 -0
  204. package/framework/skills/polish/SKILL.md +209 -0
  205. package/framework/skills/pr/SKILL.md +66 -0
  206. package/framework/skills/qualia/SKILL.md +153 -0
  207. package/framework/skills/qualia-add-todo/SKILL.md +68 -0
  208. package/framework/skills/qualia-audit-milestone/SKILL.md +92 -0
  209. package/framework/skills/qualia-check-todos/SKILL.md +55 -0
  210. package/framework/skills/qualia-complete-milestone/SKILL.md +108 -0
  211. package/framework/skills/qualia-debug/SKILL.md +149 -0
  212. package/framework/skills/qualia-design/SKILL.md +203 -0
  213. package/framework/skills/qualia-discuss-phase/SKILL.md +72 -0
  214. package/framework/skills/qualia-execute-phase/SKILL.md +86 -0
  215. package/framework/skills/qualia-help/SKILL.md +67 -0
  216. package/framework/skills/qualia-idk/SKILL.md +352 -0
  217. package/framework/skills/qualia-list-phase-assumptions/SKILL.md +67 -0
  218. package/framework/skills/qualia-new-milestone/SKILL.md +72 -0
  219. package/framework/skills/qualia-new-project/SKILL.md +92 -0
  220. package/framework/skills/qualia-optimize/SKILL.md +417 -0
  221. package/framework/skills/qualia-pause-work/SKILL.md +96 -0
  222. package/framework/skills/qualia-plan-milestone-gaps/SKILL.md +57 -0
  223. package/framework/skills/qualia-plan-phase/SKILL.md +101 -0
  224. package/framework/skills/qualia-progress/SKILL.md +53 -0
  225. package/framework/skills/qualia-quick/SKILL.md +89 -0
  226. package/framework/skills/qualia-research-phase/SKILL.md +88 -0
  227. package/framework/skills/qualia-resume-work/SKILL.md +62 -0
  228. package/framework/skills/qualia-review/SKILL.md +263 -0
  229. package/framework/skills/qualia-start/SKILL.md +182 -0
  230. package/framework/skills/qualia-verify-work/SKILL.md +105 -0
  231. package/framework/skills/qualia-workflow/SKILL.md +130 -0
  232. package/framework/skills/rag/SKILL.md +750 -0
  233. package/framework/skills/responsive/SKILL.md +231 -0
  234. package/framework/skills/retro/SKILL.md +284 -0
  235. package/framework/skills/sakani-conventions/SKILL.md +136 -0
  236. package/framework/skills/sakani-conventions/evals/evals.json +23 -0
  237. package/framework/skills/sakani-conventions/references/entities.md +365 -0
  238. package/framework/skills/sakani-conventions/references/error-codes.md +95 -0
  239. package/framework/skills/seo-master/SKILL.md +490 -0
  240. package/framework/skills/seo-master/references/checklist.md +199 -0
  241. package/framework/skills/seo-master/references/structured-data.md +609 -0
  242. package/framework/skills/ship/SKILL.md +202 -0
  243. package/framework/skills/stack-researcher/SKILL.md +215 -0
  244. package/framework/skills/status/SKILL.md +154 -0
  245. package/framework/skills/status/scripts/health-check.sh +562 -0
  246. package/framework/skills/subscription-payments/SKILL.md +250 -0
  247. package/framework/skills/supabase/SKILL.md +973 -0
  248. package/framework/skills/supabase/references/templates.md +159 -0
  249. package/framework/skills/team/SKILL.md +67 -0
  250. package/framework/skills/test-runner/SKILL.md +202 -0
  251. package/framework/skills/voice-agent/SKILL.md +407 -0
  252. package/framework/skills/zoho-workflow/SKILL.md +51 -0
  253. package/framework/statusline-command.sh +117 -0
  254. package/package.json +24 -0
  255. package/profiles/fawzi.json +16 -0
  256. package/profiles/hasan.json +16 -0
  257. package/profiles/moayad.json +16 -0
  258. package/templates/CLAUDE-owner.md +52 -0
  259. package/templates/CLAUDE.md.hbs +58 -0
  260. package/templates/env.claude.template +12 -0
  261. package/templates/settings.json +141 -0
@@ -0,0 +1,365 @@
1
+ # Sakani Entity Reference
2
+
3
+ Complete entity definitions from SRS V1.14. This is the source of truth for schema design, API contracts, and type generation.
4
+
5
+ ## Conventions
6
+
7
+ - All IDs are UUIDs
8
+ - All tables have `id`, `created_at` (timestamptz, UTC), `updated_at` (timestamptz, UTC)
9
+ - Monetary fields: `{ amount: numeric, currency: text }` (ISO 4217)
10
+ - All timestamps stored UTC, presented Asia/Amman
11
+ - `request_id` correlation on every write operation
12
+
13
+ ---
14
+
15
+ ## Identity Domain
16
+
17
+ ### building
18
+ | Field | Type | Notes |
19
+ |-------|------|-------|
20
+ | id | uuid | PK |
21
+ | building_key_v1 | text | Canonical key for deterministic matching. UNIQUE. Never expose. |
22
+ | name_ar | text | Arabic building name |
23
+ | name_en | text | English building name |
24
+ | building_type | enum | RESIDENTIAL, COMMERCIAL, MIXED |
25
+ | address | jsonb | Structured address object |
26
+ | unit_count | integer | Number of units |
27
+ | subscription_status | enum | TRIAL, ACTIVE, INACTIVE |
28
+ | trial_expires_at | timestamptz | 30-day trial expiry |
29
+
30
+ ### building_contact
31
+ | Field | Type | Notes |
32
+ |-------|------|-------|
33
+ | building_id | uuid | FK → building |
34
+ | contact_type | enum | PHONE, EMAIL, ADDRESS |
35
+ | value | text | |
36
+
37
+ ### building_setup_request
38
+ | Field | Type | Notes |
39
+ |-------|------|-------|
40
+ | id | uuid | PK |
41
+ | requested_by | uuid | FK → auth.users |
42
+ | status | enum | PENDING, APPROVED, REJECTED, RETURNED_FOR_FIX |
43
+ | building_data | jsonb | Submitted building details |
44
+ | occupation_permit_document_id | uuid | FK → document |
45
+ | reviewed_by | uuid | FK → auth.users (staff) |
46
+ | review_notes | text | |
47
+ | rejection_reason_code | text | Stable identifier |
48
+
49
+ ### unit
50
+ | Field | Type | Notes |
51
+ |-------|------|-------|
52
+ | id | uuid | PK |
53
+ | building_id | uuid | FK → building |
54
+ | unit_key_v1 | text | Canonical key. UNIQUE per building. Never expose. |
55
+ | unit_number | text | Display number |
56
+ | floor | integer | |
57
+ | unit_type | enum | APARTMENT, OFFICE, SHOP, OTHER |
58
+ | status | enum | DRAFT, ACTIVE |
59
+
60
+ ### unit_claim_request
61
+ | Field | Type | Notes |
62
+ |-------|------|-------|
63
+ | id | uuid | PK |
64
+ | unit_id | uuid | FK → unit |
65
+ | claimed_by | uuid | FK → auth.users |
66
+ | status | enum | PENDING, APPROVED, REJECTED, RETURNED_FOR_FIX |
67
+ | goshan_document_id | uuid | FK → document |
68
+ | match_outcome | enum | ZERO_MATCH, ONE_MATCH, MULTI_MATCH |
69
+ | reviewed_by | uuid | FK → auth.users (staff) |
70
+
71
+ ### unit_membership
72
+ | Field | Type | Notes |
73
+ |-------|------|-------|
74
+ | id | uuid | PK |
75
+ | unit_id | uuid | FK → unit |
76
+ | user_id | uuid | FK → auth.users |
77
+ | role | enum | OWNER_VERIFIED, TENANT |
78
+ | status | enum | ACTIVE, INACTIVE |
79
+ | invited_by | uuid | FK → auth.users |
80
+
81
+ One OWNER_VERIFIED per unit (no co-ownership in Phase 1).
82
+
83
+ ### building_role_assignment
84
+ | Field | Type | Notes |
85
+ |-------|------|-------|
86
+ | id | uuid | PK |
87
+ | building_id | uuid | FK → building |
88
+ | user_id | uuid | FK → auth.users |
89
+ | role | enum | BM_CANDIDATE, BM_VERIFIED, GUARD, DEV_ADMIN |
90
+ | status | enum | ACTIVE, INACTIVE |
91
+ | assigned_by | uuid | FK → auth.users |
92
+
93
+ ### document
94
+ | Field | Type | Notes |
95
+ |-------|------|-------|
96
+ | id | uuid | PK |
97
+ | owner_entity_type | enum | BUILDING, UNIT, USER, TICKET, CREDIT_TOPUP_REQUEST, CONTRACT, NOTICE, TASK_TEMPLATE, TASK_INSTANCE |
98
+ | owner_entity_id | uuid | Polymorphic FK |
99
+ | document_type | text | Classification |
100
+ | storage_path | text | Object storage path |
101
+ | signed_url_ttl | integer | Seconds |
102
+ | uploaded_by | uuid | FK → auth.users |
103
+ | approval_status | enum | PENDING, APPROVED, REJECTED |
104
+ | visibility | enum | PUBLIC, BUILDING_MEMBERS, UNIT_MEMBERS, PRIVATE |
105
+
106
+ ---
107
+
108
+ ## Finance Domain
109
+
110
+ ### dues_config
111
+ | Field | Type | Notes |
112
+ |-------|------|-------|
113
+ | id | uuid | PK |
114
+ | building_id | uuid | FK → building |
115
+ | amount | numeric | Monthly amount |
116
+ | currency | text | ISO 4217 (JOD) |
117
+ | collection_day | integer | Day of month (1-28 recommended) |
118
+ | effective_from | date | |
119
+
120
+ ### dues_cycle
121
+ | Field | Type | Notes |
122
+ |-------|------|-------|
123
+ | id | uuid | PK |
124
+ | building_id | uuid | FK → building |
125
+ | cycle_ym | text | Format: YYYY-MM |
126
+ | status | enum | OPEN, CLOSED |
127
+
128
+ ### dues_obligation
129
+ | Field | Type | Notes |
130
+ |-------|------|-------|
131
+ | id | uuid | PK |
132
+ | cycle_id | uuid | FK → dues_cycle |
133
+ | unit_id | uuid | FK → unit |
134
+ | amount | numeric | |
135
+ | currency | text | JOD |
136
+ | status | enum | UNPAID, PAID, LATE |
137
+ | due_date | date | |
138
+
139
+ UNPAID → LATE at cycle boundary. UNPAID/LATE → PAID via settlement.
140
+
141
+ ### ledger_entry
142
+ | Field | Type | Notes |
143
+ |-------|------|-------|
144
+ | id | uuid | PK |
145
+ | building_id | uuid | FK → building |
146
+ | unit_id | uuid | FK → unit (nullable for building-level) |
147
+ | entry_type | enum | CREDIT_TOPUP, MANUAL_UNIT_INCOME, OPENING_BALANCE, EXPENSE, SUBSCRIPTION_FEE, AUTOSETTLEMENT_APPLIED, REVERSAL |
148
+ | amount | numeric | Positive = credit, negative = debit |
149
+ | currency | text | JOD |
150
+ | reference_id | uuid | FK to source entity |
151
+ | reference_type | text | Source entity type |
152
+ | idempotency_key | text | UNIQUE. Prevents duplicate writes. |
153
+ | request_id | uuid | Audit correlation |
154
+ | created_by | uuid | FK → auth.users |
155
+
156
+ **APPEND-ONLY.** Never UPDATE or DELETE. Corrections via REVERSAL entries only.
157
+
158
+ ### credit_topup_request
159
+ | Field | Type | Notes |
160
+ |-------|------|-------|
161
+ | id | uuid | PK |
162
+ | unit_id | uuid | FK → unit |
163
+ | requested_by | uuid | FK → auth.users (owner only) |
164
+ | amount | numeric | |
165
+ | currency | text | JOD |
166
+ | evidence_document_id | uuid | FK → document (CliQ/bank screenshot) |
167
+ | status | enum | PENDING, APPROVED, REJECTED |
168
+ | reviewed_by | uuid | FK → auth.users (BM) |
169
+ | idempotency_key | text | UNIQUE |
170
+
171
+ ### settlement_entry
172
+ | Field | Type | Notes |
173
+ |-------|------|-------|
174
+ | id | uuid | PK |
175
+ | obligation_id | uuid | FK → dues_obligation |
176
+ | ledger_entry_id | uuid | FK → ledger_entry |
177
+ | amount | numeric | |
178
+ | settled_at | timestamptz | |
179
+
180
+ FIFO: oldest obligation settled first. No partial settlement.
181
+
182
+ ### expense
183
+ | Field | Type | Notes |
184
+ |-------|------|-------|
185
+ | id | uuid | PK |
186
+ | building_id | uuid | FK → building |
187
+ | amount | numeric | |
188
+ | currency | text | JOD |
189
+ | description | text | |
190
+ | category | text | |
191
+ | evidence_document_id | uuid | FK → document |
192
+ | recorded_by | uuid | FK → auth.users (BM) |
193
+ | approval_status | enum | PENDING, APPROVED |
194
+
195
+ ---
196
+
197
+ ## Subscription Domain
198
+
199
+ ### subscription_entitlement
200
+ | Field | Type | Notes |
201
+ |-------|------|-------|
202
+ | id | uuid | PK |
203
+ | building_id | uuid | FK → building. ONE per building. |
204
+ | status | enum | TRIAL, ACTIVE, INACTIVE |
205
+ | current_period_start | timestamptz | |
206
+ | current_period_end | timestamptz | |
207
+ | provider | text | stripe, hyperpay |
208
+ | provider_subscription_id | text | External ID |
209
+
210
+ ### subscription_plan
211
+ | Field | Type | Notes |
212
+ |-------|------|-------|
213
+ | id | uuid | PK |
214
+ | name | text | |
215
+ | building_type | enum | RESIDENTIAL, COMMERCIAL, MIXED |
216
+ | unit_count_min | integer | |
217
+ | unit_count_max | integer | |
218
+ | price | numeric | |
219
+ | currency | text | JOD |
220
+ | billing_interval | text | monthly, yearly |
221
+
222
+ ### subscription_price_quote
223
+ | Field | Type | Notes |
224
+ |-------|------|-------|
225
+ | id | uuid | PK |
226
+ | building_id | uuid | FK → building |
227
+ | plan_id | uuid | FK → subscription_plan |
228
+ | quoted_price | numeric | Snapshot at quote time |
229
+ | inputs_snapshot | jsonb | building_type, unit_count at quote time |
230
+ | expires_at | timestamptz | Quote expiry |
231
+ | status | enum | ACTIVE, EXPIRED, CONSUMED |
232
+
233
+ ### subscription_checkout_session
234
+ | Field | Type | Notes |
235
+ |-------|------|-------|
236
+ | id | uuid | PK |
237
+ | quote_id | uuid | FK → subscription_price_quote |
238
+ | provider | text | stripe, hyperpay |
239
+ | provider_session_id | text | |
240
+ | status | enum | PENDING, COMPLETED, FAILED |
241
+ | promo_redemption_id | uuid | FK → promo_redemption (nullable) |
242
+
243
+ ### subscription_event
244
+ | Field | Type | Notes |
245
+ |-------|------|-------|
246
+ | id | uuid | PK |
247
+ | provider | text | |
248
+ | provider_event_id | text | UNIQUE (idempotency) |
249
+ | canonical_event_type | text | Normalized event type |
250
+ | raw_payload | jsonb | |
251
+ | processed_at | timestamptz | |
252
+ | signature_valid | boolean | |
253
+
254
+ ### promo_code
255
+ | Field | Type | Notes |
256
+ |-------|------|-------|
257
+ | id | uuid | PK |
258
+ | code | text | UNIQUE |
259
+ | discount_type | enum | PERCENTAGE, FIXED |
260
+ | discount_value | numeric | |
261
+ | max_redemptions | integer | |
262
+ | current_redemptions | integer | |
263
+ | valid_from | timestamptz | |
264
+ | valid_until | timestamptz | |
265
+ | status | enum | ACTIVE, EXHAUSTED, EXPIRED |
266
+
267
+ ### promo_redemption
268
+ | Field | Type | Notes |
269
+ |-------|------|-------|
270
+ | id | uuid | PK |
271
+ | promo_code_id | uuid | FK → promo_code |
272
+ | building_id | uuid | FK → building |
273
+ | status | enum | RESERVED, CONSUMED |
274
+
275
+ RESERVED on checkout start, CONSUMED on payment success. Atomic.
276
+
277
+ ### reimbursement_obligation
278
+ | Field | Type | Notes |
279
+ |-------|------|-------|
280
+ | id | uuid | PK |
281
+ | building_id | uuid | FK → building |
282
+ | checkout_session_id | uuid | FK → subscription_checkout_session |
283
+ | amount | numeric | |
284
+ | currency | text | JOD |
285
+ | settlement_method | enum | DUES_OFFSET, MANUAL |
286
+ | status | enum | PENDING, SETTLED |
287
+ | idempotency_key | text | UNIQUE |
288
+
289
+ ---
290
+
291
+ ## Operations Domain
292
+
293
+ ### guard_invite
294
+ | Field | Type | Notes |
295
+ |-------|------|-------|
296
+ | id | uuid | PK |
297
+ | building_id | uuid | FK → building |
298
+ | invited_by | uuid | FK → auth.users (BM) |
299
+ | phone_number | text | |
300
+ | status | enum | PENDING, ACCEPTED, EXPIRED, REVOKED |
301
+ | expires_at | timestamptz | 7-day expiry |
302
+ | token | text | Single-use invite token |
303
+
304
+ One ACTIVE guard per building.
305
+
306
+ ### guard_task
307
+ | Field | Type | Notes |
308
+ |-------|------|-------|
309
+ | id | uuid | PK |
310
+ | building_id | uuid | FK → building |
311
+ | template_id | uuid | FK → task_template (nullable) |
312
+ | assigned_to | uuid | FK → auth.users (guard) |
313
+ | title | text | |
314
+ | description | text | |
315
+ | scheduled_at | timestamptz | |
316
+ | reminder_at | timestamptz | T-15m before scheduled_at |
317
+ | status | enum | PENDING, IN_PROGRESS, COMPLETED, MISSED |
318
+ | visibility | enum | BUILDING_PUBLIC, UNIT_PRIVATE |
319
+
320
+ BUILDING_PUBLIC: all building members see details. UNIT_PRIVATE: others see "Busy/Private" only.
321
+
322
+ ### ticket
323
+ | Field | Type | Notes |
324
+ |-------|------|-------|
325
+ | id | uuid | PK |
326
+ | building_id | uuid | FK → building |
327
+ | unit_id | uuid | FK → unit (nullable) |
328
+ | reported_by | uuid | FK → auth.users |
329
+ | assigned_to | uuid | FK → auth.users (guard, nullable) |
330
+ | title | text | |
331
+ | description | text | |
332
+ | category | text | Optional |
333
+ | status | enum | NEW, IN_PROGRESS, DONE, CLOSED, CANCELLED |
334
+ | priority | enum | LOW, MEDIUM, HIGH |
335
+
336
+ Status flow: NEW → IN_PROGRESS → DONE → CLOSED. Optional CANCELLED from any state.
337
+
338
+ ---
339
+
340
+ ## Audit Domain
341
+
342
+ ### audit_log
343
+ | Field | Type | Notes |
344
+ |-------|------|-------|
345
+ | id | uuid | PK |
346
+ | event_type | text | e.g., permit_submitted, credit_topup_approved |
347
+ | actor_user_id | uuid | FK → auth.users |
348
+ | building_id | uuid | Nullable |
349
+ | unit_id | uuid | Nullable |
350
+ | request_id | uuid | Correlation |
351
+ | payload | jsonb | Event-specific data (no PII) |
352
+ | created_at | timestamptz | |
353
+
354
+ **IMMUTABLE.** 7-year retention. Filterable by building_id, unit_id, actor_user_id, event_type, date range.
355
+
356
+ ### statement_version
357
+ | Field | Type | Notes |
358
+ |-------|------|-------|
359
+ | id | uuid | PK |
360
+ | building_id | uuid | FK → building |
361
+ | cycle_ym | text | |
362
+ | version_token | text | UNIQUE |
363
+ | pdf_storage_path | text | |
364
+ | hash | text | Immutable content hash |
365
+ | generated_at | timestamptz | |
@@ -0,0 +1,95 @@
1
+ # Sakani Error Codes
2
+
3
+ All 44 error codes from SRS V1.14 (EH-6.02 through EH-6.44). Every API endpoint must use these exact codes.
4
+
5
+ ## Error Response Shape
6
+
7
+ ```typescript
8
+ interface ApiError {
9
+ http_status: number;
10
+ error_code: string;
11
+ message_key: string; // i18n lookup key
12
+ request_id: string; // UUID, always present
13
+ details?: Record<string, unknown>; // safe details only
14
+ }
15
+ ```
16
+
17
+ ## Safe-Details Rule
18
+
19
+ NEVER include in `details` or error messages:
20
+ - `building_key_v1` or `unit_key_v1` values
21
+ - National ID numbers or extracted document text
22
+ - Internal entity IDs that enable enumeration
23
+ - Stack traces or internal paths
24
+
25
+ ## Error Code Table
26
+
27
+ | Code | error_code | HTTP | message_key | Context |
28
+ |------|-----------|------|-------------|---------|
29
+ | EH-6.02 | UNAUTHENTICATED | 401 | error.auth.unauthenticated | No valid token |
30
+ | EH-6.03 | TOKEN_EXPIRED | 401 | error.auth.token_expired | Access token expired |
31
+ | EH-6.04 | INSUFFICIENT_PERMISSIONS | 403 | error.auth.insufficient_permissions | Role/scope insufficient |
32
+ | EH-6.05 | BUILDING_NOT_FOUND | 404 | error.building.not_found | Building lookup 0-match |
33
+ | EH-6.06 | BUILDING_AMBIGUOUS | 409 | error.building.ambiguous | Building lookup >1-match |
34
+ | EH-6.07 | UNIT_NOT_FOUND | 404 | error.unit.not_found | Unit lookup 0-match |
35
+ | EH-6.08 | UNIT_AMBIGUOUS | 409 | error.unit.ambiguous | Unit lookup >1-match |
36
+ | EH-6.09 | UNIT_ALREADY_CLAIMED | 409 | error.unit.already_claimed | OWNER_VERIFIED exists |
37
+ | EH-6.10 | CLAIM_ALREADY_PENDING | 409 | error.claim.already_pending | Duplicate claim request |
38
+ | EH-6.11 | PERMIT_ALREADY_SUBMITTED | 409 | error.permit.already_submitted | Duplicate permit submission |
39
+ | EH-6.12 | SETUP_REQUEST_ALREADY_PENDING | 409 | error.setup.already_pending | Duplicate setup request |
40
+ | EH-6.13 | DOCUMENT_NOT_FOUND | 404 | error.document.not_found | Document ID invalid |
41
+ | EH-6.14 | DOCUMENT_ACCESS_DENIED | 403 | error.document.access_denied | Visibility check failed |
42
+ | EH-6.15 | INVALID_DOCUMENT_TYPE | 422 | error.document.invalid_type | Wrong document classification |
43
+ | EH-6.16 | DUES_CONFIG_NOT_FOUND | 404 | error.dues.config_not_found | No dues config for building |
44
+ | EH-6.17 | DUES_CYCLE_NOT_FOUND | 404 | error.dues.cycle_not_found | Invalid cycle_ym |
45
+ | EH-6.18 | OBLIGATION_NOT_FOUND | 404 | error.dues.obligation_not_found | Invalid obligation |
46
+ | EH-6.19 | INSUFFICIENT_CREDIT | 422 | error.credit.insufficient | Credit doesn't cover obligation |
47
+ | EH-6.20 | DUPLICATE_TOPUP_REQUEST | 409 | error.credit.duplicate_topup | Idempotency key collision |
48
+ | EH-6.21 | TOPUP_ALREADY_REVIEWED | 409 | error.credit.already_reviewed | Re-reviewing decided request |
49
+ | EH-6.22 | OPENING_BALANCE_EXISTS | 409 | error.ledger.opening_balance_exists | One per unit |
50
+ | EH-6.23 | OPENING_BALANCE_WINDOW_CLOSED | 422 | error.ledger.opening_balance_window | Past controlled window |
51
+ | EH-6.24 | LEDGER_IDEMPOTENCY_CONFLICT | 409 | error.ledger.idempotency_conflict | Duplicate financial write |
52
+ | EH-6.25 | SUBSCRIPTION_NOT_FOUND | 404 | error.subscription.not_found | No entitlement for building |
53
+ | EH-6.26 | SUBSCRIPTION_INACTIVE | 403 | error.subscription.inactive | Paywall gate |
54
+ | EH-6.27 | TRIAL_EXPIRED | 403 | error.subscription.trial_expired | 30-day trial over |
55
+ | EH-6.28 | QUOTE_EXPIRED | 422 | error.subscription.quote_expired | Price quote past expiry |
56
+ | EH-6.29 | QUOTE_ALREADY_CONSUMED | 409 | error.subscription.quote_consumed | Quote used in checkout |
57
+ | EH-6.30 | PROMO_CODE_INVALID | 422 | error.promo.invalid | Code not found or inactive |
58
+ | EH-6.31 | PROMO_CODE_EXHAUSTED | 422 | error.promo.exhausted | Max redemptions reached |
59
+ | EH-6.32 | PROMO_ALREADY_RESERVED | 409 | error.promo.already_reserved | Duplicate reservation |
60
+ | EH-6.33 | CHECKOUT_SESSION_INVALID | 422 | error.checkout.invalid | Bad session state |
61
+ | EH-6.34 | WEBHOOK_SIGNATURE_INVALID | 401 | error.webhook.signature_invalid | Provider signature failed |
62
+ | EH-6.35 | GUARD_INVITE_EXPIRED | 422 | error.guard.invite_expired | Past 7-day window |
63
+ | EH-6.36 | GUARD_INVITE_REVOKED | 422 | error.guard.invite_revoked | Invite was revoked |
64
+ | EH-6.37 | GUARD_ALREADY_ACTIVE | 409 | error.guard.already_active | One active guard per building |
65
+ | EH-6.38 | TICKET_NOT_FOUND | 404 | error.ticket.not_found | Invalid ticket |
66
+ | EH-6.39 | TICKET_INVALID_TRANSITION | 422 | error.ticket.invalid_transition | Status flow violated |
67
+ | EH-6.40 | TASK_NOT_FOUND | 404 | error.task.not_found | Invalid task |
68
+ | EH-6.41 | VALIDATION_ERROR | 422 | error.validation.failed | Zod/input validation |
69
+ | EH-6.42 | RATE_LIMITED | 429 | error.rate_limit.exceeded | Too many requests |
70
+ | EH-6.43 | INTERNAL_ERROR | 500 | error.internal | Unexpected server error |
71
+ | EH-6.44 | SERVICE_UNAVAILABLE | 503 | error.service.unavailable | Downstream service down |
72
+
73
+ ## Usage in NestJS
74
+
75
+ ```typescript
76
+ // In @sakani/shared/src/constants/errors.ts
77
+ export const SAKANI_ERRORS = {
78
+ UNAUTHENTICATED: { code: 'UNAUTHENTICATED', status: 401, messageKey: 'error.auth.unauthenticated' },
79
+ BUILDING_NOT_FOUND: { code: 'BUILDING_NOT_FOUND', status: 404, messageKey: 'error.building.not_found' },
80
+ // ... all 44
81
+ } as const;
82
+
83
+ // In NestJS exception filter
84
+ throw new SakaniException(SAKANI_ERRORS.BUILDING_NOT_FOUND, { requestId });
85
+ ```
86
+
87
+ ## Deterministic Lookup Semantics
88
+
89
+ These error codes have precise semantic meanings for building/unit lookup:
90
+ - `BUILDING_NOT_FOUND` = exactly 0-match (not "maybe not found")
91
+ - `BUILDING_AMBIGUOUS` = exactly >1-match
92
+ - `UNIT_NOT_FOUND` = exactly 0-match
93
+ - `UNIT_AMBIGUOUS` = exactly >1-match
94
+
95
+ The lookup algorithm must be deterministic: same input always produces the same match outcome.