@polymorphism-tech/morph-spec 1.0.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.
- package/README.md +279 -0
- package/bin/morph-spec.js +53 -0
- package/content/.claude/commands/morph-apply.md +66 -0
- package/content/.claude/commands/morph-archive.md +79 -0
- package/content/.claude/commands/morph-costs.md +206 -0
- package/content/.claude/commands/morph-infra.md +209 -0
- package/content/.claude/commands/morph-proposal.md +60 -0
- package/content/.claude/commands/morph-status.md +71 -0
- package/content/.claude/settings.local.json +15 -0
- package/content/.claude/skills/infra/bicep-architect.md +419 -0
- package/content/.claude/skills/infra/container-specialist.md +437 -0
- package/content/.claude/skills/infra/devops-engineer.md +405 -0
- package/content/.claude/skills/integrations/asaas-financial.md +333 -0
- package/content/.claude/skills/integrations/azure-identity.md +309 -0
- package/content/.claude/skills/integrations/clerk-auth.md +290 -0
- package/content/.claude/skills/specialists/azure-architect.md +142 -0
- package/content/.claude/skills/specialists/cost-guardian.md +110 -0
- package/content/.claude/skills/specialists/ef-modeler.md +200 -0
- package/content/.claude/skills/specialists/hangfire-orchestrator.md +245 -0
- package/content/.claude/skills/specialists/ms-agent-expert.md +209 -0
- package/content/.claude/skills/specialists/po-pm-advisor.md +197 -0
- package/content/.claude/skills/specialists/standards-architect.md +78 -0
- package/content/.claude/skills/specialists/ui-ux-designer.md +325 -0
- package/content/.claude/skills/stacks/dotnet-blazor.md +352 -0
- package/content/.claude/skills/stacks/dotnet-nextjs.md +402 -0
- package/content/.claude/skills/stacks/shopify.md +445 -0
- package/content/.morph/archive/.gitkeep +25 -0
- package/content/.morph/config/agents.json +149 -0
- package/content/.morph/config/config.template.json +96 -0
- package/content/.morph/examples/api-nextjs/README.md +241 -0
- package/content/.morph/examples/api-nextjs/contracts.ts +307 -0
- package/content/.morph/examples/api-nextjs/spec.md +399 -0
- package/content/.morph/examples/api-nextjs/tasks.md +168 -0
- package/content/.morph/examples/micro-saas/README.md +125 -0
- package/content/.morph/examples/micro-saas/contracts.cs +358 -0
- package/content/.morph/examples/micro-saas/decisions.md +246 -0
- package/content/.morph/examples/micro-saas/spec.md +236 -0
- package/content/.morph/examples/micro-saas/tasks.md +150 -0
- package/content/.morph/examples/multi-agent/README.md +309 -0
- package/content/.morph/examples/multi-agent/contracts.cs +433 -0
- package/content/.morph/examples/multi-agent/spec.md +479 -0
- package/content/.morph/examples/multi-agent/tasks.md +185 -0
- package/content/.morph/features/.gitkeep +25 -0
- package/content/.morph/project.md +159 -0
- package/content/.morph/specs/.gitkeep +20 -0
- package/content/.morph/standards/architecture.md +190 -0
- package/content/.morph/standards/azure.md +184 -0
- package/content/.morph/standards/coding.md +342 -0
- package/content/.morph/templates/agent.cs +172 -0
- package/content/.morph/templates/component.razor +239 -0
- package/content/.morph/templates/contracts.cs +217 -0
- package/content/.morph/templates/decisions.md +106 -0
- package/content/.morph/templates/infra/app-insights.bicep +63 -0
- package/content/.morph/templates/infra/container-app-env.bicep +49 -0
- package/content/.morph/templates/infra/container-app.bicep +156 -0
- package/content/.morph/templates/infra/key-vault.bicep +91 -0
- package/content/.morph/templates/infra/main.bicep +155 -0
- package/content/.morph/templates/infra/parameters.dev.json +23 -0
- package/content/.morph/templates/infra/parameters.prod.json +23 -0
- package/content/.morph/templates/infra/sql-database.bicep +103 -0
- package/content/.morph/templates/infra/storage.bicep +106 -0
- package/content/.morph/templates/integrations/asaas-client.cs +387 -0
- package/content/.morph/templates/integrations/asaas-webhook.cs +351 -0
- package/content/.morph/templates/integrations/azure-identity-config.cs +288 -0
- package/content/.morph/templates/integrations/clerk-config.cs +258 -0
- package/content/.morph/templates/job.cs +171 -0
- package/content/.morph/templates/migration.cs +83 -0
- package/content/.morph/templates/proposal.md +155 -0
- package/content/.morph/templates/recap.md +105 -0
- package/content/.morph/templates/repository.cs +141 -0
- package/content/.morph/templates/saas/subscription.cs +347 -0
- package/content/.morph/templates/saas/tenant.cs +338 -0
- package/content/.morph/templates/service.cs +139 -0
- package/content/.morph/templates/spec.md +147 -0
- package/content/.morph/templates/tasks.md +235 -0
- package/content/.morph/templates/test.cs +239 -0
- package/content/CLAUDE.md +318 -0
- package/package.json +50 -0
- package/src/commands/doctor.js +132 -0
- package/src/commands/init.js +121 -0
- package/src/commands/update.js +84 -0
- package/src/utils/file-copier.js +50 -0
- package/src/utils/logger.js +32 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
// ==============================================================================
|
|
2
|
+
// Micro-SaaS - Contracts
|
|
3
|
+
// Interfaces, DTOs e Enums do exemplo Micro-SaaS
|
|
4
|
+
// ==============================================================================
|
|
5
|
+
|
|
6
|
+
namespace MicroSaaS.Contracts;
|
|
7
|
+
|
|
8
|
+
// ==============================================================================
|
|
9
|
+
// ENUMS
|
|
10
|
+
// ==============================================================================
|
|
11
|
+
|
|
12
|
+
public enum TenantStatus
|
|
13
|
+
{
|
|
14
|
+
Active,
|
|
15
|
+
Suspended,
|
|
16
|
+
Deleted
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public enum TenantUserRole
|
|
20
|
+
{
|
|
21
|
+
Owner,
|
|
22
|
+
Admin,
|
|
23
|
+
Member,
|
|
24
|
+
Viewer
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public enum TenantUserStatus
|
|
28
|
+
{
|
|
29
|
+
Pending,
|
|
30
|
+
Active,
|
|
31
|
+
Inactive
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public enum SubscriptionStatus
|
|
35
|
+
{
|
|
36
|
+
Trial,
|
|
37
|
+
Active,
|
|
38
|
+
PastDue,
|
|
39
|
+
Canceled,
|
|
40
|
+
Expired
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public enum BillingCycle
|
|
44
|
+
{
|
|
45
|
+
Monthly,
|
|
46
|
+
Yearly
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public enum PaymentStatus
|
|
50
|
+
{
|
|
51
|
+
Pending,
|
|
52
|
+
Confirmed,
|
|
53
|
+
Received,
|
|
54
|
+
Overdue,
|
|
55
|
+
Refunded,
|
|
56
|
+
Chargeback
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public enum PaymentMethod
|
|
60
|
+
{
|
|
61
|
+
Pix,
|
|
62
|
+
Boleto,
|
|
63
|
+
CreditCard
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ==============================================================================
|
|
67
|
+
// DTOs - TENANT
|
|
68
|
+
// ==============================================================================
|
|
69
|
+
|
|
70
|
+
public record CreateTenantRequest(
|
|
71
|
+
string Name,
|
|
72
|
+
string Slug,
|
|
73
|
+
string OwnerEmail,
|
|
74
|
+
string OwnerExternalId
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
public record UpdateTenantRequest(
|
|
78
|
+
string Name,
|
|
79
|
+
string? Description,
|
|
80
|
+
string? LogoUrl
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
public record TenantResponse(
|
|
84
|
+
int Id,
|
|
85
|
+
string Name,
|
|
86
|
+
string Slug,
|
|
87
|
+
string? Description,
|
|
88
|
+
string? LogoUrl,
|
|
89
|
+
TenantStatus Status,
|
|
90
|
+
string? CustomDomain,
|
|
91
|
+
SubscriptionSummaryResponse? Subscription,
|
|
92
|
+
DateTime CreatedAt
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
public record TenantSummaryResponse(
|
|
96
|
+
int Id,
|
|
97
|
+
string Name,
|
|
98
|
+
string Slug,
|
|
99
|
+
TenantStatus Status
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// ==============================================================================
|
|
103
|
+
// DTOs - TENANT USER
|
|
104
|
+
// ==============================================================================
|
|
105
|
+
|
|
106
|
+
public record InviteUserRequest(
|
|
107
|
+
string Email,
|
|
108
|
+
TenantUserRole Role = TenantUserRole.Member
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
public record UpdateUserRoleRequest(
|
|
112
|
+
TenantUserRole Role
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
public record TenantUserResponse(
|
|
116
|
+
int Id,
|
|
117
|
+
string Email,
|
|
118
|
+
string? Name,
|
|
119
|
+
TenantUserRole Role,
|
|
120
|
+
TenantUserStatus Status,
|
|
121
|
+
DateTime? LastLoginAt,
|
|
122
|
+
DateTime CreatedAt
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// ==============================================================================
|
|
126
|
+
// DTOs - PLAN
|
|
127
|
+
// ==============================================================================
|
|
128
|
+
|
|
129
|
+
public record PlanResponse(
|
|
130
|
+
int Id,
|
|
131
|
+
string Name,
|
|
132
|
+
string? Description,
|
|
133
|
+
decimal PriceMonthly,
|
|
134
|
+
decimal PriceYearly,
|
|
135
|
+
PlanLimits Limits,
|
|
136
|
+
PlanFeatures Features,
|
|
137
|
+
bool IsActive
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
public record PlanLimits(
|
|
141
|
+
int MaxUsers,
|
|
142
|
+
long MaxStorageBytes,
|
|
143
|
+
int MaxApiRequestsPerMonth
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
public record PlanFeatures(
|
|
147
|
+
bool CustomDomain,
|
|
148
|
+
bool ApiAccess,
|
|
149
|
+
bool PrioritySupport,
|
|
150
|
+
bool AdvancedAnalytics
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// ==============================================================================
|
|
154
|
+
// DTOs - SUBSCRIPTION
|
|
155
|
+
// ==============================================================================
|
|
156
|
+
|
|
157
|
+
public record CreateSubscriptionRequest(
|
|
158
|
+
int PlanId,
|
|
159
|
+
BillingCycle BillingCycle,
|
|
160
|
+
PaymentMethod PaymentMethod
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
public record UpgradeSubscriptionRequest(
|
|
164
|
+
int NewPlanId,
|
|
165
|
+
bool ImmediateUpgrade = true
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
public record SubscriptionResponse(
|
|
169
|
+
int Id,
|
|
170
|
+
int TenantId,
|
|
171
|
+
PlanResponse Plan,
|
|
172
|
+
SubscriptionStatus Status,
|
|
173
|
+
BillingCycle BillingCycle,
|
|
174
|
+
DateTime CurrentPeriodStart,
|
|
175
|
+
DateTime CurrentPeriodEnd,
|
|
176
|
+
DateTime? TrialEndsAt,
|
|
177
|
+
DateTime? CanceledAt,
|
|
178
|
+
string? AsaasSubscriptionId,
|
|
179
|
+
DateTime CreatedAt
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
public record SubscriptionSummaryResponse(
|
|
183
|
+
int Id,
|
|
184
|
+
string PlanName,
|
|
185
|
+
SubscriptionStatus Status,
|
|
186
|
+
DateTime CurrentPeriodEnd,
|
|
187
|
+
int DaysRemaining
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
// ==============================================================================
|
|
191
|
+
// DTOs - PAYMENT
|
|
192
|
+
// ==============================================================================
|
|
193
|
+
|
|
194
|
+
public record PaymentResponse(
|
|
195
|
+
int Id,
|
|
196
|
+
decimal Amount,
|
|
197
|
+
PaymentStatus Status,
|
|
198
|
+
PaymentMethod Method,
|
|
199
|
+
DateTime? PaidAt,
|
|
200
|
+
DateTime DueDate,
|
|
201
|
+
string? AsaasPaymentId,
|
|
202
|
+
string? InvoiceUrl,
|
|
203
|
+
string? PixQrCode,
|
|
204
|
+
string? BoletoBarcode
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
// ==============================================================================
|
|
208
|
+
// DTOs - DASHBOARD
|
|
209
|
+
// ==============================================================================
|
|
210
|
+
|
|
211
|
+
public record DashboardResponse(
|
|
212
|
+
TenantSummaryResponse Tenant,
|
|
213
|
+
SubscriptionSummaryResponse? Subscription,
|
|
214
|
+
DashboardMetrics Metrics,
|
|
215
|
+
IReadOnlyList<RecentActivityItem> RecentActivity
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
public record DashboardMetrics(
|
|
219
|
+
int TotalUsers,
|
|
220
|
+
int ActiveUsers,
|
|
221
|
+
long StorageUsedBytes,
|
|
222
|
+
long StorageLimitBytes,
|
|
223
|
+
int ApiRequestsThisMonth,
|
|
224
|
+
int ApiRequestsLimit
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
public record RecentActivityItem(
|
|
228
|
+
string Description,
|
|
229
|
+
string? UserId,
|
|
230
|
+
string? UserName,
|
|
231
|
+
DateTime Timestamp
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
// ==============================================================================
|
|
235
|
+
// DTOs - WEBHOOKS
|
|
236
|
+
// ==============================================================================
|
|
237
|
+
|
|
238
|
+
public record AsaasWebhookPayload(
|
|
239
|
+
string Event,
|
|
240
|
+
AsaasPaymentData? Payment
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
public record AsaasPaymentData(
|
|
244
|
+
string Id,
|
|
245
|
+
string Customer,
|
|
246
|
+
string? Subscription,
|
|
247
|
+
decimal Value,
|
|
248
|
+
decimal NetValue,
|
|
249
|
+
string Status,
|
|
250
|
+
string BillingType,
|
|
251
|
+
DateTime? PaymentDate,
|
|
252
|
+
DateTime DueDate
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
// ==============================================================================
|
|
256
|
+
// INTERFACES - SERVICES
|
|
257
|
+
// ==============================================================================
|
|
258
|
+
|
|
259
|
+
public interface ITenantService
|
|
260
|
+
{
|
|
261
|
+
Task<TenantResponse> CreateAsync(CreateTenantRequest request, CancellationToken ct = default);
|
|
262
|
+
Task<TenantResponse?> GetByIdAsync(int id, CancellationToken ct = default);
|
|
263
|
+
Task<TenantResponse?> GetBySlugAsync(string slug, CancellationToken ct = default);
|
|
264
|
+
Task<TenantResponse> UpdateAsync(int id, UpdateTenantRequest request, CancellationToken ct = default);
|
|
265
|
+
Task SuspendAsync(int id, CancellationToken ct = default);
|
|
266
|
+
Task ActivateAsync(int id, CancellationToken ct = default);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
public interface ITenantUserService
|
|
270
|
+
{
|
|
271
|
+
Task<IReadOnlyList<TenantUserResponse>> GetByTenantAsync(int tenantId, CancellationToken ct = default);
|
|
272
|
+
Task<TenantUserResponse> InviteAsync(int tenantId, InviteUserRequest request, CancellationToken ct = default);
|
|
273
|
+
Task<TenantUserResponse> UpdateRoleAsync(int tenantId, int userId, UpdateUserRoleRequest request, CancellationToken ct = default);
|
|
274
|
+
Task RemoveAsync(int tenantId, int userId, CancellationToken ct = default);
|
|
275
|
+
Task RecordLoginAsync(string externalUserId, CancellationToken ct = default);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
public interface ISubscriptionService
|
|
279
|
+
{
|
|
280
|
+
Task<SubscriptionResponse> CreateAsync(int tenantId, CreateSubscriptionRequest request, CancellationToken ct = default);
|
|
281
|
+
Task<SubscriptionResponse?> GetCurrentAsync(int tenantId, CancellationToken ct = default);
|
|
282
|
+
Task<SubscriptionResponse> UpgradeAsync(int tenantId, UpgradeSubscriptionRequest request, CancellationToken ct = default);
|
|
283
|
+
Task CancelAsync(int tenantId, CancellationToken ct = default);
|
|
284
|
+
Task<IReadOnlyList<PaymentResponse>> GetPaymentsAsync(int tenantId, CancellationToken ct = default);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
public interface IPlanService
|
|
288
|
+
{
|
|
289
|
+
Task<IReadOnlyList<PlanResponse>> GetAllAsync(CancellationToken ct = default);
|
|
290
|
+
Task<PlanResponse?> GetByIdAsync(int id, CancellationToken ct = default);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
public interface IDashboardService
|
|
294
|
+
{
|
|
295
|
+
Task<DashboardResponse> GetDashboardAsync(int tenantId, CancellationToken ct = default);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
public interface IWebhookService
|
|
299
|
+
{
|
|
300
|
+
Task HandleAsaasWebhookAsync(AsaasWebhookPayload payload, CancellationToken ct = default);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// ==============================================================================
|
|
304
|
+
// INTERFACES - REPOSITORIES
|
|
305
|
+
// ==============================================================================
|
|
306
|
+
|
|
307
|
+
public interface ITenantRepository
|
|
308
|
+
{
|
|
309
|
+
Task<Tenant?> GetByIdAsync(int id, CancellationToken ct = default);
|
|
310
|
+
Task<Tenant?> GetBySlugAsync(string slug, CancellationToken ct = default);
|
|
311
|
+
Task<bool> SlugExistsAsync(string slug, CancellationToken ct = default);
|
|
312
|
+
Task AddAsync(Tenant tenant, CancellationToken ct = default);
|
|
313
|
+
void Update(Tenant tenant);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
public interface ITenantUserRepository
|
|
317
|
+
{
|
|
318
|
+
Task<IReadOnlyList<TenantUser>> GetByTenantAsync(int tenantId, CancellationToken ct = default);
|
|
319
|
+
Task<TenantUser?> GetByIdAsync(int id, CancellationToken ct = default);
|
|
320
|
+
Task<TenantUser?> GetByExternalIdAsync(string externalUserId, CancellationToken ct = default);
|
|
321
|
+
Task AddAsync(TenantUser user, CancellationToken ct = default);
|
|
322
|
+
void Update(TenantUser user);
|
|
323
|
+
void Remove(TenantUser user);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
public interface ISubscriptionRepository
|
|
327
|
+
{
|
|
328
|
+
Task<Subscription?> GetByIdAsync(int id, CancellationToken ct = default);
|
|
329
|
+
Task<Subscription?> GetCurrentByTenantAsync(int tenantId, CancellationToken ct = default);
|
|
330
|
+
Task<Subscription?> GetByAsaasIdAsync(string asaasSubscriptionId, CancellationToken ct = default);
|
|
331
|
+
Task AddAsync(Subscription subscription, CancellationToken ct = default);
|
|
332
|
+
void Update(Subscription subscription);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
public interface IPlanRepository
|
|
336
|
+
{
|
|
337
|
+
Task<IReadOnlyList<Plan>> GetAllActiveAsync(CancellationToken ct = default);
|
|
338
|
+
Task<Plan?> GetByIdAsync(int id, CancellationToken ct = default);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
public interface IPaymentRepository
|
|
342
|
+
{
|
|
343
|
+
Task<IReadOnlyList<SubscriptionPayment>> GetBySubscriptionAsync(int subscriptionId, CancellationToken ct = default);
|
|
344
|
+
Task<SubscriptionPayment?> GetByAsaasIdAsync(string asaasPaymentId, CancellationToken ct = default);
|
|
345
|
+
Task AddAsync(SubscriptionPayment payment, CancellationToken ct = default);
|
|
346
|
+
void Update(SubscriptionPayment payment);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// ==============================================================================
|
|
350
|
+
// PLACEHOLDER ENTITY REFERENCES (implementados em Domain)
|
|
351
|
+
// ==============================================================================
|
|
352
|
+
|
|
353
|
+
// Estas classes são placeholders - a implementação real está em Domain/Entities
|
|
354
|
+
public class Tenant { public int Id { get; set; } }
|
|
355
|
+
public class TenantUser { public int Id { get; set; } }
|
|
356
|
+
public class Subscription { public int Id { get; set; } }
|
|
357
|
+
public class Plan { public int Id { get; set; } }
|
|
358
|
+
public class SubscriptionPayment { public int Id { get; set; } }
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Micro-SaaS - Architectural Decision Records
|
|
2
|
+
|
|
3
|
+
## ADR-001: Blazor Server vs Blazor WebAssembly
|
|
4
|
+
|
|
5
|
+
**Status**: Accepted
|
|
6
|
+
|
|
7
|
+
**Context**: Escolher entre Blazor Server e Blazor WebAssembly para o frontend.
|
|
8
|
+
|
|
9
|
+
**Decision**: Blazor Server
|
|
10
|
+
|
|
11
|
+
**Rationale**:
|
|
12
|
+
- Melhor para dashboards com dados em tempo real
|
|
13
|
+
- Menor payload inicial
|
|
14
|
+
- Acesso direto ao backend (sem API intermediária)
|
|
15
|
+
- Melhor SEO com pre-rendering
|
|
16
|
+
- Scale-to-zero funciona bem com Container Apps
|
|
17
|
+
|
|
18
|
+
**Consequences**:
|
|
19
|
+
- Requer conexão SignalR persistente
|
|
20
|
+
- Latência perceptível em conexões lentas
|
|
21
|
+
- Não funciona offline
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## ADR-002: Asaas vs Stripe para Billing
|
|
26
|
+
|
|
27
|
+
**Status**: Accepted
|
|
28
|
+
|
|
29
|
+
**Context**: Escolher gateway de pagamento para mercado brasileiro.
|
|
30
|
+
|
|
31
|
+
**Decision**: Asaas
|
|
32
|
+
|
|
33
|
+
**Rationale**:
|
|
34
|
+
- Suporte nativo a PIX e Boleto
|
|
35
|
+
- Taxas competitivas para Brasil
|
|
36
|
+
- API bem documentada
|
|
37
|
+
- Webhooks confiáveis
|
|
38
|
+
- Gestão de assinaturas built-in
|
|
39
|
+
|
|
40
|
+
**Consequences**:
|
|
41
|
+
- Limitado ao mercado brasileiro
|
|
42
|
+
- Menos features que Stripe
|
|
43
|
+
- Se expandir internacionalmente, precisará adicionar outro gateway
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## ADR-003: Clerk vs Azure AD B2C para Auth
|
|
48
|
+
|
|
49
|
+
**Status**: Accepted
|
|
50
|
+
|
|
51
|
+
**Context**: Escolher provider de autenticação.
|
|
52
|
+
|
|
53
|
+
**Decision**: Clerk (com Azure AD como alternativa)
|
|
54
|
+
|
|
55
|
+
**Rationale**:
|
|
56
|
+
- Setup mais simples
|
|
57
|
+
- UI pré-construída
|
|
58
|
+
- Boa integração com .NET
|
|
59
|
+
- Free tier generoso (10k MAU)
|
|
60
|
+
- Organization support para multi-tenancy
|
|
61
|
+
|
|
62
|
+
**Alternatives Considered**:
|
|
63
|
+
- Azure AD B2C: Mais complexo, mas melhor para enterprise
|
|
64
|
+
- Auth0: Boa opção, mas mais caro
|
|
65
|
+
|
|
66
|
+
**Consequences**:
|
|
67
|
+
- Dependência de serviço terceiro
|
|
68
|
+
- Custo em escala (após 10k MAU)
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## ADR-004: Multi-Tenancy Strategy
|
|
73
|
+
|
|
74
|
+
**Status**: Accepted
|
|
75
|
+
|
|
76
|
+
**Context**: Definir estratégia de isolamento de dados.
|
|
77
|
+
|
|
78
|
+
**Decision**: Database-per-tenant com query filter
|
|
79
|
+
|
|
80
|
+
**Rationale**:
|
|
81
|
+
- Single database com `TenantId` em cada tabela
|
|
82
|
+
- EF Core Global Query Filters para isolamento
|
|
83
|
+
- Mais econômico que database separado
|
|
84
|
+
- Escala bem para milhares de tenants
|
|
85
|
+
|
|
86
|
+
**Implementation**:
|
|
87
|
+
```csharp
|
|
88
|
+
modelBuilder.Entity<Order>()
|
|
89
|
+
.HasQueryFilter(o => o.TenantId == _tenantContext.TenantId);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Consequences**:
|
|
93
|
+
- Cuidado extra com queries que bypassam filtros
|
|
94
|
+
- Backup/restore é do banco inteiro
|
|
95
|
+
- Migração de tenant individual é mais complexa
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## ADR-005: Tenant Resolution Strategy
|
|
100
|
+
|
|
101
|
+
**Status**: Accepted
|
|
102
|
+
|
|
103
|
+
**Context**: Como identificar o tenant em cada request.
|
|
104
|
+
|
|
105
|
+
**Decision**: Multiple strategies (subdomain > header > route > claim)
|
|
106
|
+
|
|
107
|
+
**Rationale**:
|
|
108
|
+
1. **Subdomain** (`acme.app.com`): Mais limpo para usuários
|
|
109
|
+
2. **Header** (`X-Tenant-ID`): Para APIs
|
|
110
|
+
3. **Route** (`/tenant/{slug}`): Fallback
|
|
111
|
+
4. **Claim**: Para JWT tokens
|
|
112
|
+
|
|
113
|
+
**Consequences**:
|
|
114
|
+
- DNS wildcard necessário
|
|
115
|
+
- Configuração de CORS mais complexa
|
|
116
|
+
- Custom domains requerem SSL wildcard ou certificados individuais
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## ADR-006: Azure Container Apps vs App Service
|
|
121
|
+
|
|
122
|
+
**Status**: Accepted
|
|
123
|
+
|
|
124
|
+
**Context**: Escolher serviço de hosting.
|
|
125
|
+
|
|
126
|
+
**Decision**: Azure Container Apps
|
|
127
|
+
|
|
128
|
+
**Rationale**:
|
|
129
|
+
- Scale-to-zero (custo zero quando inativo)
|
|
130
|
+
- Auto-scaling baseado em HTTP requests
|
|
131
|
+
- Built-in ingress controller
|
|
132
|
+
- Managed identity integration
|
|
133
|
+
- Mais barato para cargas variáveis
|
|
134
|
+
|
|
135
|
+
**Consequences**:
|
|
136
|
+
- Cold start de ~2-5 segundos
|
|
137
|
+
- Menos features que App Service
|
|
138
|
+
- Debugging mais complexo
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## ADR-007: SQL Server Free Tier
|
|
143
|
+
|
|
144
|
+
**Status**: Accepted
|
|
145
|
+
|
|
146
|
+
**Context**: Escolher tier de database.
|
|
147
|
+
|
|
148
|
+
**Decision**: SQL Server Free Tier (32GB)
|
|
149
|
+
|
|
150
|
+
**Rationale**:
|
|
151
|
+
- Custo zero para desenvolvimento e MVPs
|
|
152
|
+
- 32GB suficiente para milhares de tenants pequenos
|
|
153
|
+
- Upgrade fácil quando necessário
|
|
154
|
+
- Compatível com EF Core
|
|
155
|
+
|
|
156
|
+
**Consequences**:
|
|
157
|
+
- Limites de DTU/vCore
|
|
158
|
+
- Sem geo-replication
|
|
159
|
+
- Upgrade necessário para produção de alta escala
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## ADR-008: Subscription Lifecycle
|
|
164
|
+
|
|
165
|
+
**Status**: Accepted
|
|
166
|
+
|
|
167
|
+
**Context**: Definir estados e transições de subscription.
|
|
168
|
+
|
|
169
|
+
**Decision**: Estado máquina com 5 estados
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
Trial → Active → PastDue → Canceled
|
|
173
|
+
↓
|
|
174
|
+
Expired
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**States**:
|
|
178
|
+
- **Trial**: 14 dias sem cobrança
|
|
179
|
+
- **Active**: Pagamento em dia
|
|
180
|
+
- **PastDue**: Pagamento atrasado (grace period 7 dias)
|
|
181
|
+
- **Canceled**: Cancelado pelo usuário
|
|
182
|
+
- **Expired**: Trial ou grace period expirado
|
|
183
|
+
|
|
184
|
+
**Consequences**:
|
|
185
|
+
- Lógica de transição precisa ser robusta
|
|
186
|
+
- Webhooks Asaas controlam transições de pagamento
|
|
187
|
+
- Jobs agendados para expiração de trial
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## ADR-009: Caching Strategy
|
|
192
|
+
|
|
193
|
+
**Status**: Accepted
|
|
194
|
+
|
|
195
|
+
**Context**: Definir estratégia de cache.
|
|
196
|
+
|
|
197
|
+
**Decision**: In-memory cache com invalidation
|
|
198
|
+
|
|
199
|
+
**Rationale**:
|
|
200
|
+
- Tenant data raramente muda
|
|
201
|
+
- Plans são estáticos
|
|
202
|
+
- In-memory suficiente para Container Apps com poucas instâncias
|
|
203
|
+
|
|
204
|
+
**Implementation**:
|
|
205
|
+
- `IMemoryCache` para dados de leitura frequente
|
|
206
|
+
- Cache invalidation em updates
|
|
207
|
+
|
|
208
|
+
**Consequences**:
|
|
209
|
+
- Cache não compartilhado entre instâncias
|
|
210
|
+
- Inconsistência temporária possível (aceitável)
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## ADR-010: Error Handling Strategy
|
|
215
|
+
|
|
216
|
+
**Status**: Accepted
|
|
217
|
+
|
|
218
|
+
**Context**: Padronizar tratamento de erros.
|
|
219
|
+
|
|
220
|
+
**Decision**: Problem Details (RFC 7807) + Global Exception Handler
|
|
221
|
+
|
|
222
|
+
**Implementation**:
|
|
223
|
+
```csharp
|
|
224
|
+
app.UseExceptionHandler(options =>
|
|
225
|
+
{
|
|
226
|
+
options.Run(async context =>
|
|
227
|
+
{
|
|
228
|
+
var problemDetails = new ProblemDetails
|
|
229
|
+
{
|
|
230
|
+
Status = StatusCodes.Status500InternalServerError,
|
|
231
|
+
Title = "An error occurred",
|
|
232
|
+
Instance = context.Request.Path
|
|
233
|
+
};
|
|
234
|
+
await context.Response.WriteAsJsonAsync(problemDetails);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
**Consequences**:
|
|
240
|
+
- Respostas de erro consistentes
|
|
241
|
+
- Fácil integração com frontends
|
|
242
|
+
- Logging estruturado
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
*MORPH-SPEC by Polymorphism Tech*
|