mdan-cli 2.5.0 → 2.6.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.
@@ -0,0 +1,567 @@
1
+ # Auto Phase 4: ARCHITECT
2
+
3
+ > Design system architecture
4
+
5
+ ## Objective
6
+
7
+ Design the system architecture, including components, data models, security, and deployment strategy.
8
+
9
+ ## Tasks
10
+
11
+ ### 4.1 Design System Architecture
12
+
13
+ - Define system components
14
+ - Design component interactions
15
+ - Create architecture diagrams
16
+ - Define data flow
17
+
18
+ ### 4.2 Design Data Models
19
+
20
+ - Create entity models
21
+ - Define relationships
22
+ - Design database schema
23
+ - Plan migrations
24
+
25
+ ### 4.3 Design Security Architecture
26
+
27
+ - Define authentication flow
28
+ - Design authorization model
29
+ - Plan security controls
30
+ - Define encryption strategy
31
+
32
+ ### 4.4 Design API Architecture
33
+
34
+ - Define API endpoints
35
+ - Design request/response models
36
+ - Plan API versioning
37
+ - Define error handling
38
+
39
+ ### 4.5 Design Deployment Architecture
40
+
41
+ - Define deployment strategy
42
+ - Design infrastructure
43
+ - Plan scaling approach
44
+ - Define monitoring strategy
45
+
46
+ ## Output
47
+
48
+ Generate `docs/architecture.md`:
49
+
50
+ ```markdown
51
+ # System Architecture
52
+
53
+ ## Overview
54
+
55
+ [High-level architecture description]
56
+
57
+ ## System Components
58
+
59
+ ### Frontend
60
+
61
+ **Blazor Server Application**
62
+ - User interface
63
+ - State management
64
+ - Client-side validation
65
+ - Real-time updates via SignalR
66
+
67
+ ### Backend
68
+
69
+ **ASP.NET Core Web API**
70
+ - RESTful API endpoints
71
+ - Business logic
72
+ - Data access layer
73
+ - Authentication/authorization
74
+
75
+ ### Database
76
+
77
+ **SQL Server 2022**
78
+ - User data
79
+ - Transaction records
80
+ - Audit logs
81
+ - Configuration data
82
+
83
+ ### External Services
84
+
85
+ - Azure AD (authentication)
86
+ - Generic external services (configurable)
87
+ - Azure Key Vault (secrets)
88
+
89
+ ## Architecture Diagram
90
+
91
+ ```
92
+ ┌─────────────┐
93
+ │ Browser │
94
+ └──────┬──────┘
95
+ │ HTTPS
96
+
97
+ ┌─────────────────┐
98
+ │ Azure App │
99
+ │ Service │
100
+ │ (Blazor Server)│
101
+ └──────┬──────────┘
102
+ │ SignalR
103
+
104
+ ┌─────────────────┐
105
+ │ ASP.NET Core │
106
+ │ Web API │
107
+ └──────┬──────────┘
108
+
109
+ ├─────────────┬─────────────┬─────────────┐
110
+ ▼ ▼ ▼ ▼
111
+ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
112
+ │Azure AD │ │External │ │External │ │Key Vault │
113
+ │ │ │Service 1 │ │Service 2 │ │ │
114
+ └──────────┘ └──────────┘ └──────────┘ └──────────┘
115
+
116
+
117
+ ┌─────────────────┐
118
+ │ SQL Server │
119
+ │ Database │
120
+ └─────────────────┘
121
+ ```
122
+
123
+ ## Data Models
124
+
125
+ ### User
126
+
127
+ ```csharp
128
+ public class User
129
+ {
130
+ public int Id { get; set; }
131
+ public string AzureAdId { get; set; }
132
+ public string Email { get; set; }
133
+ public string FirstName { get; set; }
134
+ public string LastName { get; set; }
135
+ public string Role { get; set; }
136
+ public DateTime CreatedAt { get; set; }
137
+ public DateTime? LastLoginAt { get; set; }
138
+ }
139
+ ```
140
+
141
+ ### ExternalService
142
+
143
+ ```csharp
144
+ public class ExternalService
145
+ {
146
+ public int Id { get; set; }
147
+ public string Name { get; set; }
148
+ public string BaseUrl { get; set; }
149
+ public string ApiKey { get; set; }
150
+ public int Timeout { get; set; }
151
+ public int RetryCount { get; set; }
152
+ public int RetryDelay { get; set; }
153
+ public bool EnableCircuitBreaker { get; set; }
154
+ public int CircuitBreakerThreshold { get; set; }
155
+ public bool EnableRateLimiting { get; set; }
156
+ public int RateLimitPerMinute { get; set; }
157
+ public bool EnableCaching { get; set; }
158
+ public int CacheDurationMinutes { get; set; }
159
+ public bool IsActive { get; set; }
160
+ public DateTime CreatedAt { get; set; }
161
+ public DateTime? LastSyncAt { get; set; }
162
+
163
+ public User User { get; set; }
164
+ }
165
+ ```
166
+
167
+ ### ServiceActivity
168
+
169
+ ```csharp
170
+ public class ServiceActivity
171
+ {
172
+ public int Id { get; set; }
173
+ public int ExternalServiceId { get; set; }
174
+ public string Type { get; set; } // request, response, error
175
+ public string Endpoint { get; set; }
176
+ public string Method { get; set; }
177
+ public int StatusCode { get; set; }
178
+ public long ResponseTime { get; set; }
179
+ public string? Description { get; set; }
180
+ public DateTime CreatedAt { get; set; }
181
+
182
+ public ExternalService ExternalService { get; set; }
183
+ }
184
+ ```
185
+
186
+ ### Notification
187
+
188
+ ```csharp
189
+ public class Notification
190
+ {
191
+ public int Id { get; set; }
192
+ public int UserId { get; set; }
193
+ public string Type { get; set; }
194
+ public string Title { get; set; }
195
+ public string Message { get; set; }
196
+ public bool IsRead { get; set; }
197
+ public DateTime CreatedAt { get; set; }
198
+ public DateTime? ReadAt { get; set; }
199
+
200
+ public User User { get; set; }
201
+ }
202
+ ```
203
+
204
+ ## Database Schema
205
+
206
+ ### Tables
207
+
208
+ **Users**
209
+ - Id (PK, int, identity)
210
+ - AzureAdId (nvarchar(100), unique)
211
+ - Email (nvarchar(255), unique)
212
+ - FirstName (nvarchar(100))
213
+ - LastName (nvarchar(100))
214
+ - Role (nvarchar(50))
215
+ - CreatedAt (datetime2)
216
+ - LastLoginAt (datetime2, nullable)
217
+
218
+ **ExternalServices**
219
+ - Id (PK, int, identity)
220
+ - UserId (FK, int)
221
+ - Name (nvarchar(100))
222
+ - BaseUrl (nvarchar(500))
223
+ - ApiKey (nvarchar(500))
224
+ - Timeout (int)
225
+ - RetryCount (int)
226
+ - RetryDelay (int)
227
+ - EnableCircuitBreaker (bit)
228
+ - CircuitBreakerThreshold (int)
229
+ - EnableRateLimiting (bit)
230
+ - RateLimitPerMinute (int)
231
+ - EnableCaching (bit)
232
+ - CacheDurationMinutes (int)
233
+ - IsActive (bit)
234
+ - CreatedAt (datetime2)
235
+ - LastSyncAt (datetime2, nullable)
236
+
237
+ **ServiceActivities**
238
+ - Id (PK, int, identity)
239
+ - ExternalServiceId (FK, int)
240
+ - Type (nvarchar(20))
241
+ - Endpoint (nvarchar(500))
242
+ - Method (nvarchar(10))
243
+ - StatusCode (int)
244
+ - ResponseTime (bigint)
245
+ - Description (nvarchar(1000))
246
+ - CreatedAt (datetime2)
247
+
248
+ **Notifications**
249
+ - Id (PK, int, identity)
250
+ - UserId (FK, int)
251
+ - Type (nvarchar(50))
252
+ - Title (nvarchar(200))
253
+ - Message (nvarchar(1000))
254
+ - IsRead (bit)
255
+ - CreatedAt (datetime2)
256
+ - ReadAt (datetime2, nullable)
257
+
258
+ ### Indexes
259
+
260
+ - IX_Users_AzureAdId on Users(AzureAdId)
261
+ - IX_Users_Email on Users(Email)
262
+ - IX_ExternalServices_UserId on ExternalServices(UserId)
263
+ - IX_ServiceActivities_ExternalServiceId on ServiceActivities(ExternalServiceId)
264
+ - IX_ServiceActivities_CreatedAt on ServiceActivities(CreatedAt)
265
+ - IX_Notifications_UserId on Notifications(UserId)
266
+ - IX_Notifications_IsRead on Notifications(IsRead)
267
+
268
+ ## Security Architecture
269
+
270
+ ### Authentication Flow
271
+
272
+ ```
273
+ 1. User navigates to application
274
+ 2. Redirected to Azure AD login
275
+ 3. User authenticates with Azure AD
276
+ 4. Azure AD returns JWT token
277
+ 5. Token validated by application
278
+ 6. User session established
279
+ 7. User can access protected resources
280
+ ```
281
+
282
+ ### Authorization Model
283
+
284
+ **Roles**:
285
+ - Admin: Full access
286
+ - User: Standard access
287
+ - Viewer: Read-only access
288
+
289
+ **Permissions**:
290
+ - Users: Read, Create, Update, Delete
291
+ - External Services: Read, Create, Update, Delete
292
+ - Service Activities: Read
293
+ - Notifications: Read, Update
294
+
295
+ ### Security Controls
296
+
297
+ - **Authentication**: Azure AD with JWT tokens
298
+ - **Authorization**: Role-based access control (RBAC)
299
+ - **Encryption**: TLS 1.3 for data in transit, AES-256 for data at rest
300
+ - **Input Validation**: Server-side validation for all inputs
301
+ - **Output Encoding**: Encode all outputs to prevent XSS
302
+ - **SQL Injection Prevention**: Parameterized queries
303
+ - **CSRF Protection**: Anti-forgery tokens
304
+ - **Rate Limiting**: API rate limiting
305
+ - **Audit Logging**: All actions logged
306
+ - **Secrets Management**: Azure Key Vault
307
+
308
+ ## API Architecture
309
+
310
+ ### Endpoints
311
+
312
+ **Authentication**
313
+ - POST /api/auth/login - Login with Azure AD
314
+ - POST /api/auth/logout - Logout
315
+ - GET /api/auth/me - Get current user
316
+
317
+ **Users**
318
+ - GET /api/users - List users (Admin)
319
+ - GET /api/users/{id} - Get user details
320
+ - PUT /api/users/{id} - Update user
321
+ - DELETE /api/users/{id} - Delete user (Admin)
322
+
323
+ **External Services**
324
+ - GET /api/external-services - List external services
325
+ - GET /api/external-services/{id} - Get service details
326
+ - POST /api/external-services - Add service
327
+ - PUT /api/external-services/{id} - Update service
328
+ - DELETE /api/external-services/{id} - Delete service
329
+ - GET /api/external-services/{id}/status - Get service status
330
+
331
+ **Service Activities**
332
+ - GET /api/service-activities - List service activities
333
+ - GET /api/service-activities/{id} - Get activity details
334
+ - GET /api/external-services/{id}/activities - Get service activities
335
+
336
+ **Notifications**
337
+ - GET /api/notifications - List notifications
338
+ - GET /api/notifications/{id} - Get notification
339
+ - PUT /api/notifications/{id}/read - Mark as read
340
+ - PUT /api/notifications/read-all - Mark all as read
341
+
342
+ ### Request/Response Models
343
+
344
+ **User Response**
345
+ ```json
346
+ {
347
+ "id": 1,
348
+ "email": "user@example.com",
349
+ "firstName": "John",
350
+ "lastName": "Doe",
351
+ "role": "User",
352
+ "createdAt": "2024-01-15T10:00:00Z"
353
+ }
354
+ ```
355
+
356
+ **External Service Response**
357
+ ```json
358
+ {
359
+ "id": 1,
360
+ "name": "ServiceName",
361
+ "baseUrl": "https://api.example.com/v1",
362
+ "status": "Active",
363
+ "lastSyncAt": "2024-01-15T10:00:00Z"
364
+ }
365
+ ```
366
+
367
+ **Service Activity Response**
368
+ ```json
369
+ {
370
+ "id": 1,
371
+ "externalServiceId": 1,
372
+ "type": "request",
373
+ "endpoint": "/api/data",
374
+ "method": "GET",
375
+ "statusCode": 200,
376
+ "responseTime": 150,
377
+ "createdAt": "2024-01-15T10:00:00Z"
378
+ }
379
+ ```
380
+
381
+ ### Error Handling
382
+
383
+ **Error Response Format**
384
+ ```json
385
+ {
386
+ "error": {
387
+ "code": "VALIDATION_ERROR",
388
+ "message": "Invalid input",
389
+ "details": [
390
+ {
391
+ "field": "email",
392
+ "message": "Email is required"
393
+ }
394
+ ]
395
+ }
396
+ }
397
+ ```
398
+
399
+ **Error Codes**
400
+ - VALIDATION_ERROR (400)
401
+ - UNAUTHORIZED (401)
402
+ - FORBIDDEN (403)
403
+ - NOT_FOUND (404)
404
+ - CONFLICT (409)
405
+ - INTERNAL_ERROR (500)
406
+
407
+ ## Deployment Architecture
408
+
409
+ ### Azure Resources
410
+
411
+ **App Service**
412
+ - Blazor Server application
413
+ - ASP.NET Core Web API
414
+ - Scaling: Auto-scale based on CPU/memory
415
+ - Deployment slots: Production, Staging
416
+
417
+ **SQL Database**
418
+ - Azure SQL Database
419
+ - Tier: Standard S2
420
+ - Geo-replication: Enabled
421
+ - Backup: 7-day retention
422
+
423
+ **Key Vault**
424
+ - Store secrets (API keys, connection strings)
425
+ - Access policies: RBAC
426
+ - Soft delete: Enabled
427
+
428
+ **Application Insights**
429
+ - Monitoring and logging
430
+ - Performance tracking
431
+ - Error tracking
432
+ - Usage analytics
433
+
434
+ ### Deployment Strategy
435
+
436
+ **CI/CD Pipeline**
437
+ 1. Code pushed to GitHub
438
+ 2. Azure DevOps build triggered
439
+ 3. Run tests
440
+ 4. Build application
441
+ 5. Deploy to staging
442
+ 6. Run smoke tests
443
+ 7. Deploy to production
444
+
445
+ **Blue-Green Deployment**
446
+ - Zero downtime deployments
447
+ - Instant rollback capability
448
+ - Traffic routing via Azure Front Door
449
+
450
+ ### Scaling Strategy
451
+
452
+ **Horizontal Scaling**
453
+ - Auto-scale based on metrics
454
+ - Scale out: Add instances
455
+ - Scale in: Remove instances
456
+
457
+ **Vertical Scaling**
458
+ - Upgrade App Service plan
459
+ - Increase database DTUs
460
+ - Monitor performance
461
+
462
+ ## Monitoring Strategy
463
+
464
+ ### Metrics to Monitor
465
+
466
+ - Application performance
467
+ - Response times
468
+ - Error rates
469
+ - Database performance
470
+ - API usage
471
+ - User activity
472
+
473
+ ### Alerts
474
+
475
+ - High error rate (>5%)
476
+ - Slow response times (>2s)
477
+ - Database connection issues
478
+ - Authentication failures
479
+ - API rate limit breaches
480
+
481
+ ### Logging
482
+
483
+ - Application logs
484
+ - Audit logs
485
+ - Security logs
486
+ - Performance logs
487
+
488
+ ## Technology Stack
489
+
490
+ - **Frontend**: Blazor Server, .NET 8.0
491
+ - **Backend**: ASP.NET Core Web API, .NET 8.0
492
+ - **Database**: SQL Server 2022, Entity Framework Core
493
+ - **Authentication**: Azure AD, JWT
494
+ - **Cloud**: Azure App Service, Azure SQL Database
495
+ - **CI/CD**: Azure DevOps
496
+ - **Monitoring**: Application Insights
497
+
498
+ ## Next Steps
499
+
500
+ Proceed to IMPLEMENT phase.
501
+ ```
502
+
503
+ ## Quality Gates
504
+
505
+ - [ ] Architecture documented
506
+ - [ ] Data models defined
507
+ - [ ] Security designed
508
+ - [ ] API designed
509
+ - [ ] Deployment planned
510
+
511
+ ## Success Criteria
512
+
513
+ - Architecture is clear and complete
514
+ - Data models cover all requirements
515
+ - Security is comprehensive
516
+ - API is well-defined
517
+ - Deployment is feasible
518
+
519
+ ## Error Handling
520
+
521
+ ### Architecture Conflicts
522
+
523
+ - Trigger debate
524
+ - Resolve conflict
525
+ - Document decision
526
+ - Continue
527
+
528
+ ### Missing Components
529
+
530
+ - Log warning
531
+ - Add placeholder
532
+ - Document gap
533
+ - Continue
534
+
535
+ ## Token Management
536
+
537
+ Track token usage:
538
+ - Architecture design: ~6,000 tokens
539
+ - Data models: ~4,000 tokens
540
+ - Security design: ~4,000 tokens
541
+ - API design: ~4,000 tokens
542
+ - Deployment design: ~3,000 tokens
543
+
544
+ Total: ~21,000 tokens
545
+
546
+ ## Logging
547
+
548
+ ```
549
+ [timestamp] Starting ARCHITECT phase
550
+ [timestamp] Designing system architecture...
551
+ [timestamp] Designing data models...
552
+ [timestamp] Designing security architecture...
553
+ [timestamp] Designing API architecture...
554
+ [timestamp] Designing deployment architecture...
555
+ [timestamp] Token usage: X / 128,000 (X%)
556
+ [timestamp] ARCHITECT phase complete
557
+ ```
558
+
559
+ ## Completion Signal
560
+
561
+ ```
562
+ PHASE 4 COMPLETE ✅
563
+ ```
564
+
565
+ ## Version
566
+
567
+ MDAN-AUTO Phase 4: ARCHITECT v1.0