@atlashub/smartstack-cli 2.0.0 → 2.2.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 (59) hide show
  1. package/.documentation/agents.html +147 -40
  2. package/.documentation/apex.html +1 -1
  3. package/.documentation/business-analyse.html +3 -3
  4. package/.documentation/cli-commands.html +2 -2
  5. package/.documentation/commands.html +14 -14
  6. package/.documentation/efcore.html +14 -14
  7. package/.documentation/gitflow.html +12 -12
  8. package/.documentation/hooks.html +41 -3
  9. package/.documentation/index.html +1 -1
  10. package/.documentation/init.html +2 -2
  11. package/.documentation/installation.html +11 -11
  12. package/.documentation/js/app.js +1 -1
  13. package/.documentation/ralph-loop.html +1 -1
  14. package/.documentation/test-web.html +4 -4
  15. package/dist/index.js +19 -11
  16. package/dist/index.js.map +1 -1
  17. package/dist/mcp-entry.mjs +57595 -4569
  18. package/dist/mcp-entry.mjs.map +1 -1
  19. package/package.json +1 -1
  20. package/templates/agents/ba-reader.md +250 -0
  21. package/templates/agents/ba-writer.md +210 -0
  22. package/templates/agents/docs-context-reader.md +51 -33
  23. package/templates/skills/_shared.md +2 -0
  24. package/templates/skills/business-analyse/SKILL.md +120 -108
  25. package/templates/skills/business-analyse/_shared.md +191 -160
  26. package/templates/skills/business-analyse/patterns/suggestion-catalog.md +478 -0
  27. package/templates/skills/business-analyse/questionnaire/01-context.md +3 -15
  28. package/templates/skills/business-analyse/questionnaire/08-performance.md +7 -21
  29. package/templates/skills/business-analyse/questionnaire/09-constraints.md +0 -13
  30. package/templates/skills/business-analyse/questionnaire/10-documentation.md +0 -13
  31. package/templates/skills/business-analyse/questionnaire.md +72 -76
  32. package/templates/skills/business-analyse/react/components.md +317 -154
  33. package/templates/skills/business-analyse/react/i18n-template.md +167 -106
  34. package/templates/skills/business-analyse/react/schema.md +325 -106
  35. package/templates/skills/business-analyse/schemas/feature-schema.json +690 -0
  36. package/templates/skills/business-analyse/steps/step-00-init.md +395 -285
  37. package/templates/skills/business-analyse/steps/step-01-analyse.md +505 -0
  38. package/templates/skills/business-analyse/steps/step-02-specify.md +833 -0
  39. package/templates/skills/business-analyse/steps/step-03-validate.md +862 -0
  40. package/templates/skills/business-analyse/steps/step-04-handoff.md +1593 -0
  41. package/templates/skills/business-analyse/templates/tpl-handoff.md +95 -43
  42. package/templates/skills/controller/templates.md +82 -0
  43. package/templates/skills/efcore/references/zero-downtime-patterns.md +227 -0
  44. package/templates/skills/efcore/steps/migration/step-03-validate.md +19 -0
  45. package/templates/skills/review-code/SKILL.md +4 -2
  46. package/templates/skills/review-code/references/owasp-api-top10.md +243 -0
  47. package/templates/skills/review-code/references/security-checklist.md +86 -1
  48. package/templates/skills/review-code/references/smartstack-conventions.md +166 -0
  49. package/templates/skills/workflow/SKILL.md +27 -0
  50. package/templates/skills/business-analyse/steps/step-01-discover.md +0 -737
  51. package/templates/skills/business-analyse/steps/step-02-analyse.md +0 -299
  52. package/templates/skills/business-analyse/steps/step-03-specify.md +0 -409
  53. package/templates/skills/business-analyse/steps/step-04-validate.md +0 -313
  54. package/templates/skills/business-analyse/steps/step-05-handoff.md +0 -658
  55. package/templates/skills/business-analyse/steps/step-06-doc-html.md +0 -320
  56. package/templates/skills/business-analyse/templates/00-context.md +0 -105
  57. package/templates/skills/business-analyse/templates/tpl-brd.md +0 -97
  58. package/templates/skills/business-analyse/templates/tpl-discovery.md +0 -78
  59. package/templates/skills/business-analyse/tracking/change-template.md +0 -30
