forjajs 5.0.1 → 5.3.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/CHANGELOG.md +114 -2
- package/README.md +40 -5
- package/README.pt-BR.md +42 -4
- package/boilerplates/02-saas-starter/README.md +58 -293
- package/boilerplates/02-saas-starter/backend/.env.example +13 -0
- package/boilerplates/02-saas-starter/backend/.oxlintrc.json +8 -0
- package/boilerplates/02-saas-starter/backend/nest-cli.json +6 -0
- package/boilerplates/02-saas-starter/backend/package.json +32 -73
- package/boilerplates/02-saas-starter/backend/src/app.module.ts +16 -16
- package/boilerplates/02-saas-starter/backend/src/billing/adapters/http/billing.controller.ts +55 -0
- package/boilerplates/02-saas-starter/backend/src/billing/adapters/persistence/orm-entities.ts +28 -0
- package/boilerplates/02-saas-starter/backend/src/billing/adapters/persistence/typeorm-billing.repository.ts +46 -0
- package/boilerplates/02-saas-starter/backend/src/billing/application/billing.service.spec.ts +58 -0
- package/boilerplates/02-saas-starter/backend/src/billing/application/billing.service.ts +68 -0
- package/boilerplates/02-saas-starter/backend/src/billing/billing.module.ts +11 -0
- package/boilerplates/02-saas-starter/backend/src/billing/domain/plan.spec.ts +23 -0
- package/boilerplates/02-saas-starter/backend/src/billing/domain/plan.ts +36 -0
- package/boilerplates/02-saas-starter/backend/src/billing/domain/ports.ts +27 -0
- package/boilerplates/02-saas-starter/backend/src/billing/domain/subscription.spec.ts +28 -0
- package/boilerplates/02-saas-starter/backend/src/billing/domain/subscription.ts +47 -0
- package/boilerplates/02-saas-starter/backend/src/identity/adapters/http/auth.dto.ts +22 -0
- package/boilerplates/02-saas-starter/backend/src/identity/adapters/http/identity.controller.ts +59 -0
- package/boilerplates/02-saas-starter/backend/src/identity/adapters/persistence/orm-entities.ts +25 -0
- package/boilerplates/02-saas-starter/backend/src/identity/adapters/persistence/typeorm-identity.repository.ts +47 -0
- package/boilerplates/02-saas-starter/backend/src/identity/application/auth.service.spec.ts +72 -0
- package/boilerplates/02-saas-starter/backend/src/identity/application/auth.service.ts +63 -0
- package/boilerplates/02-saas-starter/backend/src/identity/domain/model.spec.ts +19 -0
- package/boilerplates/02-saas-starter/backend/src/identity/domain/model.ts +42 -0
- package/boilerplates/02-saas-starter/backend/src/identity/domain/password.spec.ts +17 -0
- package/boilerplates/02-saas-starter/backend/src/identity/domain/password.ts +26 -0
- package/boilerplates/02-saas-starter/backend/src/identity/identity.module.ts +12 -0
- package/boilerplates/02-saas-starter/backend/src/main.ts +19 -19
- package/boilerplates/02-saas-starter/backend/src/platform/auth/jwt-auth.guard.ts +17 -0
- package/boilerplates/02-saas-starter/backend/src/platform/auth/principal.ts +22 -0
- package/boilerplates/02-saas-starter/backend/src/platform/auth/roles.guard.spec.ts +23 -0
- package/boilerplates/02-saas-starter/backend/src/platform/auth/roles.guard.ts +20 -0
- package/boilerplates/02-saas-starter/backend/src/platform/auth/token.service.ts +54 -0
- package/boilerplates/02-saas-starter/backend/src/platform/config.spec.ts +18 -0
- package/boilerplates/02-saas-starter/backend/src/platform/config.ts +33 -0
- package/boilerplates/02-saas-starter/backend/src/platform/platform.module.ts +14 -0
- package/boilerplates/02-saas-starter/backend/tsconfig.build.json +6 -0
- package/boilerplates/02-saas-starter/backend/tsconfig.json +16 -21
- package/boilerplates/02-saas-starter/backend/vitest.config.ts +7 -0
- package/boilerplates/02-saas-starter/boilerplate.manifest.json +19 -14
- package/boilerplates/02-saas-starter/docker-compose.yml +10 -24
- package/boilerplates/02-saas-starter/memory/30-domains/billing/context.md +15 -132
- package/boilerplates/02-saas-starter/memory/30-domains/identity/context.md +20 -0
- package/boilerplates/README.md +9 -10
- package/dist/apps/cli/src/index.d.ts +0 -1
- package/dist/apps/cli/src/index.js +43 -32
- package/dist/apps/dashboard/app/api/forja/[...path]/route.js +34 -1
- package/dist/apps/dashboard/app/api/forja/capabilities.d.ts +26 -0
- package/dist/apps/dashboard/app/api/forja/capabilities.js +39 -0
- package/dist/apps/dashboard/app/dashboard-client.jsx +607 -42
- package/dist/apps/server/src/forja-nest.module.d.ts +6 -0
- package/dist/apps/server/src/forja-nest.module.js +55 -0
- package/dist/apps/server/src/main.d.ts +21 -4
- package/dist/apps/server/src/main.js +79 -57
- package/dist/apps/server/src/task-planning-service.d.ts +29 -0
- package/dist/apps/server/src/task-planning-service.js +195 -0
- package/dist/apps/server/src/task-runtime-coordinator.d.ts +57 -0
- package/dist/apps/server/src/task-runtime-coordinator.js +229 -0
- package/dist/bin/forja.js +3 -2
- package/dist/bin/init-project.js +1 -0
- package/dist/lib/agent-evals.d.ts +138 -0
- package/dist/lib/agent-evals.js +349 -0
- package/dist/lib/cli-output.js +14 -2
- package/dist/lib/code-context.d.ts +33 -5
- package/dist/lib/code-context.js +70 -5
- package/dist/lib/context-builder.d.ts +49 -4
- package/dist/lib/context-builder.js +114 -47
- package/dist/lib/core/coverage-gate.d.ts +59 -0
- package/dist/lib/core/coverage-gate.js +58 -0
- package/dist/lib/core/doc-graph.d.ts +38 -0
- package/dist/lib/core/doc-graph.js +83 -0
- package/dist/lib/core/health.js +286 -5
- package/dist/lib/core/journey.js +36 -0
- package/dist/lib/core/registry.js +81 -6
- package/dist/lib/docs-reference.d.ts +35 -0
- package/dist/lib/docs-reference.js +57 -0
- package/dist/lib/generators/memory-generator.d.ts +0 -11
- package/dist/lib/generators/memory-generator.js +5 -161
- package/dist/lib/generators/readme-generator.js +1 -1
- package/dist/lib/llm/json-output.d.ts +14 -0
- package/dist/lib/llm/json-output.js +77 -0
- package/dist/lib/project-wiring.d.ts +8 -0
- package/dist/lib/project-wiring.js +79 -3
- package/dist/lib/session-memory.d.ts +38 -0
- package/dist/lib/session-memory.js +206 -0
- package/dist/lib/spec-trace.d.ts +46 -0
- package/dist/lib/spec-trace.js +184 -0
- package/dist/lib/validators/structure-validator.js +0 -1
- package/dist/packages/adapter-nest/src/index.d.ts +2 -1
- package/dist/packages/adapter-nest/src/index.js +59 -1
- package/dist/packages/adapter-sqlite/src/index.d.ts +15 -1
- package/dist/packages/adapter-sqlite/src/index.js +61 -1
- package/dist/packages/context/src/index.d.ts +2 -0
- package/dist/packages/context/src/index.js +36 -15
- package/dist/packages/contracts/src/index.d.ts +64 -0
- package/dist/packages/core/src/index.d.ts +9 -1
- package/dist/packages/core/src/index.js +28 -3
- package/dist/packages/graph/src/index.js +14 -5
- package/dist/packages/llm/src/index.js +12 -2
- package/dist/packages/mcp/src/index.d.ts +8 -0
- package/dist/packages/mcp/src/index.js +12 -1
- package/dist/packages/observability/src/index.d.ts +11 -0
- package/dist/packages/observability/src/index.js +3 -0
- package/dist/packages/orchestration/src/index.d.ts +15 -1
- package/dist/packages/orchestration/src/index.js +127 -21
- package/dist/packages/planner/src/index.d.ts +7 -1
- package/dist/packages/planner/src/index.js +67 -10
- package/dist/packages/planner/src/proposal-store.d.ts +30 -0
- package/dist/packages/planner/src/proposal-store.js +109 -0
- package/dist/packages/policy/src/index.d.ts +9 -16
- package/dist/packages/policy/src/index.js +114 -31
- package/dist/packages/runtime/src/index.d.ts +16 -2
- package/dist/packages/runtime/src/index.js +176 -61
- package/dist/scripts/build-smart-context.d.ts +2 -0
- package/dist/scripts/build-smart-context.js +12 -3
- package/dist/scripts/code-context.d.ts +3 -1
- package/dist/scripts/code-context.js +13 -3
- package/dist/scripts/coverage-gate.d.ts +2 -0
- package/dist/scripts/coverage-gate.js +101 -0
- package/dist/scripts/eval-agents.d.ts +11 -0
- package/dist/scripts/eval-agents.js +96 -0
- package/dist/scripts/gen-commands-doc.d.ts +2 -0
- package/dist/scripts/gen-commands-doc.js +18 -0
- package/dist/scripts/hook-session-memory.d.ts +9 -0
- package/dist/scripts/hook-session-memory.js +20 -0
- package/dist/scripts/hook-session-start.js +34 -0
- package/dist/scripts/llm-fit.js +23 -1
- package/dist/scripts/spec-trace.d.ts +10 -0
- package/dist/scripts/spec-trace.js +73 -0
- package/dist/scripts/sync-universal-memory.js +69 -4
- package/dist/scripts/token-benchmark.d.ts +33 -1
- package/dist/scripts/token-benchmark.js +179 -5
- package/dist/scripts/token-economy.js +3 -1
- package/dist/scripts/tools-doctor.d.ts +16 -1
- package/dist/scripts/tools-doctor.js +58 -17
- package/docs/commands.md +155 -0
- package/docs/fluxo.md +11 -7
- package/docs/init-project.md +3 -1
- package/docs/llm-fit-loop.md +36 -0
- package/docs/manual-operacional-cli-sdd-gsd.md +3 -2
- package/docs/produto/factsheet-marketing.md +7 -5
- package/docs/produto/roteiro-demo.md +14 -5
- package/docs/quick-reference.md +3 -3
- package/docs/token-optimization.md +10 -6
- package/memory/90-decisions/0088-templates-validados.md +3 -0
- package/memory/90-decisions/0089-skills-do-projeto.md +51 -0
- package/memory/90-decisions/0090-adapters-de-agente-somente-leitura.md +47 -0
- package/memory/90-decisions/0091-memoria-de-sessao-por-hooks.md +40 -0
- package/memory/90-decisions/0092-criterios-de-aceite-ligados-a-testes.md +37 -0
- package/memory/90-decisions/0093-avaliacoes-com-agentes-reais.md +40 -0
- package/package.json +4 -2
- package/specs/avaliacoes-de-agentes/spec.md +52 -0
- package/specs/criterios-ligados-a-testes/spec.md +42 -0
- package/specs/memoria-de-sessao/spec.md +48 -0
- package/specs/skills-do-projeto/plan.md +40 -0
- package/specs/skills-do-projeto/spec.md +63 -0
- package/specs/skills-do-projeto/tasks.md +27 -0
- package/specs/v6-agent-runtime-portable/spec.md +83 -0
- package/specs/v6-core-consolidation/spec.md +70 -0
- package/specs/v6-docs-drift/spec.md +85 -0
- package/specs/v6-quality-gates/spec.md +99 -0
- package/specs/v6-token-economy/spec.md +84 -0
- package/templates/evals/agents/adr.json +25 -0
- package/templates/evals/agents/memoria.json +32 -0
- package/templates/evals/agents/proxima-acao.json +29 -0
- package/templates/evals/agents/spec-nova.json +26 -0
- package/templates/evals/agents/teste-do-criterio.json +29 -0
- package/templates/project/AGENTS.md +16 -0
- package/templates/project/CLAUDE.md +3 -2
- package/templates/project/agents/context-engineer.md +3 -0
- package/templates/project/agents/governance.md +3 -0
- package/templates/project/agents/marketing.md +3 -0
- package/templates/project/agents/orchestrator.md +3 -0
- package/templates/project/agents/product.md +3 -0
- package/templates/project/agents/sdd-architect.md +3 -0
- package/templates/project/skills/README.md +14 -0
- package/templates/project/skills/accessibility-review/SKILL.md +89 -0
- package/templates/project/skills/api-design/SKILL.md +77 -0
- package/templates/project/skills/architecture-decision-record/SKILL.md +92 -0
- package/templates/project/skills/backlog-slicing/SKILL.md +82 -0
- package/templates/project/skills/bounded-context-mapping/SKILL.md +88 -0
- package/templates/project/skills/ci-pipeline-review/SKILL.md +83 -0
- package/templates/project/skills/commit-message/SKILL.md +143 -0
- package/templates/project/skills/data-migrations/SKILL.md +88 -0
- package/templates/project/skills/dependency-upgrade/SKILL.md +75 -0
- package/templates/project/skills/docker-compose-review/SKILL.md +85 -0
- package/templates/project/skills/domain-modeling/SKILL.md +120 -0
- package/templates/project/skills/event-storming/SKILL.md +95 -0
- package/templates/project/skills/executive-writing/SKILL.md +99 -0
- package/templates/project/skills/frontend-architecture/SKILL.md +97 -0
- package/templates/project/skills/incident-postmortem/SKILL.md +93 -0
- package/templates/project/skills/lgpd-compliance/SKILL.md +108 -0
- package/templates/project/skills/llm-provider-routing/SKILL.md +18 -0
- package/templates/project/skills/observability/SKILL.md +93 -0
- package/templates/project/skills/product-evaluation/SKILL.md +130 -0
- package/templates/project/skills/prompt-spec/SKILL.md +83 -0
- package/templates/project/skills/pull-request/SKILL.md +101 -0
- package/templates/project/skills/query-performance/SKILL.md +83 -0
- package/templates/project/skills/release-checklist/SKILL.md +106 -0
- package/templates/project/skills/release-notes/SKILL.md +87 -0
- package/templates/project/skills/requirements-elicitation/SKILL.md +127 -0
- package/templates/project/skills/requirements-gathering/SKILL.md +134 -0
- package/templates/project/skills/technical-spike/SKILL.md +101 -0
- package/templates/project/skills/testing/SKILL.md +109 -0
- package/templates/project/skills/threat-modeling/SKILL.md +87 -0
- package/templates/project/skills/ts-async-patterns/SKILL.md +101 -0
- package/templates/project/skills/ts-code-review/SKILL.md +121 -0
- package/templates/project/skills/ts-module-layout/SKILL.md +104 -0
- package/templates/project/skills/ts-testing/SKILL.md +89 -0
- package/templates/project/skills/web-performance/SKILL.md +72 -0
- package/boilerplates/02-saas-starter/.env.example +0 -25
- package/boilerplates/02-saas-starter/CHECKLIST-CRIACAO.md +0 -190
- package/boilerplates/02-saas-starter/INFO.md +0 -252
- package/boilerplates/02-saas-starter/QUICK_START.md +0 -194
- package/boilerplates/02-saas-starter/START-HERE.md +0 -259
- package/boilerplates/02-saas-starter/backend/src/common/decorators/roles.decorator.ts +0 -3
- package/boilerplates/02-saas-starter/backend/src/common/decorators/tenant.decorator.ts +0 -6
- package/boilerplates/02-saas-starter/backend/src/common/middleware/roles.guard.ts +0 -23
- package/boilerplates/02-saas-starter/backend/src/config/database.ts +0 -26
- package/boilerplates/02-saas-starter/backend/src/modules/auth/auth.controller.ts +0 -46
- package/boilerplates/02-saas-starter/backend/src/modules/auth/auth.module.ts +0 -25
- package/boilerplates/02-saas-starter/backend/src/modules/auth/auth.service.ts +0 -145
- package/boilerplates/02-saas-starter/backend/src/modules/auth/dto/auth.dto.ts +0 -30
- package/boilerplates/02-saas-starter/backend/src/modules/auth/strategies/jwt.strategy.ts +0 -24
- package/boilerplates/02-saas-starter/backend/src/modules/auth/strategies/local.strategy.ts +0 -19
- package/boilerplates/02-saas-starter/backend/src/modules/billing/billing.controller.ts +0 -42
- package/boilerplates/02-saas-starter/backend/src/modules/billing/billing.module.ts +0 -13
- package/boilerplates/02-saas-starter/backend/src/modules/billing/billing.service.ts +0 -67
- package/boilerplates/02-saas-starter/backend/src/modules/billing/entities/invoice.entity.ts +0 -52
- package/boilerplates/02-saas-starter/backend/src/modules/organizations/entities/organization.entity.ts +0 -36
- package/boilerplates/02-saas-starter/backend/src/modules/organizations/organizations.controller.ts +0 -16
- package/boilerplates/02-saas-starter/backend/src/modules/organizations/organizations.module.ts +0 -13
- package/boilerplates/02-saas-starter/backend/src/modules/organizations/organizations.service.ts +0 -34
- package/boilerplates/02-saas-starter/backend/src/modules/subscriptions/entities/subscription.entity.ts +0 -40
- package/boilerplates/02-saas-starter/backend/src/modules/subscriptions/subscriptions.controller.ts +0 -36
- package/boilerplates/02-saas-starter/backend/src/modules/subscriptions/subscriptions.module.ts +0 -13
- package/boilerplates/02-saas-starter/backend/src/modules/subscriptions/subscriptions.service.ts +0 -91
- package/boilerplates/02-saas-starter/backend/src/modules/users/entities/user.entity.ts +0 -42
- package/boilerplates/02-saas-starter/backend/src/modules/users/users.controller.ts +0 -14
- package/boilerplates/02-saas-starter/backend/src/modules/users/users.module.ts +0 -13
- package/boilerplates/02-saas-starter/backend/src/modules/users/users.service.ts +0 -48
- package/boilerplates/02-saas-starter/memory/00-global/agent-contract.md +0 -227
- package/boilerplates/02-saas-starter/memory/00-global/context-policy.md +0 -141
- package/boilerplates/02-saas-starter/memory/00-global/index.md +0 -133
- package/boilerplates/02-saas-starter/memory/00-global/mission.md +0 -45
- package/boilerplates/02-saas-starter/memory/00-global/patterns.md +0 -223
- package/boilerplates/02-saas-starter/memory/10-product/business-rules.md +0 -240
- package/boilerplates/02-saas-starter/memory/10-product/nfrs.md +0 -239
- package/boilerplates/02-saas-starter/memory/10-product/personas.md +0 -195
- package/boilerplates/02-saas-starter/memory/10-product/vision.md +0 -63
- package/boilerplates/02-saas-starter/memory/20-architecture/overview.md +0 -232
- package/boilerplates/02-saas-starter/memory/30-domains/auth/api.md +0 -186
- package/boilerplates/02-saas-starter/memory/30-domains/auth/context.md +0 -85
- package/boilerplates/02-saas-starter/memory/30-domains/billing/api.md +0 -262
- package/boilerplates/02-saas-starter/memory/30-domains/subscriptions/api.md +0 -176
- package/boilerplates/02-saas-starter/memory/30-domains/subscriptions/context.md +0 -100
- package/boilerplates/02-saas-starter/memory/40-delivery/backlog.md +0 -81
- package/boilerplates/02-saas-starter/memory/40-delivery/roadmap.md +0 -97
- package/boilerplates/02-saas-starter/memory/40-delivery/sprint-atual.md +0 -57
- package/boilerplates/02-saas-starter/memory/50-orchestration/topology.md +0 -90
- package/boilerplates/02-saas-starter/memory/60-runs/index.md +0 -54
- package/boilerplates/02-saas-starter/memory/70-summaries/global.md +0 -50
- package/boilerplates/02-saas-starter/memory/80-data/schema.md +0 -185
- package/boilerplates/02-saas-starter/memory/90-decisions/adr-template.md +0 -75
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
# Padrões & Convenções do Projeto SaaS Starter
|
|
2
|
-
|
|
3
|
-
## Code Patterns
|
|
4
|
-
|
|
5
|
-
### 1. Estrutura de Módulo
|
|
6
|
-
|
|
7
|
-
Cada módulo segue este padrão:
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
modules/
|
|
11
|
-
├── domain-name/
|
|
12
|
-
├── entities/
|
|
13
|
-
│ └── domain.entity.ts # Typeorm entity
|
|
14
|
-
├── dto/
|
|
15
|
-
│ ├── create-domain.dto.ts
|
|
16
|
-
│ └── update-domain.dto.ts
|
|
17
|
-
├── domain.service.ts # Lógica de negócio
|
|
18
|
-
├── domain.controller.ts # Endpoints HTTP
|
|
19
|
-
└── domain.module.ts # Module definition
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### 2. Service Pattern
|
|
23
|
-
|
|
24
|
-
```typescript
|
|
25
|
-
@Injectable()
|
|
26
|
-
export class DomainService {
|
|
27
|
-
constructor(
|
|
28
|
-
@InjectRepository(DomainEntity)
|
|
29
|
-
private readonly repo: Repository<DomainEntity>,
|
|
30
|
-
private readonly tenantContext: TenantContextService,
|
|
31
|
-
) {}
|
|
32
|
-
|
|
33
|
-
async create(dto: CreateDomainDto): Promise<DomainEntity> {
|
|
34
|
-
const tenantId = this.tenantContext.getTenantId();
|
|
35
|
-
return this.repo.save({
|
|
36
|
-
...dto,
|
|
37
|
-
tenantId,
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### 3. Controller Pattern
|
|
44
|
-
|
|
45
|
-
```typescript
|
|
46
|
-
@Controller('api/domains')
|
|
47
|
-
@UseGuards(JwtAuthGuard, RolesGuard)
|
|
48
|
-
export class DomainController {
|
|
49
|
-
constructor(private readonly service: DomainService) {}
|
|
50
|
-
|
|
51
|
-
@Post()
|
|
52
|
-
@Roles('admin', 'owner')
|
|
53
|
-
create(@Body() dto: CreateDomainDto) {
|
|
54
|
-
return this.service.create(dto);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
### 4. Tenant Context
|
|
60
|
-
|
|
61
|
-
- Injetado via middleware no request
|
|
62
|
-
- Validado no JwtStrategy
|
|
63
|
-
- Isolado por request usando Async Local Storage
|
|
64
|
-
- Sempre incluído em queries do banco
|
|
65
|
-
|
|
66
|
-
### 5. RBAC (Role-Based Access Control)
|
|
67
|
-
|
|
68
|
-
**Roles:**
|
|
69
|
-
- `owner` — full access, billing, team management
|
|
70
|
-
- `admin` — module management, user invites
|
|
71
|
-
- `member` — read + limited operations
|
|
72
|
-
|
|
73
|
-
**Decorator:**
|
|
74
|
-
```typescript
|
|
75
|
-
@Roles('owner', 'admin')
|
|
76
|
-
async update(@Param('id') id: string) { }
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### 6. Error Handling
|
|
80
|
-
|
|
81
|
-
```typescript
|
|
82
|
-
throw new BadRequestException('Invalid subscription plan');
|
|
83
|
-
throw new ForbiddenException('Only organization owners can manage billing');
|
|
84
|
-
throw new UnauthorizedException('Invalid credentials');
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### 7. Validation
|
|
88
|
-
|
|
89
|
-
- Class-validator para DTOs
|
|
90
|
-
- Custom validators para regras de negócio
|
|
91
|
-
- Pipes no controller
|
|
92
|
-
|
|
93
|
-
## Database Patterns
|
|
94
|
-
|
|
95
|
-
### 1. Tenant Isolation
|
|
96
|
-
|
|
97
|
-
Todas as entidades têm `tenantId`:
|
|
98
|
-
```typescript
|
|
99
|
-
@Entity()
|
|
100
|
-
export class Organization {
|
|
101
|
-
@PrimaryGeneratedColumn('uuid')
|
|
102
|
-
id: string;
|
|
103
|
-
|
|
104
|
-
@Column({ type: 'uuid' })
|
|
105
|
-
tenantId: string;
|
|
106
|
-
|
|
107
|
-
// ...
|
|
108
|
-
}
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### 2. Soft Deletes
|
|
112
|
-
|
|
113
|
-
Entidades com dados sensíveis usam soft delete:
|
|
114
|
-
```typescript
|
|
115
|
-
@DeleteDateColumn()
|
|
116
|
-
deletedAt?: Date;
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### 3. Indexes
|
|
120
|
-
|
|
121
|
-
```typescript
|
|
122
|
-
@Index(['tenantId', 'email'])
|
|
123
|
-
@Index(['tenantId', 'status'])
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
## API Conventions
|
|
127
|
-
|
|
128
|
-
### 1. Response Format
|
|
129
|
-
|
|
130
|
-
```json
|
|
131
|
-
{
|
|
132
|
-
"data": { /* resource */ },
|
|
133
|
-
"meta": {
|
|
134
|
-
"timestamp": "2024-01-15T10:30:00Z",
|
|
135
|
-
"version": "1.0"
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 2. Error Response
|
|
141
|
-
|
|
142
|
-
```json
|
|
143
|
-
{
|
|
144
|
-
"error": "RESOURCE_NOT_FOUND",
|
|
145
|
-
"message": "Organization not found",
|
|
146
|
-
"statusCode": 404,
|
|
147
|
-
"timestamp": "2024-01-15T10:30:00Z"
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
### 3. List Response
|
|
152
|
-
|
|
153
|
-
```json
|
|
154
|
-
{
|
|
155
|
-
"data": [ /* items */ ],
|
|
156
|
-
"pagination": {
|
|
157
|
-
"page": 1,
|
|
158
|
-
"limit": 20,
|
|
159
|
-
"total": 150,
|
|
160
|
-
"pages": 8
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
## Testing Conventions
|
|
166
|
-
|
|
167
|
-
### 1. Unit Tests
|
|
168
|
-
|
|
169
|
-
- Usar `jest` com `@testing-library/nestjs`
|
|
170
|
-
- Mock services com `jest.Mock`
|
|
171
|
-
- Testar apenas a unidade, não integração
|
|
172
|
-
|
|
173
|
-
### 2. E2E Tests
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
describe('Auth (e2e)', () => {
|
|
177
|
-
let app: INestApplication;
|
|
178
|
-
|
|
179
|
-
beforeAll(async () => {
|
|
180
|
-
// Setup
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
it('should signup user', async () => {
|
|
184
|
-
const response = await request(app.getHttpServer())
|
|
185
|
-
.post('/api/auth/signup')
|
|
186
|
-
.send({ email, password });
|
|
187
|
-
|
|
188
|
-
expect(response.status).toBe(201);
|
|
189
|
-
expect(response.body.data.accessToken).toBeDefined();
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
## Naming Conventions
|
|
195
|
-
|
|
196
|
-
- **Services**: `PascalCase + Service` (AuthService, SubscriptionService)
|
|
197
|
-
- **Controllers**: `PascalCase + Controller` (AuthController)
|
|
198
|
-
- **Entities**: `PascalCase + Entity` (UserEntity)
|
|
199
|
-
- **DTOs**: `PascalCase + Dto` (CreateUserDto)
|
|
200
|
-
- **Routes**: kebab-case (/api/auth/sign-up)
|
|
201
|
-
- **Fields**: camelCase (firstName, tenantId, createdAt)
|
|
202
|
-
|
|
203
|
-
## Commit Message Format
|
|
204
|
-
|
|
205
|
-
```
|
|
206
|
-
feat: add subscription upgrade endpoint
|
|
207
|
-
|
|
208
|
-
- Add POST /api/subscriptions/:id/upgrade
|
|
209
|
-
- Validate plan compatibility
|
|
210
|
-
- Record billing event
|
|
211
|
-
- Send confirmation email
|
|
212
|
-
|
|
213
|
-
Closes #123
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
## Documentation Requirements
|
|
217
|
-
|
|
218
|
-
Every module must have:
|
|
219
|
-
1. README.md with module purpose
|
|
220
|
-
2. Context document in memory/30-domains/
|
|
221
|
-
3. API documentation (Swagger/OpenAPI)
|
|
222
|
-
4. Example curl requests
|
|
223
|
-
5. Error codes and meanings
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
# Regras de Negócio
|
|
2
|
-
|
|
3
|
-
## 1. Subscription Plans
|
|
4
|
-
|
|
5
|
-
### Planos Padrão
|
|
6
|
-
|
|
7
|
-
| Plan | Price/mo | Users | API Calls | Storage | Support |
|
|
8
|
-
|------|----------|-------|-----------|---------|---------|
|
|
9
|
-
| **Free** | $0 | 1 | 1k/mo | 1GB | Community |
|
|
10
|
-
| **Pro** | $99 | 5 | 100k/mo | 100GB | Email |
|
|
11
|
-
| **Enterprise** | Custom | Unlimited | Unlimited | Unlimited | Dedicated |
|
|
12
|
-
|
|
13
|
-
### Regras de Transição
|
|
14
|
-
|
|
15
|
-
**Upgrade:**
|
|
16
|
-
- Free → Pro: Imediato, prorated charge
|
|
17
|
-
- Pro → Enterprise: Requer aprovação
|
|
18
|
-
- Any → Any: Sem penalty
|
|
19
|
-
|
|
20
|
-
**Downgrade:**
|
|
21
|
-
- Pro → Free: Imediato, credit note
|
|
22
|
-
- Downgrade gera refund pro-rata
|
|
23
|
-
- Cannot downgrade mid-commitment (annual plans)
|
|
24
|
-
|
|
25
|
-
**Effective Date:**
|
|
26
|
-
- Upgrade: Imediato
|
|
27
|
-
- Downgrade: Fim da billing cycle
|
|
28
|
-
- Já-paid: Pro-rata adjustment
|
|
29
|
-
|
|
30
|
-
### Limits & Quotas
|
|
31
|
-
|
|
32
|
-
- Free: 1k API calls/mo (soft), 1GB storage (hard)
|
|
33
|
-
- Pro: 100k API calls/mo (soft), 100GB storage (hard)
|
|
34
|
-
- Enterprise: Unlimited
|
|
35
|
-
- Rate limiting: 100 req/sec per tenant
|
|
36
|
-
|
|
37
|
-
**What happens at limit?**
|
|
38
|
-
- Soft limit: Warning email, continue working
|
|
39
|
-
- Hard limit: 429 Too Many Requests, suggest upgrade
|
|
40
|
-
|
|
41
|
-
---
|
|
42
|
-
|
|
43
|
-
## 2. Billing
|
|
44
|
-
|
|
45
|
-
### Invoice Schedule
|
|
46
|
-
|
|
47
|
-
- Monthly subscription: Charge first day of month
|
|
48
|
-
- Annual subscription: Charge on anniversary
|
|
49
|
-
- Pro-rata charges: Immediate
|
|
50
|
-
- Failed charge: Retry 3x over 14 days, then cancel
|
|
51
|
-
|
|
52
|
-
### Payment Terms
|
|
53
|
-
|
|
54
|
-
- Credit card: Charge immediately
|
|
55
|
-
- Annual discount: 20% (e.g., Pro $1188/year = $99/mo)
|
|
56
|
-
- No long-term contracts (SaaS, not enterprise software)
|
|
57
|
-
- Money-back guarantee: 14 days
|
|
58
|
-
|
|
59
|
-
### Refund Policy
|
|
60
|
-
|
|
61
|
-
- Within 14 days: Full refund
|
|
62
|
-
- After 14 days: Pro-rata refund (unused balance)
|
|
63
|
-
- Chargeback: Suspend account immediately
|
|
64
|
-
- Refund issued within 5-7 business days
|
|
65
|
-
|
|
66
|
-
### Tax
|
|
67
|
-
|
|
68
|
-
- US: Sales tax calculated by state (Stripe does this)
|
|
69
|
-
- EU: VAT applied, reverse charge for B2B
|
|
70
|
-
- Exempt: Non-profits (certificate required)
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## 3. Users & Roles
|
|
75
|
-
|
|
76
|
-
### RBAC Matrix
|
|
77
|
-
|
|
78
|
-
| Action | Owner | Admin | Member |
|
|
79
|
-
|--------|-------|-------|--------|
|
|
80
|
-
| Create org | ✅ | ❌ | ❌ |
|
|
81
|
-
| Delete org | ✅ | ❌ | ❌ |
|
|
82
|
-
| Change plan | ✅ | ❌ | ❌ |
|
|
83
|
-
| Invite user | ✅ | ✅ | ❌ |
|
|
84
|
-
| Remove user | ✅ | ✅ | ❌ |
|
|
85
|
-
| Change role | ✅ | ❌ | ❌ |
|
|
86
|
-
| View billing | ✅ | ✅ | ❌ |
|
|
87
|
-
| Use API | ✅ | ✅ | ✅ |
|
|
88
|
-
|
|
89
|
-
### User Lifecycle
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
Invite → Pending → Accepted → Active → Removed/Suspended
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
**Rules:**
|
|
96
|
-
- Owner is permanent, cannot be removed
|
|
97
|
-
- Min 1 owner per org, max 3 (governance)
|
|
98
|
-
- Invitation expires in 7 days
|
|
99
|
-
- Removed user: Access revoked immediately, no refund
|
|
100
|
-
- Suspended user: Access disabled, but data retained
|
|
101
|
-
|
|
102
|
-
### Seat Usage
|
|
103
|
-
|
|
104
|
-
- Free: 1 user
|
|
105
|
-
- Pro: 5 seats included, $10 per additional
|
|
106
|
-
- Enterprise: Unlimited
|
|
107
|
-
|
|
108
|
-
**Calculation:**
|
|
109
|
-
```
|
|
110
|
-
Monthly bill = Subscription + (Overage seats × $10)
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
---
|
|
114
|
-
|
|
115
|
-
## 4. Multi-Tenancy
|
|
116
|
-
|
|
117
|
-
### Organization Isolation
|
|
118
|
-
|
|
119
|
-
Every request must include:
|
|
120
|
-
- `Authorization: Bearer {jwt}`
|
|
121
|
-
- JWT contains `tenantId`
|
|
122
|
-
- Query filters by `tenantId` automatically
|
|
123
|
-
- Cross-tenant queries: FORBIDDEN
|
|
124
|
-
|
|
125
|
-
### Tenant Context Rules
|
|
126
|
-
|
|
127
|
-
1. **Mandatory**: Every endpoint must validate tenant
|
|
128
|
-
2. **Implicit**: Service methods receive tenantId via middleware
|
|
129
|
-
3. **Defensive**: Never trust client-provided tenantId
|
|
130
|
-
4. **Logged**: All tenant access in audit log
|
|
131
|
-
|
|
132
|
-
### Data Segregation
|
|
133
|
-
|
|
134
|
-
- Separate database per tenant: NO (security/ops complexity)
|
|
135
|
-
- Row-level security: YES (tenant_id on every table)
|
|
136
|
-
- Index on tenant_id: MANDATORY
|
|
137
|
-
- Soft-deletes: YES (audit + recovery)
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
## 5. Security
|
|
142
|
-
|
|
143
|
-
### Password Rules
|
|
144
|
-
|
|
145
|
-
- Minimum 12 characters
|
|
146
|
-
- At least: uppercase + lowercase + number + symbol
|
|
147
|
-
- Cannot contain username or email
|
|
148
|
-
- Expire: Never (stateless auth)
|
|
149
|
-
- History: Not enforced (JWT, not sessions)
|
|
150
|
-
|
|
151
|
-
### JWT Strategy
|
|
152
|
-
|
|
153
|
-
- Algorithm: HS256
|
|
154
|
-
- Access token: 15 min expiry
|
|
155
|
-
- Refresh token: 7 days expiry
|
|
156
|
-
- Signing secret: From env, rotated quarterly
|
|
157
|
-
- No sensitive data in payload (only id, tenantId, roles)
|
|
158
|
-
|
|
159
|
-
### Session Handling
|
|
160
|
-
|
|
161
|
-
- Stateless (no session store)
|
|
162
|
-
- Token blacklisting on logout: Cache in Redis, TTL 7 days
|
|
163
|
-
- Concurrent sessions: Unlimited per user
|
|
164
|
-
- Device limit: Not enforced (SaaS, not mobile app)
|
|
165
|
-
|
|
166
|
-
### IP Whitelisting
|
|
167
|
-
|
|
168
|
-
- Enterprise only
|
|
169
|
-
- Configure in org settings
|
|
170
|
-
- Bypass: Fail-open (if misconfigured, not fail-closed)
|
|
171
|
-
|
|
172
|
-
---
|
|
173
|
-
|
|
174
|
-
## 6. Compliance & Data Protection
|
|
175
|
-
|
|
176
|
-
### GDPR
|
|
177
|
-
|
|
178
|
-
- Right to access: Export user data in 24h
|
|
179
|
-
- Right to delete: Hard-delete after 30 day retention
|
|
180
|
-
- Right to portability: JSON export of all data
|
|
181
|
-
- Consent: Recorded at signup, audit logged
|
|
182
|
-
- DPA required: For EU customers
|
|
183
|
-
|
|
184
|
-
### Data Retention
|
|
185
|
-
|
|
186
|
-
- Active org: Keep indefinitely
|
|
187
|
-
- Deleted org: Soft-delete, purge after 1 year
|
|
188
|
-
- Logs: 90 days (audit), 7 days (debug)
|
|
189
|
-
- Backups: 30 day retention
|
|
190
|
-
|
|
191
|
-
### PII Handling
|
|
192
|
-
|
|
193
|
-
- Never log passwords, API keys, tokens
|
|
194
|
-
- Redact in error messages (e.g., "invalid ***")
|
|
195
|
-
- Encrypt at rest: Not mandatory (assume secure infrastructure)
|
|
196
|
-
- Encrypt in transit: TLS 1.3, mandatory
|
|
197
|
-
- No personal data in CDN
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## 7. Cancellation & Churn Prevention
|
|
202
|
-
|
|
203
|
-
### Cancellation Policy
|
|
204
|
-
|
|
205
|
-
- Self-service: Cancel anytime, effective end of billing cycle
|
|
206
|
-
- Data: Accessible for 30 days, then deleted
|
|
207
|
-
- Reactivation: Can reactivate within 30 days (restore data)
|
|
208
|
-
- Appeal: No manual intervention
|
|
209
|
-
|
|
210
|
-
### Churn Prevention
|
|
211
|
-
|
|
212
|
-
- 7 days before expiry: Reminder email
|
|
213
|
-
- Failed payment: Retry 3x, then notification
|
|
214
|
-
- Downgrade trigger: Send "Why?" survey
|
|
215
|
-
- Win-back: No special offers (preserve pricing integrity)
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## 8. Terms & Policies
|
|
220
|
-
|
|
221
|
-
### Service Level Agreement (SLA)
|
|
222
|
-
|
|
223
|
-
- Uptime: 99.9% (monitoring by Pingdom)
|
|
224
|
-
- Support: Max 24h response time (Pro tier)
|
|
225
|
-
- Incident: Public status page
|
|
226
|
-
- Breach: Service credit 10% of monthly fee
|
|
227
|
-
|
|
228
|
-
### Acceptable Use Policy
|
|
229
|
-
|
|
230
|
-
- Prohibited: Spam, malware, illegal content, scraping
|
|
231
|
-
- Enforcement: Suspension without notice
|
|
232
|
-
- Appeal: Customer support, 48h review period
|
|
233
|
-
- Serious breach: Permanent termination
|
|
234
|
-
|
|
235
|
-
### Change Management
|
|
236
|
-
|
|
237
|
-
- Price changes: 30 days notice
|
|
238
|
-
- Feature deprecation: 6 months notice
|
|
239
|
-
- Service terms: 30 days notice
|
|
240
|
-
- Backwards compatibility: Guaranteed for API v1
|
|
@@ -1,239 +0,0 @@
|
|
|
1
|
-
# NFRs - Non-Functional Requirements
|
|
2
|
-
|
|
3
|
-
## 1. Performance
|
|
4
|
-
|
|
5
|
-
### Response Times (p99)
|
|
6
|
-
|
|
7
|
-
| Endpoint | Target |
|
|
8
|
-
|----------|--------|
|
|
9
|
-
| /api/auth/login | < 200ms |
|
|
10
|
-
| /api/subscriptions | < 150ms |
|
|
11
|
-
| /api/billing | < 300ms |
|
|
12
|
-
| /api/users | < 100ms |
|
|
13
|
-
| Health check | < 50ms |
|
|
14
|
-
|
|
15
|
-
### Database Query Performance
|
|
16
|
-
|
|
17
|
-
- Simple queries: < 50ms
|
|
18
|
-
- Complex queries (joins): < 200ms
|
|
19
|
-
- Aggregations: < 1s
|
|
20
|
-
- Indexes: On every foreign key + filtering column
|
|
21
|
-
|
|
22
|
-
### Throughput
|
|
23
|
-
|
|
24
|
-
- 1000 concurrent users: No degradation
|
|
25
|
-
- 10k requests/min: No errors
|
|
26
|
-
- Database connections: Pool of 20 (adjust per load test)
|
|
27
|
-
- Cache hit rate: > 80% for subscription data
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
## 2. Scalability
|
|
32
|
-
|
|
33
|
-
### Horizontal Scaling
|
|
34
|
-
|
|
35
|
-
- Stateless API: Deploy multiple instances
|
|
36
|
-
- Load balancer: Round-robin or sticky sessions
|
|
37
|
-
- Cache layer: Redis for session/subscription data
|
|
38
|
-
- Database: Single PostgreSQL, upgrade to RDS eventually
|
|
39
|
-
|
|
40
|
-
### Database Scaling Strategy
|
|
41
|
-
|
|
42
|
-
**Phase 1** (0-100k users): Single PostgreSQL instance
|
|
43
|
-
**Phase 2** (100k-1M users): RDS Multi-AZ + read replicas
|
|
44
|
-
**Phase 3** (1M+ users): Sharding by tenant_id
|
|
45
|
-
|
|
46
|
-
### Vertical Scaling Limits
|
|
47
|
-
|
|
48
|
-
- Memory: Start with 2GB, monitor
|
|
49
|
-
- CPU: Start with 2 cores, scale to 8
|
|
50
|
-
- Disk: Start with 100GB, add SSD
|
|
51
|
-
|
|
52
|
-
---
|
|
53
|
-
|
|
54
|
-
## 3. Reliability & Availability
|
|
55
|
-
|
|
56
|
-
### Uptime Target
|
|
57
|
-
|
|
58
|
-
- Production: 99.9% SLA (43 min downtime/month)
|
|
59
|
-
- Staging: 95% (no SLA)
|
|
60
|
-
- Development: No guarantee
|
|
61
|
-
|
|
62
|
-
### Fault Tolerance
|
|
63
|
-
|
|
64
|
-
- Database failure: Immediate alert, manual failover
|
|
65
|
-
- API failure: Health check detects in 30s, auto-restart
|
|
66
|
-
- Payment gateway failure: Retry logic + fallback to mock
|
|
67
|
-
- Cache failure: Graceful degradation, no cache needed
|
|
68
|
-
|
|
69
|
-
### Error Recovery
|
|
70
|
-
|
|
71
|
-
- Transient errors (500): Retry 3x with exponential backoff
|
|
72
|
-
- Permanent errors (400): Fail immediately, log for debugging
|
|
73
|
-
- Timeout: 30s default, 60s for webhooks
|
|
74
|
-
|
|
75
|
-
### Data Durability
|
|
76
|
-
|
|
77
|
-
- Database backups: Daily, retained 30 days
|
|
78
|
-
- WAL archiving: Enabled
|
|
79
|
-
- Recovery: Restore to 24h ago in <30min
|
|
80
|
-
- RPO (Recovery Point Objective): 1 day
|
|
81
|
-
- RTO (Recovery Time Objective): 30 minutes
|
|
82
|
-
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
## 4. Security
|
|
86
|
-
|
|
87
|
-
### Threat Vectors & Mitigations
|
|
88
|
-
|
|
89
|
-
| Threat | Mitigation | Implemented |
|
|
90
|
-
|--------|-----------|-----------|
|
|
91
|
-
| SQL Injection | Parameterized queries (Typeorm ORM) | ✅ |
|
|
92
|
-
| XSS | CSP headers, input validation | 🚧 |
|
|
93
|
-
| CSRF | JWT (stateless), no session cookies | ✅ |
|
|
94
|
-
| Brute force | Rate limiting 100 req/sec | 🚧 |
|
|
95
|
-
| Man-in-the-middle | TLS 1.3, HSTS | 🚧 |
|
|
96
|
-
| Privilege escalation | RBAC, JWT validation | ✅ |
|
|
97
|
-
| Data breach | Encryption in transit, PII redaction | ✅ |
|
|
98
|
-
| Denial of service | Rate limiting, query timeouts | 🚧 |
|
|
99
|
-
|
|
100
|
-
### Cryptography
|
|
101
|
-
|
|
102
|
-
- Password hashing: bcrypt, cost=12
|
|
103
|
-
- JWT signing: HS256, secret from env
|
|
104
|
-
- Token rotation: No (JWT is stateless)
|
|
105
|
-
- API keys: SHA-256 hash in database
|
|
106
|
-
- Secrets in env: Never in code or git
|
|
107
|
-
|
|
108
|
-
### Authentication & Authorization
|
|
109
|
-
|
|
110
|
-
- Multi-factor auth: Not in MVP (hook for future)
|
|
111
|
-
- Session timeout: 15 min (access token)
|
|
112
|
-
- Password reset: Email link, 24h expiry
|
|
113
|
-
- Account lockout: After 5 failed attempts (15 min)
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## 5. Maintainability
|
|
118
|
-
|
|
119
|
-
### Code Quality
|
|
120
|
-
|
|
121
|
-
- Language: TypeScript strict mode (no `any`)
|
|
122
|
-
- Linting: ESLint + Prettier, enforced in CI
|
|
123
|
-
- Testing: Unit (50%+), E2E (30%+), Coverage >60%
|
|
124
|
-
- Code reviews: Every PR requires 1 approval
|
|
125
|
-
- Documentation: JSDoc on public methods
|
|
126
|
-
|
|
127
|
-
### Deployment
|
|
128
|
-
|
|
129
|
-
- CI/CD: GitHub Actions
|
|
130
|
-
- Deployment: Blue-green or canary
|
|
131
|
-
- Rollback: Automatic on health check failure
|
|
132
|
-
- Configuration: 12-factor app (env vars only)
|
|
133
|
-
|
|
134
|
-
### Observability
|
|
135
|
-
|
|
136
|
-
- Logging: JSON, structured logging with levels
|
|
137
|
-
- Metrics: Prometheus scrape endpoint
|
|
138
|
-
- Tracing: OpenTelemetry hooks (not mandatory)
|
|
139
|
-
- Monitoring: Alert on >1% error rate
|
|
140
|
-
|
|
141
|
-
### Version Control
|
|
142
|
-
|
|
143
|
-
- Git flow: main (prod) ← staging ← feature branches
|
|
144
|
-
- Commit messages: Conventional commits
|
|
145
|
-
- Tags: Semantic versioning (v1.0.0)
|
|
146
|
-
- Release notes: Changelog per version
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
## 6. Compliance
|
|
151
|
-
|
|
152
|
-
### Regulatory
|
|
153
|
-
|
|
154
|
-
- GDPR: Compliant (data export, deletion, consent)
|
|
155
|
-
- CCPA: Compliant (opt-out, data requests)
|
|
156
|
-
- SOC2 Type I: Audit trail, access controls
|
|
157
|
-
- HIPAA: Not required for MVP
|
|
158
|
-
|
|
159
|
-
### Data Protection
|
|
160
|
-
|
|
161
|
-
- Data at rest: Application-level encryption (not DB encryption)
|
|
162
|
-
- Data in transit: TLS 1.3 mandatory
|
|
163
|
-
- PII classification: Email, password, name
|
|
164
|
-
- Retention: 90 days for logs, 1 year for deleted orgs
|
|
165
|
-
|
|
166
|
-
### Audit & Logging
|
|
167
|
-
|
|
168
|
-
- User actions: Logged (create, update, delete)
|
|
169
|
-
- Admin actions: Logged with timestamp + user
|
|
170
|
-
- Failed auth: Logged but rate-limited (prevent log spam)
|
|
171
|
-
- Access patterns: No personal data, just metrics
|
|
172
|
-
|
|
173
|
-
---
|
|
174
|
-
|
|
175
|
-
## 7. Usability
|
|
176
|
-
|
|
177
|
-
### Developer Experience
|
|
178
|
-
|
|
179
|
-
- Setup time: < 10 minutes
|
|
180
|
-
- Deploy time: < 5 minutes
|
|
181
|
-
- Learning curve: Existing NestJS developers +1 day
|
|
182
|
-
- Error messages: Clear, actionable, no stack traces in production
|
|
183
|
-
|
|
184
|
-
### API Usability
|
|
185
|
-
|
|
186
|
-
- Consistency: RESTful with HTTP verbs
|
|
187
|
-
- Discoverability: Swagger/OpenAPI docs
|
|
188
|
-
- Error handling: Standard HTTP status codes + error codes
|
|
189
|
-
- Pagination: Limit + offset, max 100 items
|
|
190
|
-
- Filtering: Query params, escapable
|
|
191
|
-
|
|
192
|
-
### Documentation
|
|
193
|
-
|
|
194
|
-
- README: Quick start, examples, architecture
|
|
195
|
-
- API docs: Swagger endpoint at /api/docs
|
|
196
|
-
- Patterns: memory/00-global/patterns.md
|
|
197
|
-
- Examples: Postman collection provided
|
|
198
|
-
|
|
199
|
-
---
|
|
200
|
-
|
|
201
|
-
## 8. Cost Optimization
|
|
202
|
-
|
|
203
|
-
### Infrastructure
|
|
204
|
-
|
|
205
|
-
- Database: PostgreSQL (cheaper than DynamoDB)
|
|
206
|
-
- Cache: Redis (cheaper than ElastiCache for small scale)
|
|
207
|
-
- CDN: Not needed (API only)
|
|
208
|
-
- Monitoring: Open-source tools (Prometheus, Grafana)
|
|
209
|
-
|
|
210
|
-
### Development
|
|
211
|
-
|
|
212
|
-
- No vendor lock-in (can migrate to AWS/GCP/Azure)
|
|
213
|
-
- OSS stack: NestJS, Typeorm, Jest (no expensive licenses)
|
|
214
|
-
- Cost tracking: Budget alerts in cloud provider
|
|
215
|
-
|
|
216
|
-
---
|
|
217
|
-
|
|
218
|
-
## 9. Cross-Cutting Concerns
|
|
219
|
-
|
|
220
|
-
### Monitoring & Alerting
|
|
221
|
-
|
|
222
|
-
- CPU > 80%: Scale up
|
|
223
|
-
- Memory > 85%: Investigate leak
|
|
224
|
-
- Error rate > 1%: Page on-call
|
|
225
|
-
- Database connections > 18/20: Page on-call
|
|
226
|
-
- Response time p99 > 1s: Investigate
|
|
227
|
-
|
|
228
|
-
### Incident Response
|
|
229
|
-
|
|
230
|
-
- Severity 1 (total outage): 15 min response
|
|
231
|
-
- Severity 2 (partial outage): 1 hour response
|
|
232
|
-
- Severity 3 (degradation): 4 hours response
|
|
233
|
-
- Severity 4 (minor issue): Next business day
|
|
234
|
-
|
|
235
|
-
### SLA Remedies
|
|
236
|
-
|
|
237
|
-
- 99.5-99.9%: 10% credit
|
|
238
|
-
- 99-99.5%: 25% credit
|
|
239
|
-
- <99%: 50% credit (or full refund)
|