@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,236 @@
|
|
|
1
|
+
# Micro-SaaS - Especificação
|
|
2
|
+
|
|
3
|
+
## 1. Visão Geral
|
|
4
|
+
|
|
5
|
+
Sistema Micro-SaaS multi-tenant com gestão de assinaturas e billing integrado via Asaas.
|
|
6
|
+
|
|
7
|
+
### 1.1 Objetivos
|
|
8
|
+
|
|
9
|
+
- Permitir criação de tenants isolados
|
|
10
|
+
- Gerenciar assinaturas e pagamentos
|
|
11
|
+
- Fornecer dashboard administrativo por tenant
|
|
12
|
+
- Escalar de forma econômica (scale-to-zero)
|
|
13
|
+
|
|
14
|
+
### 1.2 Personas
|
|
15
|
+
|
|
16
|
+
| Persona | Descrição |
|
|
17
|
+
|---------|-----------|
|
|
18
|
+
| **Tenant Owner** | Cria e administra o tenant |
|
|
19
|
+
| **Tenant Admin** | Gerencia usuários e configurações |
|
|
20
|
+
| **Tenant Member** | Usuário regular do sistema |
|
|
21
|
+
| **Platform Admin** | Administrador da plataforma (super admin) |
|
|
22
|
+
|
|
23
|
+
## 2. Requisitos Funcionais
|
|
24
|
+
|
|
25
|
+
### 2.1 Autenticação & Autorização
|
|
26
|
+
|
|
27
|
+
| ID | Requisito |
|
|
28
|
+
|----|-----------|
|
|
29
|
+
| AUTH-001 | Login via Clerk (email, Google, Microsoft) |
|
|
30
|
+
| AUTH-002 | Criação automática de tenant no primeiro login |
|
|
31
|
+
| AUTH-003 | Convite de usuários para tenant existente |
|
|
32
|
+
| AUTH-004 | Roles: Owner, Admin, Member, Viewer |
|
|
33
|
+
| AUTH-005 | Permissões granulares por role |
|
|
34
|
+
|
|
35
|
+
### 2.2 Multi-Tenancy
|
|
36
|
+
|
|
37
|
+
| ID | Requisito |
|
|
38
|
+
|----|-----------|
|
|
39
|
+
| MT-001 | Isolamento completo de dados por tenant |
|
|
40
|
+
| MT-002 | Subdomínio customizado (acme.app.com) |
|
|
41
|
+
| MT-003 | Domínio customizado opcional |
|
|
42
|
+
| MT-004 | Configurações independentes por tenant |
|
|
43
|
+
| MT-005 | Branding básico (logo, cores) |
|
|
44
|
+
|
|
45
|
+
### 2.3 Subscription & Billing
|
|
46
|
+
|
|
47
|
+
| ID | Requisito |
|
|
48
|
+
|----|-----------|
|
|
49
|
+
| SUB-001 | Planos: Free, Starter, Pro, Enterprise |
|
|
50
|
+
| SUB-002 | Ciclos: Mensal e Anual |
|
|
51
|
+
| SUB-003 | Métodos: PIX, Boleto, Cartão de Crédito |
|
|
52
|
+
| SUB-004 | Trial period de 14 dias |
|
|
53
|
+
| SUB-005 | Upgrade/Downgrade de plano |
|
|
54
|
+
| SUB-006 | Cancelamento com período de carência |
|
|
55
|
+
| SUB-007 | Webhooks Asaas para status de pagamento |
|
|
56
|
+
|
|
57
|
+
### 2.4 Dashboard
|
|
58
|
+
|
|
59
|
+
| ID | Requisito |
|
|
60
|
+
|----|-----------|
|
|
61
|
+
| DASH-001 | Overview com métricas principais |
|
|
62
|
+
| DASH-002 | Gestão de usuários do tenant |
|
|
63
|
+
| DASH-003 | Histórico de pagamentos |
|
|
64
|
+
| DASH-004 | Configurações do tenant |
|
|
65
|
+
| DASH-005 | Upgrade de plano |
|
|
66
|
+
|
|
67
|
+
## 3. Requisitos Não-Funcionais
|
|
68
|
+
|
|
69
|
+
### 3.1 Performance
|
|
70
|
+
|
|
71
|
+
| ID | Requisito |
|
|
72
|
+
|----|-----------|
|
|
73
|
+
| PERF-001 | Tempo de resposta < 200ms (P95) |
|
|
74
|
+
| PERF-002 | Scale-to-zero quando inativo |
|
|
75
|
+
| PERF-003 | Auto-scaling até 10 instâncias |
|
|
76
|
+
|
|
77
|
+
### 3.2 Segurança
|
|
78
|
+
|
|
79
|
+
| ID | Requisito |
|
|
80
|
+
|----|-----------|
|
|
81
|
+
| SEC-001 | HTTPS obrigatório |
|
|
82
|
+
| SEC-002 | Validação de webhook signature |
|
|
83
|
+
| SEC-003 | Rate limiting por tenant |
|
|
84
|
+
| SEC-004 | Audit log de ações críticas |
|
|
85
|
+
|
|
86
|
+
### 3.3 Disponibilidade
|
|
87
|
+
|
|
88
|
+
| ID | Requisito |
|
|
89
|
+
|----|-----------|
|
|
90
|
+
| AVAIL-001 | SLA 99.5% |
|
|
91
|
+
| AVAIL-002 | Health checks ativos |
|
|
92
|
+
| AVAIL-003 | Retry automático em falhas |
|
|
93
|
+
|
|
94
|
+
## 4. Planos e Limites
|
|
95
|
+
|
|
96
|
+
| Feature | Free | Starter | Pro | Enterprise |
|
|
97
|
+
|---------|------|---------|-----|------------|
|
|
98
|
+
| Usuários | 2 | 5 | 20 | Ilimitado |
|
|
99
|
+
| Storage | 100MB | 1GB | 10GB | 100GB |
|
|
100
|
+
| API Requests/mês | 1K | 10K | 100K | Ilimitado |
|
|
101
|
+
| Suporte | Community | Email | Priority | Dedicated |
|
|
102
|
+
| Preço/mês | R$0 | R$49 | R$149 | R$499 |
|
|
103
|
+
|
|
104
|
+
## 5. Integrações
|
|
105
|
+
|
|
106
|
+
### 5.1 Asaas
|
|
107
|
+
|
|
108
|
+
- Customer management
|
|
109
|
+
- Subscription lifecycle
|
|
110
|
+
- Payment processing
|
|
111
|
+
- Webhook handling
|
|
112
|
+
|
|
113
|
+
### 5.2 Clerk
|
|
114
|
+
|
|
115
|
+
- User authentication
|
|
116
|
+
- Session management
|
|
117
|
+
- Organization (tenant) mapping
|
|
118
|
+
|
|
119
|
+
## 6. Arquitetura
|
|
120
|
+
|
|
121
|
+
### 6.1 Componentes
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
125
|
+
│ Blazor Server │
|
|
126
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
|
|
127
|
+
│ │ Pages │ │ Components │ │ Services │ │
|
|
128
|
+
│ │ /dashboard │ │ NavMenu │ │ TenantContext │ │
|
|
129
|
+
│ │ /settings │ │ DataGrid │ │ SubscriptionService │ │
|
|
130
|
+
│ │ /billing │ │ Charts │ │ UserService │ │
|
|
131
|
+
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
|
|
132
|
+
└─────────────────────────────────────────────────────────────┘
|
|
133
|
+
│
|
|
134
|
+
▼
|
|
135
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
136
|
+
│ Application Layer │
|
|
137
|
+
│ ┌─────────────────────────────────────────────────────┐ │
|
|
138
|
+
│ │ Commands: CreateTenant, InviteUser, ChangePlan │ │
|
|
139
|
+
│ │ Queries: GetDashboard, GetUsers, GetPayments │ │
|
|
140
|
+
│ └─────────────────────────────────────────────────────┘ │
|
|
141
|
+
└─────────────────────────────────────────────────────────────┘
|
|
142
|
+
│
|
|
143
|
+
▼
|
|
144
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
145
|
+
│ Infrastructure │
|
|
146
|
+
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
|
|
147
|
+
│ │ EF Core │ │ Asaas │ │ Clerk │ │
|
|
148
|
+
│ │ Repository │ │ Client │ │ Integration │ │
|
|
149
|
+
│ └──────────────┘ └──────────────┘ └──────────────────┘ │
|
|
150
|
+
└─────────────────────────────────────────────────────────────┘
|
|
151
|
+
│
|
|
152
|
+
▼
|
|
153
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
154
|
+
│ SQL Database │ Azure Storage │ Key Vault (secrets) │
|
|
155
|
+
└─────────────────────────────────────────────────────────────┘
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 6.2 Tenant Resolution
|
|
159
|
+
|
|
160
|
+
1. Subdomínio: `{tenant}.app.com`
|
|
161
|
+
2. Header: `X-Tenant-ID`
|
|
162
|
+
3. Route: `/tenant/{slug}/...`
|
|
163
|
+
4. Claim: JWT tenant_id
|
|
164
|
+
|
|
165
|
+
## 7. Modelo de Dados
|
|
166
|
+
|
|
167
|
+
### 7.1 Entidades Principais
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
Tenant
|
|
171
|
+
├── Id (int)
|
|
172
|
+
├── Name (string)
|
|
173
|
+
├── Slug (string) [unique]
|
|
174
|
+
├── Status (Active, Suspended, Deleted)
|
|
175
|
+
├── AsaasCustomerId (string)
|
|
176
|
+
├── CurrentSubscription → Subscription
|
|
177
|
+
└── Users → TenantUser[]
|
|
178
|
+
|
|
179
|
+
TenantUser
|
|
180
|
+
├── Id (int)
|
|
181
|
+
├── TenantId → Tenant
|
|
182
|
+
├── ExternalUserId (string) [Clerk ID]
|
|
183
|
+
├── Email (string)
|
|
184
|
+
├── Role (Owner, Admin, Member, Viewer)
|
|
185
|
+
└── Status (Pending, Active, Inactive)
|
|
186
|
+
|
|
187
|
+
Plan
|
|
188
|
+
├── Id (int)
|
|
189
|
+
├── Name (string)
|
|
190
|
+
├── PriceMonthly (decimal)
|
|
191
|
+
├── PriceYearly (decimal)
|
|
192
|
+
├── Features (JSON)
|
|
193
|
+
└── Limits (JSON)
|
|
194
|
+
|
|
195
|
+
Subscription
|
|
196
|
+
├── Id (int)
|
|
197
|
+
├── TenantId → Tenant
|
|
198
|
+
├── PlanId → Plan
|
|
199
|
+
├── AsaasSubscriptionId (string)
|
|
200
|
+
├── Status (Trial, Active, PastDue, Canceled)
|
|
201
|
+
├── BillingCycle (Monthly, Yearly)
|
|
202
|
+
├── CurrentPeriodStart (DateTime)
|
|
203
|
+
└── CurrentPeriodEnd (DateTime)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 8. APIs
|
|
207
|
+
|
|
208
|
+
### 8.1 Tenant Management
|
|
209
|
+
|
|
210
|
+
| Endpoint | Method | Descrição |
|
|
211
|
+
|----------|--------|-----------|
|
|
212
|
+
| `/api/tenants` | POST | Criar tenant |
|
|
213
|
+
| `/api/tenants/{id}` | GET | Obter tenant |
|
|
214
|
+
| `/api/tenants/{id}` | PUT | Atualizar tenant |
|
|
215
|
+
| `/api/tenants/{id}/users` | GET | Listar usuários |
|
|
216
|
+
| `/api/tenants/{id}/users` | POST | Convidar usuário |
|
|
217
|
+
|
|
218
|
+
### 8.2 Subscription
|
|
219
|
+
|
|
220
|
+
| Endpoint | Method | Descrição |
|
|
221
|
+
|----------|--------|-----------|
|
|
222
|
+
| `/api/subscriptions` | POST | Criar subscription |
|
|
223
|
+
| `/api/subscriptions/{id}` | GET | Obter subscription |
|
|
224
|
+
| `/api/subscriptions/{id}/upgrade` | POST | Upgrade de plano |
|
|
225
|
+
| `/api/subscriptions/{id}/cancel` | POST | Cancelar |
|
|
226
|
+
|
|
227
|
+
### 8.3 Webhooks
|
|
228
|
+
|
|
229
|
+
| Endpoint | Method | Descrição |
|
|
230
|
+
|----------|--------|-----------|
|
|
231
|
+
| `/webhooks/asaas` | POST | Eventos Asaas |
|
|
232
|
+
| `/webhooks/clerk` | POST | Eventos Clerk |
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
*MORPH-SPEC by Polymorphism Tech*
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Micro-SaaS - Tasks
|
|
2
|
+
|
|
3
|
+
## Fase 1: Setup do Projeto
|
|
4
|
+
|
|
5
|
+
| ID | Task | Dependências | Estimativa |
|
|
6
|
+
|----|------|--------------|------------|
|
|
7
|
+
| T001 | Criar solution e projetos | - | S |
|
|
8
|
+
| T002 | Configurar packages NuGet | T001 | S |
|
|
9
|
+
| T003 | Criar estrutura de pastas | T001 | S |
|
|
10
|
+
| T004 | Configurar appsettings.json | T001 | S |
|
|
11
|
+
|
|
12
|
+
## Fase 2: Domain Layer
|
|
13
|
+
|
|
14
|
+
| ID | Task | Dependências | Estimativa |
|
|
15
|
+
|----|------|--------------|------------|
|
|
16
|
+
| T005 | Criar BaseEntity | T001 | S |
|
|
17
|
+
| T006 | Criar Tenant entity | T005 | M |
|
|
18
|
+
| T007 | Criar TenantUser entity | T005 | M |
|
|
19
|
+
| T008 | Criar Plan entity | T005 | S |
|
|
20
|
+
| T009 | Criar Subscription entity | T005 | M |
|
|
21
|
+
| T010 | Criar SubscriptionPayment entity | T005 | M |
|
|
22
|
+
| T011 | Definir enums | T005 | S |
|
|
23
|
+
|
|
24
|
+
## Fase 3: Infrastructure Layer
|
|
25
|
+
|
|
26
|
+
| ID | Task | Dependências | Estimativa |
|
|
27
|
+
|----|------|--------------|------------|
|
|
28
|
+
| T012 | Criar AppDbContext | T006-T011 | M |
|
|
29
|
+
| T013 | Configurar EF Core mappings | T012 | M |
|
|
30
|
+
| T014 | Criar TenantRepository | T012 | M |
|
|
31
|
+
| T015 | Criar TenantUserRepository | T012 | M |
|
|
32
|
+
| T016 | Criar SubscriptionRepository | T012 | M |
|
|
33
|
+
| T017 | Criar PlanRepository | T012 | S |
|
|
34
|
+
| T018 | Criar PaymentRepository | T012 | M |
|
|
35
|
+
| T019 | Implementar AsaasClient | T002 | L |
|
|
36
|
+
| T020 | Implementar AsaasWebhookHandler | T019 | M |
|
|
37
|
+
|
|
38
|
+
## Fase 4: Application Layer
|
|
39
|
+
|
|
40
|
+
| ID | Task | Dependências | Estimativa |
|
|
41
|
+
|----|------|--------------|------------|
|
|
42
|
+
| T021 | Criar TenantService | T014, T015 | M |
|
|
43
|
+
| T022 | Criar TenantUserService | T015 | M |
|
|
44
|
+
| T023 | Criar SubscriptionService | T016, T019 | L |
|
|
45
|
+
| T024 | Criar PlanService | T017 | S |
|
|
46
|
+
| T025 | Criar DashboardService | T014-T018 | M |
|
|
47
|
+
| T026 | Criar WebhookService | T020, T016, T018 | M |
|
|
48
|
+
|
|
49
|
+
## Fase 5: Web Layer - Auth
|
|
50
|
+
|
|
51
|
+
| ID | Task | Dependências | Estimativa |
|
|
52
|
+
|----|------|--------------|------------|
|
|
53
|
+
| T027 | Configurar Clerk authentication | T002 | M |
|
|
54
|
+
| T028 | Implementar TenantContext | T014 | M |
|
|
55
|
+
| T029 | Criar middleware de tenant resolution | T028 | M |
|
|
56
|
+
| T030 | Configurar policies de autorização | T027 | S |
|
|
57
|
+
|
|
58
|
+
## Fase 6: Web Layer - Components
|
|
59
|
+
|
|
60
|
+
| ID | Task | Dependências | Estimativa |
|
|
61
|
+
|----|------|--------------|------------|
|
|
62
|
+
| T031 | Criar MainLayout | T027 | M |
|
|
63
|
+
| T032 | Criar NavMenu | T031 | S |
|
|
64
|
+
| T033 | Criar componentes shared (DataGrid, Card, etc) | T031 | M |
|
|
65
|
+
|
|
66
|
+
## Fase 7: Web Layer - Pages
|
|
67
|
+
|
|
68
|
+
| ID | Task | Dependências | Estimativa |
|
|
69
|
+
|----|------|--------------|------------|
|
|
70
|
+
| T034 | Criar página Dashboard | T025, T031 | M |
|
|
71
|
+
| T035 | Criar página Users | T022, T033 | M |
|
|
72
|
+
| T036 | Criar página Settings | T021, T033 | M |
|
|
73
|
+
| T037 | Criar página Billing | T023, T033 | L |
|
|
74
|
+
| T038 | Criar página Plans | T024, T033 | M |
|
|
75
|
+
|
|
76
|
+
## Fase 8: Web Layer - APIs
|
|
77
|
+
|
|
78
|
+
| ID | Task | Dependências | Estimativa |
|
|
79
|
+
|----|------|--------------|------------|
|
|
80
|
+
| T039 | Criar endpoints Tenant | T021 | M |
|
|
81
|
+
| T040 | Criar endpoints Users | T022 | M |
|
|
82
|
+
| T041 | Criar endpoints Subscription | T023 | M |
|
|
83
|
+
| T042 | Criar endpoint Webhook | T026 | M |
|
|
84
|
+
|
|
85
|
+
## Fase 9: Infrastructure (IaC)
|
|
86
|
+
|
|
87
|
+
| ID | Task | Dependências | Estimativa |
|
|
88
|
+
|----|------|--------------|------------|
|
|
89
|
+
| T043 | Criar main.bicep | - | M |
|
|
90
|
+
| T044 | Configurar Container App | T043 | M |
|
|
91
|
+
| T045 | Configurar SQL Database | T043 | M |
|
|
92
|
+
| T046 | Configurar Key Vault | T043 | S |
|
|
93
|
+
| T047 | Configurar App Insights | T043 | S |
|
|
94
|
+
|
|
95
|
+
## Fase 10: Testes e Documentação
|
|
96
|
+
|
|
97
|
+
| ID | Task | Dependências | Estimativa |
|
|
98
|
+
|----|------|--------------|------------|
|
|
99
|
+
| T048 | Criar testes unitários Domain | T006-T011 | M |
|
|
100
|
+
| T049 | Criar testes integração Services | T021-T026 | L |
|
|
101
|
+
| T050 | Criar testes E2E | T034-T042 | L |
|
|
102
|
+
| T051 | Documentar APIs (OpenAPI) | T039-T042 | M |
|
|
103
|
+
|
|
104
|
+
## Checkpoints
|
|
105
|
+
|
|
106
|
+
| Checkpoint | Após Tasks | Validação |
|
|
107
|
+
|------------|------------|-----------|
|
|
108
|
+
| CP1 | T004 | Projeto compila |
|
|
109
|
+
| CP2 | T011 | Domain layer completo |
|
|
110
|
+
| CP3 | T020 | Infrastructure layer completo |
|
|
111
|
+
| CP4 | T026 | Application layer completo |
|
|
112
|
+
| CP5 | T033 | Layout e componentes prontos |
|
|
113
|
+
| CP6 | T038 | Todas as páginas funcionando |
|
|
114
|
+
| CP7 | T042 | APIs funcionando |
|
|
115
|
+
| CP8 | T047 | IaC pronto para deploy |
|
|
116
|
+
| CP9 | T051 | Projeto completo |
|
|
117
|
+
|
|
118
|
+
## Legenda
|
|
119
|
+
|
|
120
|
+
- **S** = Small (< 1h)
|
|
121
|
+
- **M** = Medium (1-3h)
|
|
122
|
+
- **L** = Large (3-8h)
|
|
123
|
+
|
|
124
|
+
## Ordem de Execução Recomendada
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
T001 → T002 → T003 → T004 (CP1)
|
|
128
|
+
↓
|
|
129
|
+
T005 → T006-T011 (CP2)
|
|
130
|
+
↓
|
|
131
|
+
T012 → T013 → T014-T020 (CP3)
|
|
132
|
+
↓
|
|
133
|
+
T021-T026 (CP4)
|
|
134
|
+
↓
|
|
135
|
+
T027 → T028 → T029 → T030
|
|
136
|
+
↓
|
|
137
|
+
T031 → T032 → T033 (CP5)
|
|
138
|
+
↓
|
|
139
|
+
T034-T038 (CP6)
|
|
140
|
+
↓
|
|
141
|
+
T039-T042 (CP7)
|
|
142
|
+
↓
|
|
143
|
+
T043-T047 (CP8)
|
|
144
|
+
↓
|
|
145
|
+
T048-T051 (CP9)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
*MORPH-SPEC by Polymorphism Tech*
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
# Multi-Agent Example
|
|
2
|
+
|
|
3
|
+
Exemplo de sistema multi-agente usando Microsoft Agent Framework com Semantic Kernel.
|
|
4
|
+
|
|
5
|
+
## Stack
|
|
6
|
+
|
|
7
|
+
| Camada | Tecnologia |
|
|
8
|
+
|--------|------------|
|
|
9
|
+
| **Framework** | Microsoft Agent Framework |
|
|
10
|
+
| **AI Kernel** | Semantic Kernel |
|
|
11
|
+
| **LLM** | Azure OpenAI / OpenAI |
|
|
12
|
+
| **Orchestration** | Agent Orchestrator |
|
|
13
|
+
| **Storage** | Azure Cosmos DB / SQL |
|
|
14
|
+
| **Infra** | Azure Container Apps |
|
|
15
|
+
|
|
16
|
+
## Visão Geral
|
|
17
|
+
|
|
18
|
+
Sistema de agentes cooperativos que trabalham juntos para resolver tarefas complexas.
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
22
|
+
│ User Request │
|
|
23
|
+
└─────────────────────────────────────────────────────────────┘
|
|
24
|
+
│
|
|
25
|
+
▼
|
|
26
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
27
|
+
│ Orchestrator Agent │
|
|
28
|
+
│ - Analisa requisição │
|
|
29
|
+
│ - Decompõe em subtarefas │
|
|
30
|
+
│ - Delega para agentes especialistas │
|
|
31
|
+
│ - Consolida resultados │
|
|
32
|
+
└─────────────────────────────────────────────────────────────┘
|
|
33
|
+
│
|
|
34
|
+
┌───────────────┼───────────────┐
|
|
35
|
+
▼ ▼ ▼
|
|
36
|
+
┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐
|
|
37
|
+
│ Research Agent │ │ Analysis Agent │ │ Writing Agent │
|
|
38
|
+
│ - Web search │ │ - Data analysis │ │ - Text generation│
|
|
39
|
+
│ - Doc retrieval │ │ - Comparisons │ │ - Summaries │
|
|
40
|
+
│ - RAG │ │ - Insights │ │ - Reports │
|
|
41
|
+
└──────────────────┘ └──────────────────┘ └──────────────────┘
|
|
42
|
+
│ │ │
|
|
43
|
+
└───────────────┼───────────────┘
|
|
44
|
+
▼
|
|
45
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
46
|
+
│ Consolidated Response │
|
|
47
|
+
└─────────────────────────────────────────────────────────────┘
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Estrutura do Projeto
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
src/
|
|
54
|
+
├── MultiAgent.Core/
|
|
55
|
+
│ ├── Agents/
|
|
56
|
+
│ │ ├── OrchestratorAgent.cs
|
|
57
|
+
│ │ ├── ResearchAgent.cs
|
|
58
|
+
│ │ ├── AnalysisAgent.cs
|
|
59
|
+
│ │ └── WritingAgent.cs
|
|
60
|
+
│ ├── Plugins/
|
|
61
|
+
│ │ ├── WebSearchPlugin.cs
|
|
62
|
+
│ │ ├── DocumentPlugin.cs
|
|
63
|
+
│ │ └── DataAnalysisPlugin.cs
|
|
64
|
+
│ ├── Memory/
|
|
65
|
+
│ │ ├── ConversationMemory.cs
|
|
66
|
+
│ │ └── SemanticMemory.cs
|
|
67
|
+
│ └── Orchestration/
|
|
68
|
+
│ ├── TaskDecomposer.cs
|
|
69
|
+
│ └── ResultAggregator.cs
|
|
70
|
+
│
|
|
71
|
+
├── MultiAgent.Infrastructure/
|
|
72
|
+
│ ├── Services/
|
|
73
|
+
│ │ ├── AzureOpenAIService.cs
|
|
74
|
+
│ │ └── EmbeddingService.cs
|
|
75
|
+
│ └── Storage/
|
|
76
|
+
│ ├── ConversationStore.cs
|
|
77
|
+
│ └── VectorStore.cs
|
|
78
|
+
│
|
|
79
|
+
└── MultiAgent.Api/
|
|
80
|
+
├── Endpoints/
|
|
81
|
+
│ ├── ChatEndpoints.cs
|
|
82
|
+
│ └── AgentEndpoints.cs
|
|
83
|
+
└── Program.cs
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Quick Start
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# 1. Configure Azure OpenAI
|
|
90
|
+
# Crie um recurso Azure OpenAI e configure:
|
|
91
|
+
# - Deployment para gpt-4
|
|
92
|
+
# - Deployment para text-embedding-ada-002
|
|
93
|
+
|
|
94
|
+
# 2. Configure appsettings.json
|
|
95
|
+
cp appsettings.example.json appsettings.json
|
|
96
|
+
# Edite com suas credenciais
|
|
97
|
+
|
|
98
|
+
# 3. Run
|
|
99
|
+
cd src/MultiAgent.Api
|
|
100
|
+
dotnet run
|
|
101
|
+
|
|
102
|
+
# 4. Test
|
|
103
|
+
curl -X POST http://localhost:5000/api/chat \
|
|
104
|
+
-H "Content-Type: application/json" \
|
|
105
|
+
-d '{"message": "Compare the top 3 cloud providers for a SaaS startup"}'
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Agentes
|
|
109
|
+
|
|
110
|
+
### 1. Orchestrator Agent
|
|
111
|
+
|
|
112
|
+
O agente principal que coordena todos os outros.
|
|
113
|
+
|
|
114
|
+
**Responsabilidades**:
|
|
115
|
+
- Analisar a intenção do usuário
|
|
116
|
+
- Decompor tarefas complexas
|
|
117
|
+
- Delegar para agentes especialistas
|
|
118
|
+
- Consolidar respostas
|
|
119
|
+
|
|
120
|
+
### 2. Research Agent
|
|
121
|
+
|
|
122
|
+
Especialista em busca e recuperação de informações.
|
|
123
|
+
|
|
124
|
+
**Capabilities**:
|
|
125
|
+
- Web search (Bing API)
|
|
126
|
+
- Document retrieval (RAG)
|
|
127
|
+
- Knowledge base queries
|
|
128
|
+
|
|
129
|
+
### 3. Analysis Agent
|
|
130
|
+
|
|
131
|
+
Especialista em análise de dados e comparações.
|
|
132
|
+
|
|
133
|
+
**Capabilities**:
|
|
134
|
+
- Data analysis
|
|
135
|
+
- Trend identification
|
|
136
|
+
- Comparative analysis
|
|
137
|
+
- Insight generation
|
|
138
|
+
|
|
139
|
+
### 4. Writing Agent
|
|
140
|
+
|
|
141
|
+
Especialista em geração de conteúdo.
|
|
142
|
+
|
|
143
|
+
**Capabilities**:
|
|
144
|
+
- Text summarization
|
|
145
|
+
- Report generation
|
|
146
|
+
- Content formatting
|
|
147
|
+
- Translation
|
|
148
|
+
|
|
149
|
+
## Plugins
|
|
150
|
+
|
|
151
|
+
### WebSearchPlugin
|
|
152
|
+
|
|
153
|
+
```csharp
|
|
154
|
+
[KernelFunction("search_web")]
|
|
155
|
+
[Description("Search the web for information")]
|
|
156
|
+
public async Task<string> SearchWebAsync(
|
|
157
|
+
[Description("The search query")] string query,
|
|
158
|
+
[Description("Number of results")] int maxResults = 5)
|
|
159
|
+
{
|
|
160
|
+
// Implementação com Bing Search API
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### DocumentPlugin
|
|
165
|
+
|
|
166
|
+
```csharp
|
|
167
|
+
[KernelFunction("retrieve_documents")]
|
|
168
|
+
[Description("Retrieve relevant documents from the knowledge base")]
|
|
169
|
+
public async Task<IEnumerable<Document>> RetrieveDocumentsAsync(
|
|
170
|
+
[Description("The query to search for")] string query,
|
|
171
|
+
[Description("Maximum documents to return")] int limit = 3)
|
|
172
|
+
{
|
|
173
|
+
// Implementação com Vector Store
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Fluxo de Execução
|
|
178
|
+
|
|
179
|
+
```mermaid
|
|
180
|
+
sequenceDiagram
|
|
181
|
+
participant User
|
|
182
|
+
participant API
|
|
183
|
+
participant Orchestrator
|
|
184
|
+
participant Research
|
|
185
|
+
participant Analysis
|
|
186
|
+
participant Writing
|
|
187
|
+
|
|
188
|
+
User->>API: "Compare cloud providers for SaaS"
|
|
189
|
+
API->>Orchestrator: Process request
|
|
190
|
+
|
|
191
|
+
Orchestrator->>Orchestrator: Decompose task
|
|
192
|
+
Note over Orchestrator: 1. Research providers<br/>2. Analyze features<br/>3. Write comparison
|
|
193
|
+
|
|
194
|
+
Orchestrator->>Research: Get info on AWS, Azure, GCP
|
|
195
|
+
Research->>Research: Web search + RAG
|
|
196
|
+
Research-->>Orchestrator: Provider data
|
|
197
|
+
|
|
198
|
+
Orchestrator->>Analysis: Compare features, pricing
|
|
199
|
+
Analysis->>Analysis: Analyze data
|
|
200
|
+
Analysis-->>Orchestrator: Comparison insights
|
|
201
|
+
|
|
202
|
+
Orchestrator->>Writing: Create comparison report
|
|
203
|
+
Writing->>Writing: Generate formatted report
|
|
204
|
+
Writing-->>Orchestrator: Final report
|
|
205
|
+
|
|
206
|
+
Orchestrator-->>API: Consolidated response
|
|
207
|
+
API-->>User: Comparison report
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Configuração
|
|
211
|
+
|
|
212
|
+
### appsettings.json
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"AzureOpenAI": {
|
|
217
|
+
"Endpoint": "https://your-resource.openai.azure.com/",
|
|
218
|
+
"ApiKey": "your-api-key",
|
|
219
|
+
"ChatDeployment": "gpt-4",
|
|
220
|
+
"EmbeddingDeployment": "text-embedding-ada-002"
|
|
221
|
+
},
|
|
222
|
+
"BingSearch": {
|
|
223
|
+
"ApiKey": "your-bing-api-key",
|
|
224
|
+
"Endpoint": "https://api.bing.microsoft.com/v7.0/search"
|
|
225
|
+
},
|
|
226
|
+
"VectorStore": {
|
|
227
|
+
"Type": "InMemory",
|
|
228
|
+
"CosmosDbEndpoint": "",
|
|
229
|
+
"CosmosDbKey": ""
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Custos Estimados
|
|
235
|
+
|
|
236
|
+
| Recurso | Tier | Custo Estimado |
|
|
237
|
+
|---------|------|----------------|
|
|
238
|
+
| Azure OpenAI (GPT-4) | Pay-per-token | ~$0.03/1K tokens |
|
|
239
|
+
| Azure OpenAI (Embeddings) | Pay-per-token | ~$0.0001/1K tokens |
|
|
240
|
+
| Bing Search API | S1 | $7/1K transactions |
|
|
241
|
+
| Container Apps | Consumption | ~$0-10/mês |
|
|
242
|
+
| Cosmos DB (opcional) | Serverless | ~$0-5/mês |
|
|
243
|
+
|
|
244
|
+
**Nota**: Custos variam significativamente com uso. Para desenvolvimento, use modelos menores (GPT-3.5-turbo).
|
|
245
|
+
|
|
246
|
+
## Extensibilidade
|
|
247
|
+
|
|
248
|
+
### Adicionando um Novo Agente
|
|
249
|
+
|
|
250
|
+
```csharp
|
|
251
|
+
public class CustomAgent : BaseAgent
|
|
252
|
+
{
|
|
253
|
+
public CustomAgent(Kernel kernel) : base(kernel)
|
|
254
|
+
{
|
|
255
|
+
SystemPrompt = """
|
|
256
|
+
You are a specialized agent for [purpose].
|
|
257
|
+
Your capabilities include:
|
|
258
|
+
- [capability 1]
|
|
259
|
+
- [capability 2]
|
|
260
|
+
""";
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public override async Task<AgentResponse> ProcessAsync(AgentRequest request)
|
|
264
|
+
{
|
|
265
|
+
// Implementação específica
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Adicionando um Novo Plugin
|
|
271
|
+
|
|
272
|
+
```csharp
|
|
273
|
+
public class CustomPlugin
|
|
274
|
+
{
|
|
275
|
+
[KernelFunction("custom_function")]
|
|
276
|
+
[Description("Description of what this function does")]
|
|
277
|
+
public async Task<string> CustomFunctionAsync(
|
|
278
|
+
[Description("Parameter description")] string param)
|
|
279
|
+
{
|
|
280
|
+
// Implementação
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
## Padrões de Comunicação
|
|
286
|
+
|
|
287
|
+
### 1. Request-Response
|
|
288
|
+
|
|
289
|
+
Agente recebe request, processa e retorna response.
|
|
290
|
+
|
|
291
|
+
### 2. Pub-Sub (Event-Driven)
|
|
292
|
+
|
|
293
|
+
Agentes publicam eventos que outros agentes podem consumir.
|
|
294
|
+
|
|
295
|
+
### 3. Handoff
|
|
296
|
+
|
|
297
|
+
Agente transfere contexto completo para outro agente.
|
|
298
|
+
|
|
299
|
+
## Boas Práticas
|
|
300
|
+
|
|
301
|
+
1. **Prompts claros**: Defina system prompts específicos para cada agente
|
|
302
|
+
2. **Fallbacks**: Implemente fallbacks quando um agente falhar
|
|
303
|
+
3. **Rate limiting**: Controle chamadas à API para evitar throttling
|
|
304
|
+
4. **Logging**: Log todas as interações para debugging
|
|
305
|
+
5. **Cost tracking**: Monitore tokens consumidos
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
*MORPH-SPEC by Polymorphism Tech*
|