@@ -1,7 +1,7 @@
1
1
  # Template Development Handoff
2
2
 
3
- > **Usage:** Template for 4-development-handoff.md
4
- > **Loaded in:** step-05-handoff.md
3
+ > **Usage:** Template for step-04-handoff.md
4
+ > **Data source:** feature.json (sections: metadata, analysis, specification, handoff)
5
5
 
6
6
  ---
7
7
 
@@ -9,8 +9,9 @@
9
9
  # Development Handoff - {FEAT-XXX} {Feature Name}
10
10
 
11
11
  > **Module:** business/{application}/{module}
12
- > **Version:** 1.0
13
- > **Validated Specs:** FRD v1.0 (validation.json)
12
+ > **Version:** {version}
13
+ > **Validated Specs:** feature.json (validation.decision = APPROVED)
14
+ > **Source:** `docs/business/{app}/{module}/business-analyse/v{version}/feature.json`
14
15
  > **Implementation:** `/ralph-loop -r` (iterative) | `/feature-full business/{app}/{module}` (one-shot)
15
16
 
16
17
  ## DEVELOPER INSTRUCTIONS
@@ -34,10 +35,13 @@ This document is a self-contained prompt for Claude Code.
34
35
 
35
36
  | Attribute | Value |
36
37
  |----------|--------|
37
- | Feature ID | {FEAT-XXX} |
38
- | Module | business/{application}/{module} |
38
+ | Feature ID | {feature.id} |
39
+ | Module | business/{feature.metadata.application}/{feature.metadata.module} |
39
40
  | Base Permission | `business.{app}.{module}` |
40
- | Complexity | {Simple/Medium/Complex} |
41
+ | Project Namespace | {feature.metadata.projectNamespace} |
42
+ | DB Schema | `extensions` (client entities) / `core` (navigation, permissions) |
43
+ | Table Prefix | `{prefix}_` |
44
+ | Complexity | {feature.handoff.complexity} |
41
45
 
42
46
  ## 2. [EXPLORE] EXISTING PATTERNS
43
47
 
@@ -45,59 +49,91 @@ BEFORE coding, explore these files to understand the patterns:
45
49
 
46
50
  ```
47
51
  BACKEND:
48
- - src/SmartStack.Domain/Entities/ Entity structure
49
- - src/SmartStack.Application/Features/ CQRS pattern
50
- - src/SmartStack.Infrastructure/Persistence/Configurations/ EF Core
52
+ - src/{project_namespace}.Domain/Business/ -> Entity structure + folder hierarchy
53
+ - src/{project_namespace}.Application/Business/ -> DTOs + service interfaces
54
+ - src/{project_namespace}.Application/Common/Interfaces/ -> Service contracts
55
+ - src/{project_namespace}.Infrastructure/Persistence/Configurations/ -> EF Core configs (subfolder per module)
56
+ - src/{project_namespace}.Infrastructure/Services/ -> Service implementations (subfolder per module)
57
+ - src/{project_namespace}.Infrastructure/Persistence/Seeding/Data/ -> SeedData patterns
58
+
59
+ SEED DATA (CRITICAL):
60
+ - NavigationModuleConfiguration.cs -> How modules are seeded (HasData)
61
+ - NavigationTranslationConfiguration.cs -> How translations are seeded (4 languages)
62
+ - PermissionConfiguration.cs -> How permissions are seeded (HasData)
63
+ - RolePermissionConfiguration.cs -> How role-permission mappings are seeded
51
64
 
52
65
  FRONTEND:
53
- - web/smartstack-web/src/pages/business/ Existing pages
54
- - web/smartstack-web/src/components/ Reusable components
55
- - web/smartstack-web/src/services/api/ API calls
66
+ - web/src/pages/business/ -> Existing pages
67
+ - web/src/components/ -> Reusable components
68
+ - web/src/services/api/ -> API calls
56
69
  ```
57
70
 
58
71
  ## 3. FILES TO CREATE
