@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,399 @@
|
|
|
1
|
+
# API .NET + Next.js - Especificação
|
|
2
|
+
|
|
3
|
+
## 1. Visão Geral
|
|
4
|
+
|
|
5
|
+
Arquitetura full-stack moderna com API .NET e frontend Next.js, seguindo boas práticas de separação de responsabilidades.
|
|
6
|
+
|
|
7
|
+
### 1.1 Objetivos
|
|
8
|
+
|
|
9
|
+
- Backend robusto com .NET Minimal APIs
|
|
10
|
+
- Frontend moderno com Next.js App Router
|
|
11
|
+
- Autenticação unificada via Clerk
|
|
12
|
+
- Type-safety end-to-end
|
|
13
|
+
- Deploy independente de cada camada
|
|
14
|
+
|
|
15
|
+
### 1.2 Use Cases
|
|
16
|
+
|
|
17
|
+
- Dashboards administrativos
|
|
18
|
+
- Aplicações CRUD complexas
|
|
19
|
+
- Sistemas que precisam de SEO (Next.js SSR)
|
|
20
|
+
- Aplicações com múltiplos frontends (web, mobile)
|
|
21
|
+
|
|
22
|
+
## 2. Requisitos Funcionais
|
|
23
|
+
|
|
24
|
+
### 2.1 Backend (.NET API)
|
|
25
|
+
|
|
26
|
+
| ID | Requisito |
|
|
27
|
+
|----|-----------|
|
|
28
|
+
| API-001 | Minimal APIs com OpenAPI/Swagger |
|
|
29
|
+
| API-002 | Autenticação JWT via Clerk |
|
|
30
|
+
| API-003 | Validação com FluentValidation |
|
|
31
|
+
| API-004 | Paginação, filtros e ordenação |
|
|
32
|
+
| API-005 | Rate limiting por usuário |
|
|
33
|
+
| API-006 | Health checks (liveness + readiness) |
|
|
34
|
+
| API-007 | Logging estruturado |
|
|
35
|
+
| API-008 | CORS configurável |
|
|
36
|
+
|
|
37
|
+
### 2.2 Frontend (Next.js)
|
|
38
|
+
|
|
39
|
+
| ID | Requisito |
|
|
40
|
+
|----|-----------|
|
|
41
|
+
| WEB-001 | App Router com layouts aninhados |
|
|
42
|
+
| WEB-002 | Server Components para dados estáticos |
|
|
43
|
+
| WEB-003 | Client Components para interatividade |
|
|
44
|
+
| WEB-004 | React Query para cache e mutations |
|
|
45
|
+
| WEB-005 | Forms com React Hook Form + Zod |
|
|
46
|
+
| WEB-006 | UI com Tailwind + shadcn/ui |
|
|
47
|
+
| WEB-007 | Dark mode support |
|
|
48
|
+
| WEB-008 | Loading states e error boundaries |
|
|
49
|
+
|
|
50
|
+
### 2.3 Autenticação
|
|
51
|
+
|
|
52
|
+
| ID | Requisito |
|
|
53
|
+
|----|-----------|
|
|
54
|
+
| AUTH-001 | SSO via Clerk |
|
|
55
|
+
| AUTH-002 | Proteção de rotas (middleware) |
|
|
56
|
+
| AUTH-003 | Token refresh automático |
|
|
57
|
+
| AUTH-004 | Role-based access control |
|
|
58
|
+
|
|
59
|
+
## 3. Requisitos Não-Funcionais
|
|
60
|
+
|
|
61
|
+
### 3.1 Performance
|
|
62
|
+
|
|
63
|
+
| ID | Requisito |
|
|
64
|
+
|----|-----------|
|
|
65
|
+
| PERF-001 | API response < 100ms (P95) |
|
|
66
|
+
| PERF-002 | LCP < 2.5s (Core Web Vitals) |
|
|
67
|
+
| PERF-003 | FID < 100ms |
|
|
68
|
+
| PERF-004 | CLS < 0.1 |
|
|
69
|
+
|
|
70
|
+
### 3.2 Segurança
|
|
71
|
+
|
|
72
|
+
| ID | Requisito |
|
|
73
|
+
|----|-----------|
|
|
74
|
+
| SEC-001 | HTTPS obrigatório |
|
|
75
|
+
| SEC-002 | CORS restrito a domínios conhecidos |
|
|
76
|
+
| SEC-003 | Input validation em todos endpoints |
|
|
77
|
+
| SEC-004 | SQL injection prevention (EF Core) |
|
|
78
|
+
| SEC-005 | XSS prevention (React default) |
|
|
79
|
+
|
|
80
|
+
## 4. Arquitetura da API
|
|
81
|
+
|
|
82
|
+
### 4.1 Estrutura de Camadas
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
Api/
|
|
86
|
+
├── Endpoints/ # Minimal API endpoints
|
|
87
|
+
├── Middleware/ # Custom middlewares
|
|
88
|
+
├── Filters/ # Exception filters
|
|
89
|
+
└── Program.cs # Entry point
|
|
90
|
+
|
|
91
|
+
Application/
|
|
92
|
+
├── Services/ # Business logic
|
|
93
|
+
├── Validators/ # FluentValidation
|
|
94
|
+
└── DTOs/ # Data transfer objects
|
|
95
|
+
|
|
96
|
+
Domain/
|
|
97
|
+
├── Entities/ # Domain models
|
|
98
|
+
├── Interfaces/ # Repository contracts
|
|
99
|
+
└── Enums/ # Domain enums
|
|
100
|
+
|
|
101
|
+
Infrastructure/
|
|
102
|
+
├── Data/ # DbContext
|
|
103
|
+
├── Repositories/ # EF Core implementations
|
|
104
|
+
└── Services/ # External service clients
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 4.2 Endpoint Pattern
|
|
108
|
+
|
|
109
|
+
```csharp
|
|
110
|
+
// Endpoints/ProductEndpoints.cs
|
|
111
|
+
public static class ProductEndpoints
|
|
112
|
+
{
|
|
113
|
+
public static void MapProductEndpoints(this IEndpointRouteBuilder app)
|
|
114
|
+
{
|
|
115
|
+
var group = app.MapGroup("/api/products")
|
|
116
|
+
.WithTags("Products")
|
|
117
|
+
.RequireAuthorization();
|
|
118
|
+
|
|
119
|
+
group.MapGet("/", GetAll);
|
|
120
|
+
group.MapGet("/{id:int}", GetById);
|
|
121
|
+
group.MapPost("/", Create);
|
|
122
|
+
group.MapPut("/{id:int}", Update);
|
|
123
|
+
group.MapDelete("/{id:int}", Delete);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private static async Task<IResult> GetAll(
|
|
127
|
+
[AsParameters] PaginationQuery query,
|
|
128
|
+
IProductService service,
|
|
129
|
+
CancellationToken ct)
|
|
130
|
+
{
|
|
131
|
+
var result = await service.GetAllAsync(query, ct);
|
|
132
|
+
return Results.Ok(result);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 4.3 Pagination
|
|
138
|
+
|
|
139
|
+
```csharp
|
|
140
|
+
public record PaginationQuery(
|
|
141
|
+
int Page = 1,
|
|
142
|
+
int PageSize = 20,
|
|
143
|
+
string? SortBy = null,
|
|
144
|
+
bool SortDesc = false,
|
|
145
|
+
string? Search = null
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
public record PagedResult<T>(
|
|
149
|
+
IReadOnlyList<T> Items,
|
|
150
|
+
int TotalItems,
|
|
151
|
+
int Page,
|
|
152
|
+
int PageSize,
|
|
153
|
+
int TotalPages
|
|
154
|
+
);
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## 5. Arquitetura do Frontend
|
|
158
|
+
|
|
159
|
+
### 5.1 Estrutura de Pastas
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
app/
|
|
163
|
+
├── (auth)/
|
|
164
|
+
│ ├── sign-in/[[...sign-in]]/page.tsx
|
|
165
|
+
│ └── sign-up/[[...sign-up]]/page.tsx
|
|
166
|
+
├── (dashboard)/
|
|
167
|
+
│ ├── layout.tsx # Dashboard layout
|
|
168
|
+
│ ├── dashboard/page.tsx
|
|
169
|
+
│ ├── products/
|
|
170
|
+
│ │ ├── page.tsx # List
|
|
171
|
+
│ │ ├── [id]/page.tsx # Detail
|
|
172
|
+
│ │ └── new/page.tsx # Create
|
|
173
|
+
│ └── orders/
|
|
174
|
+
├── api/ # API routes (BFF)
|
|
175
|
+
├── layout.tsx # Root layout
|
|
176
|
+
└── page.tsx # Landing
|
|
177
|
+
|
|
178
|
+
components/
|
|
179
|
+
├── ui/ # shadcn components
|
|
180
|
+
├── forms/ # Form components
|
|
181
|
+
├── tables/ # Table components
|
|
182
|
+
└── shared/ # Shared components
|
|
183
|
+
|
|
184
|
+
hooks/
|
|
185
|
+
├── use-products.ts
|
|
186
|
+
├── use-orders.ts
|
|
187
|
+
└── use-pagination.ts
|
|
188
|
+
|
|
189
|
+
lib/
|
|
190
|
+
├── api-client.ts # Fetch wrapper
|
|
191
|
+
├── query-client.ts # React Query config
|
|
192
|
+
└── utils.ts # Utility functions
|
|
193
|
+
|
|
194
|
+
types/
|
|
195
|
+
├── api.ts # API response types
|
|
196
|
+
└── entities.ts # Domain types
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 5.2 Data Fetching Pattern
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// hooks/use-products.ts
|
|
203
|
+
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
204
|
+
import { apiClient } from "@/lib/api-client";
|
|
205
|
+
import type { Product, CreateProductRequest } from "@/types/entities";
|
|
206
|
+
|
|
207
|
+
export function useProducts(params?: PaginationParams) {
|
|
208
|
+
return useQuery({
|
|
209
|
+
queryKey: ["products", params],
|
|
210
|
+
queryFn: () => apiClient<PagedResult<Product>>("/api/products", { params }),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function useProduct(id: number) {
|
|
215
|
+
return useQuery({
|
|
216
|
+
queryKey: ["products", id],
|
|
217
|
+
queryFn: () => apiClient<Product>(`/api/products/${id}`),
|
|
218
|
+
enabled: !!id,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export function useCreateProduct() {
|
|
223
|
+
const queryClient = useQueryClient();
|
|
224
|
+
|
|
225
|
+
return useMutation({
|
|
226
|
+
mutationFn: (data: CreateProductRequest) =>
|
|
227
|
+
apiClient<Product>("/api/products", {
|
|
228
|
+
method: "POST",
|
|
229
|
+
body: JSON.stringify(data),
|
|
230
|
+
}),
|
|
231
|
+
onSuccess: () => {
|
|
232
|
+
queryClient.invalidateQueries({ queryKey: ["products"] });
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 5.3 Form Pattern
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
// components/forms/product-form.tsx
|
|
242
|
+
"use client";
|
|
243
|
+
|
|
244
|
+
import { useForm } from "react-hook-form";
|
|
245
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
246
|
+
import { z } from "zod";
|
|
247
|
+
import { useCreateProduct } from "@/hooks/use-products";
|
|
248
|
+
|
|
249
|
+
const schema = z.object({
|
|
250
|
+
name: z.string().min(1, "Name is required"),
|
|
251
|
+
price: z.number().positive("Price must be positive"),
|
|
252
|
+
description: z.string().optional(),
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
type FormData = z.infer<typeof schema>;
|
|
256
|
+
|
|
257
|
+
export function ProductForm() {
|
|
258
|
+
const { mutate, isPending } = useCreateProduct();
|
|
259
|
+
const form = useForm<FormData>({
|
|
260
|
+
resolver: zodResolver(schema),
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
const onSubmit = (data: FormData) => {
|
|
264
|
+
mutate(data);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<form onSubmit={form.handleSubmit(onSubmit)}>
|
|
269
|
+
{/* Form fields */}
|
|
270
|
+
</form>
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## 6. Comunicação API
|
|
276
|
+
|
|
277
|
+
### 6.1 API Client
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
// lib/api-client.ts
|
|
281
|
+
import { auth } from "@clerk/nextjs/server";
|
|
282
|
+
|
|
283
|
+
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
|
284
|
+
|
|
285
|
+
interface FetchOptions extends RequestInit {
|
|
286
|
+
params?: Record<string, string | number | undefined>;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export async function apiClient<T>(
|
|
290
|
+
endpoint: string,
|
|
291
|
+
options: FetchOptions = {}
|
|
292
|
+
): Promise<T> {
|
|
293
|
+
const { params, ...init } = options;
|
|
294
|
+
|
|
295
|
+
// Build URL with query params
|
|
296
|
+
const url = new URL(`${API_URL}${endpoint}`);
|
|
297
|
+
if (params) {
|
|
298
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
299
|
+
if (value !== undefined) {
|
|
300
|
+
url.searchParams.append(key, String(value));
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Get auth token
|
|
306
|
+
const { getToken } = auth();
|
|
307
|
+
const token = await getToken();
|
|
308
|
+
|
|
309
|
+
const response = await fetch(url.toString(), {
|
|
310
|
+
...init,
|
|
311
|
+
headers: {
|
|
312
|
+
"Content-Type": "application/json",
|
|
313
|
+
...(token && { Authorization: `Bearer ${token}` }),
|
|
314
|
+
...init.headers,
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
if (!response.ok) {
|
|
319
|
+
const error = await response.json().catch(() => ({}));
|
|
320
|
+
throw new ApiError(response.status, error.title || "Request failed", error);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return response.json();
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
class ApiError extends Error {
|
|
327
|
+
constructor(
|
|
328
|
+
public status: number,
|
|
329
|
+
message: string,
|
|
330
|
+
public details?: unknown
|
|
331
|
+
) {
|
|
332
|
+
super(message);
|
|
333
|
+
this.name = "ApiError";
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## 7. Configurações
|
|
339
|
+
|
|
340
|
+
### 7.1 API (appsettings.json)
|
|
341
|
+
|
|
342
|
+
```json
|
|
343
|
+
{
|
|
344
|
+
"ConnectionStrings": {
|
|
345
|
+
"DefaultConnection": "Server=...;Database=...;"
|
|
346
|
+
},
|
|
347
|
+
"Clerk": {
|
|
348
|
+
"Authority": "https://your-clerk-domain.clerk.accounts.dev",
|
|
349
|
+
"SecretKey": "sk_..."
|
|
350
|
+
},
|
|
351
|
+
"Cors": {
|
|
352
|
+
"AllowedOrigins": ["http://localhost:3000", "https://your-domain.com"]
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### 7.2 Frontend (.env.local)
|
|
358
|
+
|
|
359
|
+
```env
|
|
360
|
+
NEXT_PUBLIC_API_URL=http://localhost:5000
|
|
361
|
+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_...
|
|
362
|
+
CLERK_SECRET_KEY=sk_...
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
## 8. Deploy
|
|
366
|
+
|
|
367
|
+
### 8.1 Docker
|
|
368
|
+
|
|
369
|
+
```dockerfile
|
|
370
|
+
# API Dockerfile
|
|
371
|
+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
|
|
372
|
+
WORKDIR /app
|
|
373
|
+
EXPOSE 8080
|
|
374
|
+
|
|
375
|
+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
|
376
|
+
WORKDIR /src
|
|
377
|
+
COPY ["src/api/Api/Api.csproj", "Api/"]
|
|
378
|
+
RUN dotnet restore "Api/Api.csproj"
|
|
379
|
+
COPY src/api/ .
|
|
380
|
+
RUN dotnet build "Api/Api.csproj" -c Release -o /app/build
|
|
381
|
+
|
|
382
|
+
FROM build AS publish
|
|
383
|
+
RUN dotnet publish "Api/Api.csproj" -c Release -o /app/publish
|
|
384
|
+
|
|
385
|
+
FROM base AS final
|
|
386
|
+
WORKDIR /app
|
|
387
|
+
COPY --from=publish /app/publish .
|
|
388
|
+
ENTRYPOINT ["dotnet", "Api.dll"]
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
### 8.2 Container Apps
|
|
392
|
+
|
|
393
|
+
Dois Container Apps separados:
|
|
394
|
+
- `app-api`: .NET API
|
|
395
|
+
- `app-web`: Next.js (com output: standalone)
|
|
396
|
+
|
|
397
|
+
---
|
|
398
|
+
|
|
399
|
+
*MORPH-SPEC by Polymorphism Tech*
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# API .NET + Next.js - Tasks
|
|
2
|
+
|
|
3
|
+
## Fase 1: Setup do Projeto
|
|
4
|
+
|
|
5
|
+
| ID | Task | Dependências | Estimativa |
|
|
6
|
+
|----|------|--------------|------------|
|
|
7
|
+
| T001 | Criar solution .NET | - | S |
|
|
8
|
+
| T002 | Criar projeto Next.js | - | S |
|
|
9
|
+
| T003 | Configurar Docker Compose | T001, T002 | M |
|
|
10
|
+
| T004 | Configurar packages (.NET e npm) | T001, T002 | S |
|
|
11
|
+
|
|
12
|
+
## Fase 2: Backend - Domain Layer
|
|
13
|
+
|
|
14
|
+
| ID | Task | Dependências | Estimativa |
|
|
15
|
+
|----|------|--------------|------------|
|
|
16
|
+
| T005 | Criar BaseEntity | T001 | S |
|
|
17
|
+
| T006 | Criar Product entity | T005 | S |
|
|
18
|
+
| T007 | Criar Order e OrderItem entities | T005 | M |
|
|
19
|
+
| T008 | Criar Customer entity | T005 | S |
|
|
20
|
+
| T009 | Definir interfaces de repository | T005 | S |
|
|
21
|
+
|
|
22
|
+
## Fase 3: Backend - Infrastructure Layer
|
|
23
|
+
|
|
24
|
+
| ID | Task | Dependências | Estimativa |
|
|
25
|
+
|----|------|--------------|------------|
|
|
26
|
+
| T010 | Criar AppDbContext | T006-T008 | M |
|
|
27
|
+
| T011 | Configurar EF Core mappings | T010 | M |
|
|
28
|
+
| T012 | Criar ProductRepository | T010 | M |
|
|
29
|
+
| T013 | Criar OrderRepository | T010 | M |
|
|
30
|
+
| T014 | Criar CustomerRepository | T010 | M |
|
|
31
|
+
| T015 | Criar migrations | T011 | S |
|
|
32
|
+
|
|
33
|
+
## Fase 4: Backend - Application Layer
|
|
34
|
+
|
|
35
|
+
| ID | Task | Dependências | Estimativa |
|
|
36
|
+
|----|------|--------------|------------|
|
|
37
|
+
| T016 | Criar DTOs | T006-T008 | M |
|
|
38
|
+
| T017 | Criar ProductService | T012 | M |
|
|
39
|
+
| T018 | Criar OrderService | T013 | M |
|
|
40
|
+
| T019 | Criar CustomerService | T014 | M |
|
|
41
|
+
| T020 | Criar validators (FluentValidation) | T016 | M |
|
|
42
|
+
| T021 | Criar DashboardService | T017-T019 | M |
|
|
43
|
+
|
|
44
|
+
## Fase 5: Backend - API Layer
|
|
45
|
+
|
|
46
|
+
| ID | Task | Dependências | Estimativa |
|
|
47
|
+
|----|------|--------------|------------|
|
|
48
|
+
| T022 | Configurar Program.cs base | T001 | M |
|
|
49
|
+
| T023 | Configurar autenticação JWT/Clerk | T022 | M |
|
|
50
|
+
| T024 | Criar ProductEndpoints | T017, T020 | M |
|
|
51
|
+
| T025 | Criar OrderEndpoints | T018, T020 | M |
|
|
52
|
+
| T026 | Criar CustomerEndpoints | T019, T020 | M |
|
|
53
|
+
| T027 | Criar DashboardEndpoints | T021 | S |
|
|
54
|
+
| T028 | Configurar Swagger/OpenAPI | T024-T027 | S |
|
|
55
|
+
| T029 | Configurar CORS | T022 | S |
|
|
56
|
+
| T030 | Configurar Health Checks | T022 | S |
|
|
57
|
+
|
|
58
|
+
## Fase 6: Frontend - Setup
|
|
59
|
+
|
|
60
|
+
| ID | Task | Dependências | Estimativa |
|
|
61
|
+
|----|------|--------------|------------|
|
|
62
|
+
| T031 | Configurar Tailwind CSS | T002 | S |
|
|
63
|
+
| T032 | Instalar shadcn/ui components | T031 | M |
|
|
64
|
+
| T033 | Configurar Clerk | T002 | M |
|
|
65
|
+
| T034 | Criar API client | T002 | M |
|
|
66
|
+
| T035 | Configurar React Query | T002 | S |
|
|
67
|
+
|
|
68
|
+
## Fase 7: Frontend - Layout
|
|
69
|
+
|
|
70
|
+
| ID | Task | Dependências | Estimativa |
|
|
71
|
+
|----|------|--------------|------------|
|
|
72
|
+
| T036 | Criar root layout | T031 | M |
|
|
73
|
+
| T037 | Criar dashboard layout | T036 | M |
|
|
74
|
+
| T038 | Criar sidebar navigation | T037 | M |
|
|
75
|
+
| T039 | Criar header com user menu | T033, T037 | M |
|
|
76
|
+
|
|
77
|
+
## Fase 8: Frontend - Components
|
|
78
|
+
|
|
79
|
+
| ID | Task | Dependências | Estimativa |
|
|
80
|
+
|----|------|--------------|------------|
|
|
81
|
+
| T040 | Criar DataTable component | T032 | L |
|
|
82
|
+
| T041 | Criar Form components | T032 | M |
|
|
83
|
+
| T042 | Criar Card components | T032 | S |
|
|
84
|
+
| T043 | Criar Modal/Dialog components | T032 | M |
|
|
85
|
+
| T044 | Criar Loading/Error states | T032 | S |
|
|
86
|
+
|
|
87
|
+
## Fase 9: Frontend - Hooks
|
|
88
|
+
|
|
89
|
+
| ID | Task | Dependências | Estimativa |
|
|
90
|
+
|----|------|--------------|------------|
|
|
91
|
+
| T045 | Criar useProducts hook | T034, T035 | M |
|
|
92
|
+
| T046 | Criar useOrders hook | T034, T035 | M |
|
|
93
|
+
| T047 | Criar useCustomers hook | T034, T035 | M |
|
|
94
|
+
| T048 | Criar useDashboard hook | T034, T035 | S |
|
|
95
|
+
| T049 | Criar usePagination hook | T035 | S |
|
|
96
|
+
|
|
97
|
+
## Fase 10: Frontend - Pages
|
|
98
|
+
|
|
99
|
+
| ID | Task | Dependências | Estimativa |
|
|
100
|
+
|----|------|--------------|------------|
|
|
101
|
+
| T050 | Criar landing page | T036 | M |
|
|
102
|
+
| T051 | Criar sign-in page | T033 | S |
|
|
103
|
+
| T052 | Criar sign-up page | T033 | S |
|
|
104
|
+
| T053 | Criar dashboard page | T048, T042 | M |
|
|
105
|
+
| T054 | Criar products list page | T045, T040 | M |
|
|
106
|
+
| T055 | Criar product detail page | T045, T042 | M |
|
|
107
|
+
| T056 | Criar product form page | T045, T041 | M |
|
|
108
|
+
| T057 | Criar orders list page | T046, T040 | M |
|
|
109
|
+
| T058 | Criar order detail page | T046, T042 | M |
|
|
110
|
+
|
|
111
|
+
## Fase 11: Infrastructure (IaC)
|
|
112
|
+
|
|
113
|
+
| ID | Task | Dependências | Estimativa |
|
|
114
|
+
|----|------|--------------|------------|
|
|
115
|
+
| T059 | Criar main.bicep | - | M |
|
|
116
|
+
| T060 | Configurar Container App (API) | T059 | M |
|
|
117
|
+
| T061 | Configurar Container App (Web) | T059 | M |
|
|
118
|
+
| T062 | Configurar SQL Database | T059 | M |
|
|
119
|
+
| T063 | Configurar App Insights | T059 | S |
|
|
120
|
+
|
|
121
|
+
## Fase 12: Testes e Deploy
|
|
122
|
+
|
|
123
|
+
| ID | Task | Dependências | Estimativa |
|
|
124
|
+
|----|------|--------------|------------|
|
|
125
|
+
| T064 | Criar testes unitários backend | T017-T021 | L |
|
|
126
|
+
| T065 | Criar testes de integração API | T024-T027 | L |
|
|
127
|
+
| T066 | Criar testes E2E frontend | T050-T058 | L |
|
|
128
|
+
| T067 | Configurar CI/CD pipeline | T059-T063 | M |
|
|
129
|
+
|
|
130
|
+
## Checkpoints
|
|
131
|
+
|
|
132
|
+
| Checkpoint | Após Tasks | Validação |
|
|
133
|
+
|------------|------------|-----------|
|
|
134
|
+
| CP1 | T004 | Projetos compilam |
|
|
135
|
+
| CP2 | T015 | Database pronto |
|
|
136
|
+
| CP3 | T021 | Services funcionando |
|
|
137
|
+
| CP4 | T030 | API completa com Swagger |
|
|
138
|
+
| CP5 | T039 | Layout pronto |
|
|
139
|
+
| CP6 | T049 | Hooks funcionando |
|
|
140
|
+
| CP7 | T058 | Frontend completo |
|
|
141
|
+
| CP8 | T063 | IaC pronto |
|
|
142
|
+
| CP9 | T067 | Deploy funcional |
|
|
143
|
+
|
|
144
|
+
## Legenda
|
|
145
|
+
|
|
146
|
+
- **S** = Small (< 1h)
|
|
147
|
+
- **M** = Medium (1-3h)
|
|
148
|
+
- **L** = Large (3-8h)
|
|
149
|
+
|
|
150
|
+
## Ordem de Execução Paralela
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
Backend Path:
|
|
154
|
+
T001 → T005 → T006-T009 → T010-T015 → T016-T021 → T022-T030
|
|
155
|
+
|
|
156
|
+
Frontend Path (pode iniciar após T028):
|
|
157
|
+
T002 → T031-T035 → T036-T039 → T040-T044 → T045-T049 → T050-T058
|
|
158
|
+
|
|
159
|
+
IaC Path (pode iniciar independente):
|
|
160
|
+
T059-T063
|
|
161
|
+
|
|
162
|
+
Testes (após ambos paths):
|
|
163
|
+
T064-T066 → T067
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
*MORPH-SPEC by Polymorphism Tech*
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Micro-SaaS Example
|
|
2
|
+
|
|
3
|
+
Exemplo completo de um Micro-SaaS com Blazor Server + Asaas para billing.
|
|
4
|
+
|
|
5
|
+
## Stack
|
|
6
|
+
|
|
7
|
+
| Camada | Tecnologia |
|
|
8
|
+
|--------|------------|
|
|
9
|
+
| **Frontend** | Blazor Server |
|
|
10
|
+
| **Backend** | .NET 8 Minimal APIs |
|
|
11
|
+
| **Database** | SQL Server / PostgreSQL |
|
|
12
|
+
| **Auth** | Clerk ou Azure Identity |
|
|
13
|
+
| **Billing** | Asaas (PIX, Boleto, Cartão) |
|
|
14
|
+
| **Infra** | Azure Container Apps |
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Multi-tenancy com isolamento por tenant
|
|
19
|
+
- Subscription management com Asaas
|
|
20
|
+
- Dashboard administrativo
|
|
21
|
+
- User management por tenant
|
|
22
|
+
- Webhooks para eventos de pagamento
|
|
23
|
+
|
|
24
|
+
## Estrutura
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
src/
|
|
28
|
+
├── MicroSaaS.Domain/
|
|
29
|
+
│ ├── Entities/
|
|
30
|
+
│ │ ├── Tenant.cs
|
|
31
|
+
│ │ ├── TenantUser.cs
|
|
32
|
+
│ │ ├── Subscription.cs
|
|
33
|
+
│ │ └── Plan.cs
|
|
34
|
+
│ └── Interfaces/
|
|
35
|
+
├── MicroSaaS.Infrastructure/
|
|
36
|
+
│ ├── Data/
|
|
37
|
+
│ ├── Repositories/
|
|
38
|
+
│ └── Services/
|
|
39
|
+
│ └── AsaasService.cs
|
|
40
|
+
├── MicroSaaS.Application/
|
|
41
|
+
│ ├── Commands/
|
|
42
|
+
│ ├── Queries/
|
|
43
|
+
│ └── Services/
|
|
44
|
+
└── MicroSaaS.Web/
|
|
45
|
+
├── Components/
|
|
46
|
+
│ ├── Layout/
|
|
47
|
+
│ ├── Pages/
|
|
48
|
+
│ └── Shared/
|
|
49
|
+
└── Program.cs
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# 1. Clone e configure
|
|
56
|
+
dotnet new blazor -n MicroSaaS.Web -o src/MicroSaaS.Web
|
|
57
|
+
cd src/MicroSaaS.Web
|
|
58
|
+
|
|
59
|
+
# 2. Adicione packages
|
|
60
|
+
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
|
|
61
|
+
dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer
|
|
62
|
+
|
|
63
|
+
# 3. Configure appsettings.json
|
|
64
|
+
# Veja exemplo em appsettings.example.json
|
|
65
|
+
|
|
66
|
+
# 4. Run migrations
|
|
67
|
+
dotnet ef migrations add Initial
|
|
68
|
+
dotnet ef database update
|
|
69
|
+
|
|
70
|
+
# 5. Start
|
|
71
|
+
dotnet run
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Fluxo de Onboarding
|
|
75
|
+
|
|
76
|
+
```mermaid
|
|
77
|
+
sequenceDiagram
|
|
78
|
+
participant User
|
|
79
|
+
participant App
|
|
80
|
+
participant Clerk
|
|
81
|
+
participant Asaas
|
|
82
|
+
|
|
83
|
+
User->>App: Acessa /signup
|
|
84
|
+
App->>Clerk: Cria usuário
|
|
85
|
+
Clerk-->>App: User ID
|
|
86
|
+
App->>App: Cria Tenant
|
|
87
|
+
App->>Asaas: Cria Customer
|
|
88
|
+
Asaas-->>App: Customer ID
|
|
89
|
+
App->>App: Associa User ao Tenant
|
|
90
|
+
App-->>User: Redirect /dashboard
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Fluxo de Subscription
|
|
94
|
+
|
|
95
|
+
```mermaid
|
|
96
|
+
sequenceDiagram
|
|
97
|
+
participant User
|
|
98
|
+
participant App
|
|
99
|
+
participant Asaas
|
|
100
|
+
|
|
101
|
+
User->>App: Seleciona plano
|
|
102
|
+
App->>Asaas: Cria Subscription
|
|
103
|
+
Asaas-->>App: Subscription ID
|
|
104
|
+
Asaas->>App: Webhook PAYMENT_CREATED
|
|
105
|
+
App->>App: Registra pagamento pendente
|
|
106
|
+
User->>Asaas: Realiza pagamento
|
|
107
|
+
Asaas->>App: Webhook PAYMENT_RECEIVED
|
|
108
|
+
App->>App: Ativa subscription
|
|
109
|
+
App-->>User: Acesso liberado
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Custos Estimados
|
|
113
|
+
|
|
114
|
+
| Recurso | Tier | Custo/mês |
|
|
115
|
+
|---------|------|-----------|
|
|
116
|
+
| Container Apps | Consumption | ~$0 (scale-to-zero) |
|
|
117
|
+
| SQL Database | Free 32GB | $0 |
|
|
118
|
+
| Storage | LRS | ~$0.50 |
|
|
119
|
+
| Asaas | Por transação | 2.99% + R$0.49 |
|
|
120
|
+
|
|
121
|
+
**Total estimado**: < $5/mês para baixo volume
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
*MORPH-SPEC by Polymorphism Tech*
|