59
72
 
60
- ### 3.1 Backend
61
-
62
- | File | Template | Description |
63
- |------|----------|-------------|
64
- | `Domain/Entities/{Entity}.cs` | Domain Entity | Properties + rules |
65
- | `Application/Features/{Module}/` | CQRS | MediatR handlers |
66
- | `Infrastructure/.../Configurations/` | EF Core | Config + HasData |
67
- | `Api/Controllers/Business/` | Controller | REST endpoints |
73
+ > **Source:** `feature.handoff.filesToCreate[]` in feature.json
68
74
 
69
- ### 3.2 Frontend
75
+ ### 3.1 Backend
70
76
 
71
- | File | Template | Description |
72
- |------|----------|-------------|
73
- | `pages/business/{app}/{module}/` | React Page | List + detail |
74
- | `services/api/{module}Api.ts` | API Service | Axios calls |
75
- | `i18n/locales/{lang}/{module}.json` | Translations | FR, EN, IT, DE |
77
+ | File | Path Pattern | Description |
78
+ |------|-------------|-------------|
79
+ | Domain Entity | `Domain/Business/{Application}/{Module}/{Entity}.cs` | BaseEntity + IAuditableEntity |
80
+ | Service Interface | `Application/Common/Interfaces/I{Entity}Service.cs` | Service contract |
81
+ | DTOs | `Application/Business/{Application}/{Module}/DTOs/{Entity}Dto.cs` | Response, Create, Update records |
82
+ | Mapping | `Application/Business/{Application}/{Module}/DTOs/{Entity}MappingExtensions.cs` | Entity <-> DTO mapping |
83
+ | Permission Constants | `Application/Business/{Application}/{Module}/Permissions.cs` | Compile-time constants |
84
+ | EF Configuration | `Infrastructure/Persistence/Configurations/{Module}/{Entity}Configuration.cs` | Table + indexes + HasData |
85
+ | Service Implementation | `Infrastructure/Services/{Module}/{Entity}Service.cs` | Business logic |
86
+ | Controller | `Api/Controllers/Business/{Application}/{Module}Controller.cs` | NavRoute + RequirePermission |
87
+
88
+ ### 3.2 SeedData Core (CRITICAL -- without these, module is invisible and returns 403)
89
+
90
+ > **5 mandatory files** for every new module (4 EF Core HasData + 1 Application code):
91
+
92
+ | # | File | Layer | Content |
93
+ |---|------|-------|---------|
94
+ | 1 | `NavigationModuleConfiguration.cs` | Infrastructure (HasData) | Module entry in `nav_Modules` |
95
+ | 2 | `NavigationTranslationConfiguration.cs` | Infrastructure (HasData) | 4 translations (fr, en, it, de) per nav entity |
96
+ | 3 | `PermissionConfiguration.cs` | Infrastructure (HasData) | Wildcard + CRUD permissions in `nav_Permissions` |
97
+ | 4 | `Permissions.cs` | Application (code) | Compile-time constants for `[RequirePermission]` |
98
+ | 5 | `RolePermissionConfiguration.cs` | Infrastructure (HasData) | Role->Permission for {App} Admin, {App} Manager, {App} Contributor, {App} Viewer |
99
+
100
+ ### 3.3 Frontend
101
+
102
+ | File | Path Pattern | Description |
103
+ |------|-------------|-------------|
104
+ | Main Page | `pages/business/{app}/{module}/page.tsx` | List + actions |
105
+ | Components | `components/business/{module}/` | Entity-specific components |
106
+ | API Service | `services/api/{module}Api.ts` | Typed Axios calls |
107
+ | Translations | `i18n/locales/{lang}/{module}.json` | FR, EN, IT, DE |
76
108
 
77
109
  ## 4. DETAILED SPECIFICATIONS
78
110
 
111
+ > **Source:** Read from feature.json sections: `analysis.entities[]`, `specification.apiEndpoints[]`, `analysis.businessRules[]`, `specification.navigation`, `specification.permissionMatrix`
112
+
79
113
  ### 4.1 Entity
80
114
 
81
- | Attribute | Description | Required | Rules |
82
- |-----------|-------------|----------|-------|
83
- | Id | Unique identifier | Yes | GUID |
84
- | {attr} | {description} | {Yes/No} | {validation} |
115
+ **Base class:** `BaseEntity` + `IAuditableEntity`
116
+ **Table name:** `{prefix}_{EntityPlural}` in schema `extensions`
117
+ **Schema:** `extensions` for business entities, `core` for system entities (navigation, permissions)
118
+ > DO NOT add Id, TenantId, CreatedAt, UpdatedAt, CreatedBy, UpdatedBy -- these are automatic via BaseEntity + IAuditableEntity.
119
+
120
+ Attributes from: `feature.analysis.entities[].attributes[]`
85
121
 
86
122
  ### 4.2 API Endpoints
87
123
 
88
- | Endpoint | Method | Permission | Body | Response |
89
- |----------|--------|------------|------|----------|
90
- | `/api/business/{module}` | GET | `.read` | - | List |
91
- | `/api/business/{module}` | POST | `.create` | CreateDto | 201 |
92
- | `/api/business/{module}/{id}` | GET | `.read` | - | Entity |
93
- | `/api/business/{module}/{id}` | PUT | `.update` | UpdateDto | 200 |
94
- | `/api/business/{module}/{id}` | DELETE | `.delete` | - | 204 |
124
+ From: `feature.specification.apiEndpoints[]`
95
125
 
96
- ### 4.3 Business Rules Code
126
+ ### 4.3 Business Rules -> Code
127
+
128
+ From: `feature.handoff.brToCodeMapping[]`
97
129
 
98
130
  | BR-ID | Rule | Implementation |
99
131
  |-------|------|----------------|
100
- | BR-001 | {rule} | {where to implement} |
132
+ | {id} | {rule from analysis.businessRules[]} | {implementation from handoff.brToCodeMapping[]} |
133
+
134
+ ### 4.4 SeedData Specifications
135
+
136
+ From: `feature.specification.navigation` and `feature.specification.permissionMatrix`
101
137
 
102
138
  ## 5. REQUIRED TESTS
103
139
 
@@ -108,13 +144,29 @@ FRONTEND:
108
144
 
109
145
  ## 6. POST-IMPLEMENTATION CHECKLIST
110
146
 
147
+ **Build & Tests:**
111
148
  - [ ] Backend build OK
112
149
  - [ ] Frontend build OK
113
150
  - [ ] Tests passing
114
- - [ ] EF Core migration created
115
- - [ ] Permissions in PermissionConfiguration.cs
151
+
152
+ **Folder Conventions:**
153
+ - [ ] Domain entities in `Domain/Business/{Application}/{Module}/`
154
+ - [ ] Application DTOs in `Application/Business/{Application}/{Module}/DTOs/`
155
+ - [ ] Infrastructure configs in `Configurations/{Module}/`
156
+ - [ ] Infrastructure services in `Services/{Module}/`
157
+ - [ ] Controller in `Controllers/Business/{Application}/`
158
+
159
+ **SeedData Core (CRITICAL):**
160
+ - [ ] Navigation module entry (HasData in NavigationModuleConfiguration.cs)
161
+ - [ ] Navigation translations (4 languages in NavigationTranslationConfiguration.cs)
162
+ - [ ] Permissions (HasData in PermissionConfiguration.cs: wildcard + CRUD)
163
+ - [ ] Permission constants (Permissions.cs in Application layer)
164
+ - [ ] Role-Permission assignments (HasData in RolePermissionConfiguration.cs: 4 roles)
165
+ - [ ] EF Core migration created (includes all HasData seeds)
166
+
167
+ **Frontend & i18n:**
116
168
  - [ ] i18n complete (4 languages)
117
- - [ ] Documentation: `/business-analyse:6-doc-html {FEAT-XXX}`
169
+ - [ ] Nested routes (NOT flat)
118
170
 
119
171
  ---
120
172
 
@@ -1461,8 +1461,90 @@ public record BulkUpdate{Entity}Request(
1461
1461
  □ EF Core Migration created
1462
1462
  □ Migration applied
1463
1463
 
1464
+ □ API Versioning (if applicable)
1465
+ □ See API Versioning section below
1466
+
1464
1467
  □ Correct Permission Level
1465
1468
  □ Module (Level 3) - For main CRUD
1466
1469
  □ Section (Level 4) - If sub-pages with different permissions
1467
1470
  □ Resource (Level 5) - If sub-resources with distinct permissions
1468
1471
  ```
1472
+
1473
+ ---
1474
+
1475
+ ## API Versioning
1476
+
1477
+ **SmartStack convention:** Header-based versioning using `Asp.Versioning.Mvc`.
1478
+
1479
+ ### Setup
1480
+
1481
+ ```csharp
1482
+ // Program.cs
1483
+ builder.Services.AddApiVersioning(options =>
1484
+ {
1485
+ options.DefaultApiVersion = new ApiVersion(1, 0);
1486
+ options.AssumeDefaultVersionWhenUnspecified = true;
1487
+ options.ReportApiVersions = true; // Adds api-supported-versions header
1488
+ options.ApiVersionReader = new HeaderApiVersionReader("api-version");
1489
+ })
1490
+ .AddApiExplorer(options =>
1491
+ {
1492
+ options.GroupNameFormat = "'v'VVV";
1493
+ options.SubstituteApiVersionInUrl = true;
1494
+ });
1495
+ ```
1496
+
1497
+ ### Controller Usage
1498
+
1499
+ ```csharp
1500
+ // v1 - Default (no attribute needed if only one version exists)
1501
+ [ApiController]
1502
+ [ApiVersion("1.0")]
1503
+ [NavRoute("business.crm.contacts")]
1504
+ public class ContactsController : ControllerBase
1505
+ {
1506
+ [HttpGet]
1507
+ [RequirePermission(Permissions.Business.Crm.Contacts.Read)]
1508
+ public async Task<ActionResult<PagedResult<ContactDto>>> GetAll(...) { ... }
1509
+ }
1510
+
1511
+ // v2 - Breaking changes only
1512
+ [ApiController]
1513
+ [ApiVersion("2.0")]
1514
+ [NavRoute("business.crm.contacts")]
1515
+ public class ContactsV2Controller : ControllerBase
1516
+ {
1517
+ [HttpGet]
1518
+ [RequirePermission(Permissions.Business.Crm.Contacts.Read)]
1519
+ public async Task<ActionResult<PagedResult<ContactV2Dto>>> GetAll(...) { ... }
1520
+ }
1521
+ ```
1522
+
1523
+ ### Deprecation
1524
+
1525
+ ```csharp
1526
+ [ApiVersion("1.0", Deprecated = true)] // Adds api-deprecated-versions header
1527
+ [ApiVersion("2.0")]
1528
+ public class ContactsController : ControllerBase
1529
+ {
1530
+ [HttpGet]
1531
+ [MapToApiVersion("1.0")]
1532
+ public async Task<ActionResult<PagedResult<ContactDto>>> GetAllV1(...) { ... }
1533
+
1534
+ [HttpGet]
1535
+ [MapToApiVersion("2.0")]
1536
+ public async Task<ActionResult<PagedResult<ContactV2Dto>>> GetAllV2(...) { ... }
1537
+ }
1538
+ ```
1539
+
1540
+ ### SmartStack Versioning Rules
1541
+
1542
+ | Rule | Detail |
1543
+ |------|--------|
1544
+ | Default version | `1.0` (assumed when no header sent) |
1545
+ | Version header | `api-version: 2.0` |
1546
+ | When to version | Breaking changes only (field removal, type change, behavior change) |
1547
+ | Non-breaking changes | Add to existing version (new fields, new endpoints) |
1548
+ | Naming | `V2Controller` suffix or `[MapToApiVersion]` in same controller |
1549
+ | Deprecation | Mark old version deprecated, maintain for 2 releases minimum |
1550
+ | Documentation | Both versions documented via `[ProducesResponseType]` |
@@ -0,0 +1,227 @@
1
+ <overview>
2
+ Zero-downtime migration patterns for EF Core. Use when a migration contains destructive operations (column rename, type change, column drop) that could cause downtime during deployment.
3
+
4
+ These patterns apply to production deployments where the application runs continuously. For development environments, standard migrations are sufficient.
5
+ </overview>
6
+
7
+ <when_to_use>
8
+ ## When These Patterns Apply
9
+
10
+ **Destructive operations requiring zero-downtime strategy:**
11
+ - `RenameColumn` / `RenameTable`
12
+ - `DropColumn` / `DropTable`
13
+ - `AlterColumn` (type change, nullability change)
14
+
15
+ **Safe operations (no special handling needed):**
16
+ - `AddColumn` (nullable or with default value)
17
+ - `CreateTable`
18
+ - `CreateIndex`
19
+ - `AddForeignKey`
20
+ </when_to_use>
21
+
22
+ <column_rename>
23
+ ## Pattern 1: Column Rename (5 phases)
24
+
25
+ A column rename cannot be done atomically without downtime. Use a phased approach across multiple deployments.
26
+
27
+ ### Phase 1 - Add New Column (Migration 1)
28
+ ```csharp
29
+ protected override void Up(MigrationBuilder migrationBuilder)
30
+ {
31
+ migrationBuilder.AddColumn<string>(
32
+ name: "FullName",
33
+ table: "auth_users",
34
+ schema: "core",
35
+ type: "nvarchar(256)",
36
+ nullable: true); // Must be nullable initially
37
+
38
+ // Backfill existing data
39
+ migrationBuilder.Sql(
40
+ "UPDATE core.auth_users SET FullName = DisplayName WHERE FullName IS NULL");
41
+ }
42
+
43
+ protected override void Down(MigrationBuilder migrationBuilder)
44
+ {
45
+ migrationBuilder.DropColumn(name: "FullName", table: "auth_users", schema: "core");
46
+ }
47
+ ```
48
+
49
+ ### Phase 2 - Dual-Write Code (Application deployment)
50
+ ```csharp
51
+ // Entity writes to BOTH columns during transition
52
+ public void UpdateName(string name)
53
+ {
54
+ DisplayName = name; // Old column
55
+ FullName = name; // New column
56
+ }
57
+ ```
58
+
59
+ ### Phase 3 - Backfill Remaining Data (Migration 2, optional)
60
+ ```csharp
61
+ protected override void Up(MigrationBuilder migrationBuilder)
62
+ {
63
+ // Catch any rows missed during dual-write transition
64
+ migrationBuilder.Sql(
65
+ "UPDATE core.auth_users SET FullName = DisplayName WHERE FullName IS NULL");
66
+
67
+ // Make new column non-nullable
68
+ migrationBuilder.AlterColumn<string>(
69
+ name: "FullName",
70
+ table: "auth_users",
71
+ schema: "core",
72
+ type: "nvarchar(256)",
73
+ nullable: false,
74
+ defaultValue: "");
75
+ }
76
+ ```
77
+
78
+ ### Phase 4 - Switch Reads (Application deployment)
79
+ ```csharp
80
+ // Entity now reads from new column only
81
+ public string Name => FullName;
82
+ ```
83
+
84
+ ### Phase 5 - Drop Old Column (Migration 3)
85
+ ```csharp
86
+ protected override void Up(MigrationBuilder migrationBuilder)
87
+ {
88
+ migrationBuilder.DropColumn(name: "DisplayName", table: "auth_users", schema: "core");
89
+ }
90
+
91
+ protected override void Down(MigrationBuilder migrationBuilder)
92
+ {
93
+ migrationBuilder.AddColumn<string>(
94
+ name: "DisplayName",
95
+ table: "auth_users",
96
+ schema: "core",
97
+ type: "nvarchar(256)",
98
+ nullable: false,
99
+ defaultValue: "");
100
+
101
+ migrationBuilder.Sql(
102
+ "UPDATE core.auth_users SET DisplayName = FullName");
103
+ }
104
+ ```
105
+ </column_rename>
106
+
107
+ <column_type_change>
108
+ ## Pattern 2: Column Type Change (4 phases)
109
+
110
+ Changing a column type (e.g., `int` to `string`, `string` to `decimal`) follows the same dual-column approach.
111
+
112
+ ### Phase 1 - Add New Typed Column
113
+ ```csharp
114
+ protected override void Up(MigrationBuilder migrationBuilder)
115
+ {
116
+ migrationBuilder.AddColumn<decimal>(
117
+ name: "PriceDecimal",
118
+ table: "extensions_products",
119
+ schema: "extensions",
120
+ type: "decimal(18,2)",
121
+ nullable: true);
122
+
123
+ migrationBuilder.Sql(
124
+ "UPDATE extensions.extensions_products SET PriceDecimal = CAST(Price AS decimal(18,2))");
125
+ }
126
+ ```
127
+
128
+ ### Phase 2 - Dual-Write in Code
129
+ ### Phase 3 - Make Non-Nullable + Switch Reads
130
+ ### Phase 4 - Drop Old Column
131
+
132
+ Same phased pattern as column rename.
133
+ </column_type_change>
134
+
135
+ <large_table_operations>
136
+ ## Pattern 3: Large Table Backfill
137
+
138
+ For tables with millions of rows, batch the backfill to avoid lock escalation.
139
+
140
+ ```csharp
141
+ protected override void Up(MigrationBuilder migrationBuilder)
142
+ {
143
+ migrationBuilder.AddColumn<string>(
144
+ name: "NormalizedEmail",
145
+ table: "auth_users",
146
+ schema: "core",
147
+ type: "nvarchar(256)",
148
+ nullable: true);
149
+
150
+ // Batched backfill to avoid table locks
151
+ migrationBuilder.Sql(@"
152
+ DECLARE @BatchSize INT = 5000;
153
+ DECLARE @RowsAffected INT = 1;
154
+
155
+ WHILE @RowsAffected > 0
156
+ BEGIN
157
+ UPDATE TOP (@BatchSize) core.auth_users
158
+ SET NormalizedEmail = UPPER(Email)
159
+ WHERE NormalizedEmail IS NULL;
160
+
161
+ SET @RowsAffected = @@ROWCOUNT;
162
+ END
163
+ ");
164
+ }
165
+ ```
166
+
167
+ **Rules:**
168
+ - Batch size: 1,000-10,000 rows depending on table width
169
+ - Always include a `WHERE` clause to avoid re-processing
170
+ - Monitor transaction log growth during execution
171
+ - Run during low-traffic windows if possible
172
+ </large_table_operations>
173
+
174
+ <rollback_strategy>
175
+ ## Rollback Strategies
176
+
177
+ ### Migration Down() Method
178
+ Every migration MUST have a functional `Down()` method for rollback:
179
+
180
+ ```csharp
181
+ protected override void Down(MigrationBuilder migrationBuilder)
182
+ {
183
+ // Reverse the operation
184
+ migrationBuilder.DropColumn(name: "NewColumn", table: "auth_users", schema: "core");
185
+ }
186
+ ```
187
+
188
+ ### Rollback Command
189
+ ```bash
190
+ # Rollback to specific migration
191
+ dotnet ef database update {PreviousMigrationName} \
192
+ --context $DBCONTEXT \
193
+ --project $INFRA_PROJECT \
194
+ --startup-project $STARTUP_PROJECT
195
+ ```
196
+
197
+ ### Pre-Deployment Checklist
198
+ - [ ] `Down()` method tested locally
199
+ - [ ] Database backup taken before deployment
200
+ - [ ] Application compatible with both old and new schema (dual-write phase)
201
+ - [ ] Rollback procedure documented in deployment notes
202
+ - [ ] Monitoring alerts configured for error spike
203
+ </rollback_strategy>
204
+
205
+ <decision_guide>
206
+ ## Decision Guide
207
+
208
+ | Operation | Risk | Strategy |
209
+ |-----------|------|----------|
210
+ | Add nullable column | Low | Standard migration |
211
+ | Add column with default | Low | Standard migration |
212
+ | Create table | Low | Standard migration |
213
+ | Create index | Medium | `CREATE INDEX CONCURRENTLY` if supported |
214
+ | Rename column | High | 5-phase pattern |
215
+ | Change column type | High | 4-phase pattern |
216
+ | Drop column | High | Verify no reads, then drop |
217
+ | Drop table | High | Verify no references, then drop |
218
+ | Make column non-nullable | Medium | Ensure no NULL values exist first |
219
+
220
+ **Rule of thumb:** If the operation would cause a `SqlException` on running code, use a phased approach.
221
+ </decision_guide>
222
+
223
+ <sources>
224
+ - EF Core Migrations documentation
225
+ - Zero-Downtime Deployments with EF Core (Microsoft patterns)
226
+ - Blue-Green Deployment pattern (Martin Fowler)
227
+ </sources>
@@ -51,6 +51,25 @@ echo " Tables: $UP_TABLES"
51
51
  echo " Columns: $UP_COLUMNS"
52
52
  echo " Indexes: $UP_INDEXES"
53
53
  echo " Foreign Keys:$UP_FOREIGN"
54
+
55
+ # Detect destructive operations
56
+ DROP_COL=$(grep -c "DropColumn" "$MIGRATION_FILE" || echo "0")
57
+ RENAME_COL=$(grep -c "RenameColumn" "$MIGRATION_FILE" || echo "0")
58
+ ALTER_COL=$(grep -c "AlterColumn" "$MIGRATION_FILE" || echo "0")
59
+ DROP_TABLE=$(grep -c "DropTable" "$MIGRATION_FILE" || echo "0")
60
+ DESTRUCTIVE=$((DROP_COL + RENAME_COL + ALTER_COL + DROP_TABLE))
61
+
62
+ if [ "$DESTRUCTIVE" -gt 0 ]; then
63
+ echo ""
64
+ echo "WARNING: Destructive operations detected:"
65
+ [ "$DROP_COL" -gt 0 ] && echo " DropColumn: $DROP_COL"
66
+ [ "$RENAME_COL" -gt 0 ] && echo " RenameColumn: $RENAME_COL"
67
+ [ "$ALTER_COL" -gt 0 ] && echo " AlterColumn: $ALTER_COL"
68
+ [ "$DROP_TABLE" -gt 0 ] && echo " DropTable: $DROP_TABLE"
69
+ echo ""
70
+ echo "For production deployments, consider zero-downtime migration patterns."
71
+ echo "See: references/zero-downtime-patterns.md"
72
+ fi
54
73
  ```
55
74
 
56
75
  ### 3. Ask User to Validate
@@ -151,7 +151,8 @@ The MCP tool returns a structured report. Display it as-is or integrate key find
151
151
  - Authorization checks on every endpoint
152
152
  - No `eval()`, `exec()`, dangerous functions
153
153
 
154
- See [references/security-checklist.md](references/security-checklist.md) for OWASP Top 10 patterns.
154
+ See [references/security-checklist.md](references/security-checklist.md) for OWASP Top 10 patterns (web application vulnerabilities).
155
+ See [references/owasp-api-top10.md](references/owasp-api-top10.md) for OWASP API Security Top 10 (API-specific threats: BOLA, mass assignment, SSRF, resource consumption).
155
156
  </category>
156
157
 
157
158
  <category name="logic" priority="critical">
@@ -322,7 +323,8 @@ A good code review:
322
323
  <reference_guides>
323
324
  For detailed guidance and patterns:
324
325
 
325
- - **`references/security-checklist.md`** - OWASP Top 10, authentication patterns, input validation, common vulnerabilities
326
+ - **`references/security-checklist.md`** - OWASP Top 10, authentication patterns, input validation, rate limiting, security headers
327
+ - **`references/owasp-api-top10.md`** - OWASP API Security Top 10: BOLA, mass assignment, SSRF, resource consumption, SmartStack-specific detection patterns
326
328
  - **`references/clean-code-principles.md`** - SOLID principles, naming conventions, function design, code smell detection
327
329
  - **`references/feedback-patterns.md`** - Valuable vs wasteful feedback patterns, communication strategies, priority labeling
328
330
  - **`references/code-quality-metrics.md`** - Complexity calculations, maintainability index, measurement techniques