forjajs 5.0.0 → 5.1.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 +68 -2
- package/README.md +4 -2
- package/README.pt-BR.md +4 -1
- 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/bin/create-memory-nest-kit.js +0 -0
- package/dist/bin/forja.js +0 -0
- package/dist/bin/init-project.js +1 -0
- package/dist/lib/core/journey.js +10 -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-upgrade.d.ts +0 -4
- package/dist/lib/project-upgrade.js +19 -1
- package/dist/lib/project-wiring.d.ts +8 -0
- package/dist/lib/project-wiring.js +74 -2
- package/dist/lib/validators/structure-validator.js +0 -1
- package/dist/packages/llm/src/index.js +12 -2
- package/dist/scripts/llm-fit.js +23 -1
- package/dist/scripts/project-upgrade.js +9 -6
- package/docs/init-project.md +1 -1
- package/docs/llm-fit-loop.md +16 -0
- package/memory/90-decisions/0086-projeto-conectado-e-jornada-como-gate.md +1 -1
- 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/package.json +2 -2
- 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/templates/project/AGENTS.md +9 -0
- 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
package/boilerplates/02-saas-starter/backend/src/modules/subscriptions/subscriptions.controller.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Controller, Get, Post, Body, Param, UseGuards } from '@nestjs/common';
|
|
2
|
-
import { AuthGuard } from '@nestjs/passport';
|
|
3
|
-
import { SubscriptionsService } from './subscriptions.service';
|
|
4
|
-
import { TenantId } from '../../common/decorators/tenant.decorator';
|
|
5
|
-
|
|
6
|
-
@Controller('subscriptions')
|
|
7
|
-
@UseGuards(AuthGuard('jwt'))
|
|
8
|
-
export class SubscriptionsController {
|
|
9
|
-
constructor(private subsService: SubscriptionsService) {}
|
|
10
|
-
|
|
11
|
-
@Get()
|
|
12
|
-
async get(@TenantId() tenantId: string, @Body() req: any) {
|
|
13
|
-
const org = req.user.organization;
|
|
14
|
-
const sub = await this.subsService.getOrCreate(org.id, tenantId);
|
|
15
|
-
return { data: sub };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
@Post(':id/upgrade')
|
|
19
|
-
async upgrade(
|
|
20
|
-
@Param('id') id: string,
|
|
21
|
-
@Body() body: { newPlan: string },
|
|
22
|
-
@TenantId() tenantId: string,
|
|
23
|
-
@Body() req: any,
|
|
24
|
-
) {
|
|
25
|
-
const org = req.user.organization;
|
|
26
|
-
const upgraded = await this.subsService.upgrade(org.id, tenantId, body.newPlan);
|
|
27
|
-
return { data: upgraded };
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@Get('usage')
|
|
31
|
-
async getUsage(@TenantId() tenantId: string, @Body() req: any) {
|
|
32
|
-
const org = req.user.organization;
|
|
33
|
-
const usage = await this.subsService.getUsage(org.id, tenantId);
|
|
34
|
-
return { data: usage };
|
|
35
|
-
}
|
|
36
|
-
}
|
package/boilerplates/02-saas-starter/backend/src/modules/subscriptions/subscriptions.module.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
2
|
-
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
|
-
import { Subscription } from './entities/subscription.entity';
|
|
4
|
-
import { SubscriptionsService } from './subscriptions.service';
|
|
5
|
-
import { SubscriptionsController } from './subscriptions.controller';
|
|
6
|
-
|
|
7
|
-
@Module({
|
|
8
|
-
imports: [TypeOrmModule.forFeature([Subscription])],
|
|
9
|
-
controllers: [SubscriptionsController],
|
|
10
|
-
providers: [SubscriptionsService],
|
|
11
|
-
exports: [SubscriptionsService],
|
|
12
|
-
})
|
|
13
|
-
export class SubscriptionsModule {}
|
package/boilerplates/02-saas-starter/backend/src/modules/subscriptions/subscriptions.service.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { Injectable, BadRequestException } from '@nestjs/common';
|
|
2
|
-
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
-
import { Repository } from 'typeorm';
|
|
4
|
-
import { Subscription } from './entities/subscription.entity';
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class SubscriptionsService {
|
|
8
|
-
private readonly plans = {
|
|
9
|
-
free: { price: 0, apiCalls: 1000, storage: 1 },
|
|
10
|
-
pro: { price: 99, apiCalls: 100000, storage: 100 },
|
|
11
|
-
enterprise: { price: 0, apiCalls: -1, storage: -1 },
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
15
|
-
@InjectRepository(Subscription)
|
|
16
|
-
private subRepository: Repository<Subscription>,
|
|
17
|
-
) {}
|
|
18
|
-
|
|
19
|
-
async getOrCreate(organizationId: string, tenantId: string) {
|
|
20
|
-
let sub = await this.subRepository.findOne({
|
|
21
|
-
where: { organizationId, tenantId },
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
if (!sub) {
|
|
25
|
-
const now = new Date();
|
|
26
|
-
const nextMonth = new Date(now.getFullYear(), now.getMonth() + 1, 1);
|
|
27
|
-
|
|
28
|
-
sub = this.subRepository.create({
|
|
29
|
-
organizationId,
|
|
30
|
-
tenantId,
|
|
31
|
-
plan: 'free',
|
|
32
|
-
status: 'active',
|
|
33
|
-
currentPeriodStart: now,
|
|
34
|
-
currentPeriodEnd: nextMonth,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
await this.subRepository.save(sub);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return sub;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async upgrade(organizationId: string, tenantId: string, newPlan: string) {
|
|
44
|
-
if (!this.plans[newPlan]) {
|
|
45
|
-
throw new BadRequestException('Invalid plan');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const sub = await this.subRepository.findOne({
|
|
49
|
-
where: { organizationId, tenantId },
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
if (!sub) {
|
|
53
|
-
throw new BadRequestException('Subscription not found');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const validTransitions = {
|
|
57
|
-
free: ['pro', 'enterprise'],
|
|
58
|
-
pro: ['free', 'enterprise'],
|
|
59
|
-
enterprise: ['enterprise'],
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
if (!validTransitions[sub.plan]?.includes(newPlan)) {
|
|
63
|
-
throw new BadRequestException('Invalid plan transition');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
sub.plan = newPlan;
|
|
67
|
-
await this.subRepository.save(sub);
|
|
68
|
-
|
|
69
|
-
return sub;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async getUsage(organizationId: string, tenantId: string) {
|
|
73
|
-
const sub = await this.subRepository.findOne({
|
|
74
|
-
where: { organizationId, tenantId },
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
if (!sub) {
|
|
78
|
-
throw new BadRequestException('Subscription not found');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const planDetails = this.plans[sub.plan];
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
plan: sub.plan,
|
|
85
|
-
apiCallsLimit: planDetails.apiCalls === -1 ? 'unlimited' : planDetails.apiCalls,
|
|
86
|
-
storageLimit: planDetails.storage === -1 ? 'unlimited' : `${planDetails.storage}GB`,
|
|
87
|
-
apiCallsUsed: 0,
|
|
88
|
-
storageUsed: 0,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm';
|
|
2
|
-
|
|
3
|
-
@Entity('users')
|
|
4
|
-
@Index(['tenantId', 'email'])
|
|
5
|
-
@Index(['tenantId', 'status'])
|
|
6
|
-
export class User {
|
|
7
|
-
@PrimaryGeneratedColumn('uuid')
|
|
8
|
-
id: string;
|
|
9
|
-
|
|
10
|
-
@Column('uuid')
|
|
11
|
-
tenantId: string;
|
|
12
|
-
|
|
13
|
-
@Column()
|
|
14
|
-
email: string;
|
|
15
|
-
|
|
16
|
-
@Column()
|
|
17
|
-
passwordHash: string;
|
|
18
|
-
|
|
19
|
-
@Column({ nullable: true })
|
|
20
|
-
firstName: string;
|
|
21
|
-
|
|
22
|
-
@Column({ nullable: true })
|
|
23
|
-
lastName: string;
|
|
24
|
-
|
|
25
|
-
@Column('simple-array', { default: 'member' })
|
|
26
|
-
roles: string[];
|
|
27
|
-
|
|
28
|
-
@Column({ default: 'active' })
|
|
29
|
-
status: string;
|
|
30
|
-
|
|
31
|
-
@Column({ nullable: true })
|
|
32
|
-
emailVerifiedAt: Date;
|
|
33
|
-
|
|
34
|
-
@CreateDateColumn()
|
|
35
|
-
createdAt: Date;
|
|
36
|
-
|
|
37
|
-
@UpdateDateColumn()
|
|
38
|
-
updatedAt: Date;
|
|
39
|
-
|
|
40
|
-
@Column({ nullable: true })
|
|
41
|
-
deletedAt: Date;
|
|
42
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Controller, Get, UseGuards } from '@nestjs/common';
|
|
2
|
-
import { AuthGuard } from '@nestjs/passport';
|
|
3
|
-
import { UsersService } from './users.service';
|
|
4
|
-
|
|
5
|
-
@Controller('users')
|
|
6
|
-
@UseGuards(AuthGuard('jwt'))
|
|
7
|
-
export class UsersController {
|
|
8
|
-
constructor(private usersService: UsersService) {}
|
|
9
|
-
|
|
10
|
-
@Get()
|
|
11
|
-
async list(@Body() req: any) {
|
|
12
|
-
return { data: await this.usersService.list(req.user.tenantId) };
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Module } from '@nestjs/common';
|
|
2
|
-
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
|
-
import { User } from './entities/user.entity';
|
|
4
|
-
import { UsersService } from './users.service';
|
|
5
|
-
import { UsersController } from './users.controller';
|
|
6
|
-
|
|
7
|
-
@Module({
|
|
8
|
-
imports: [TypeOrmModule.forFeature([User])],
|
|
9
|
-
controllers: [UsersController],
|
|
10
|
-
providers: [UsersService],
|
|
11
|
-
exports: [UsersService],
|
|
12
|
-
})
|
|
13
|
-
export class UsersModule {}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
2
|
-
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
-
import { Repository } from 'typeorm';
|
|
4
|
-
import { User } from './entities/user.entity';
|
|
5
|
-
|
|
6
|
-
@Injectable()
|
|
7
|
-
export class UsersService {
|
|
8
|
-
constructor(
|
|
9
|
-
@InjectRepository(User)
|
|
10
|
-
private userRepository: Repository<User>,
|
|
11
|
-
) {}
|
|
12
|
-
|
|
13
|
-
async findById(id: string, tenantId: string) {
|
|
14
|
-
return this.userRepository.findOne({
|
|
15
|
-
where: { id, tenantId },
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async findByEmail(email: string, tenantId: string) {
|
|
20
|
-
return this.userRepository.findOne({
|
|
21
|
-
where: { email, tenantId },
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async create(tenantId: string, email: string, passwordHash: string) {
|
|
26
|
-
const user = this.userRepository.create({
|
|
27
|
-
tenantId,
|
|
28
|
-
email,
|
|
29
|
-
passwordHash,
|
|
30
|
-
roles: ['member'],
|
|
31
|
-
});
|
|
32
|
-
return this.userRepository.save(user);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async updateRoles(id: string, tenantId: string, roles: string[]) {
|
|
36
|
-
await this.userRepository.update(
|
|
37
|
-
{ id, tenantId },
|
|
38
|
-
{ roles },
|
|
39
|
-
);
|
|
40
|
-
return this.findById(id, tenantId);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async list(tenantId: string) {
|
|
44
|
-
return this.userRepository.find({
|
|
45
|
-
where: { tenantId },
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
# Contrato de Agentes
|
|
2
|
-
|
|
3
|
-
## 1. Ciclo de Vida de um Agente
|
|
4
|
-
|
|
5
|
-
### Setup
|
|
6
|
-
```
|
|
7
|
-
Agent recebe tarefa → Lê context (30-domains + 20-architecture)
|
|
8
|
-
→ Valida pré-requisitos → Inicia execução
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
**Checklist:**
|
|
12
|
-
- [ ] Contexto de domínio lido
|
|
13
|
-
- [ ] Dependências resolvidas
|
|
14
|
-
- [ ] Ambiente preparado
|
|
15
|
-
- [ ] Plano de execução documentado
|
|
16
|
-
|
|
17
|
-
### Execução
|
|
18
|
-
```
|
|
19
|
-
Implementa feature → Testa localmente → Registra progresso
|
|
20
|
-
→ Documenta handoff
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
**Invariantes:**
|
|
24
|
-
- Nunca quebrar testes existentes
|
|
25
|
-
- Sempre atualizar 60-runs/ com status
|
|
26
|
-
- Validar tenant isolation em toda operação
|
|
27
|
-
- Incluir error handling para todos os paths
|
|
28
|
-
|
|
29
|
-
### Conclusion
|
|
30
|
-
```
|
|
31
|
-
Feature completa → Run registrado em 60-runs/
|
|
32
|
-
→ Summary atualizado em 70-summaries/ → Handoff criado
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
**Deliverables:**
|
|
36
|
-
- Código funcional com testes
|
|
37
|
-
- Run document completo
|
|
38
|
-
- ADR se decisão arquitetural
|
|
39
|
-
- Next steps claros
|
|
40
|
-
|
|
41
|
-
## 2. Responsabilidades por Agente
|
|
42
|
-
|
|
43
|
-
### Setup Agent
|
|
44
|
-
**Entrada**: Nenhuma (configuração inicial)
|
|
45
|
-
**Saída**: Environment pronto, schemas criados, seed data
|
|
46
|
-
|
|
47
|
-
**Checklist:**
|
|
48
|
-
- [ ] PostgreSQL rodando (docker-compose)
|
|
49
|
-
- [ ] Migrations executadas
|
|
50
|
-
- [ ] .env configurado
|
|
51
|
-
- [ ] Redis funcional
|
|
52
|
-
- [ ] Seed data inserido
|
|
53
|
-
|
|
54
|
-
**Não faz**: Implementar features, apenas prepare infrastructure
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
### Auth Agent
|
|
59
|
-
**Entrada**: Setup Agent completo
|
|
60
|
-
**Saída**: Módulo auth com JWT, login, signup
|
|
61
|
-
|
|
62
|
-
**Responsabilidades:**
|
|
63
|
-
- Implementar JWT strategy
|
|
64
|
-
- Validar credenciais
|
|
65
|
-
- Gerenciar refresh tokens
|
|
66
|
-
- Registrar eventos de auth
|
|
67
|
-
|
|
68
|
-
**Não faz**: Gerenciar roles (vê Users Agent)
|
|
69
|
-
|
|
70
|
-
---
|
|
71
|
-
|
|
72
|
-
### Subscriptions Agent
|
|
73
|
-
**Entrada**: Auth Agent + Users Agent
|
|
74
|
-
**Saída**: Gerenciamento de planos e upgrades
|
|
75
|
-
|
|
76
|
-
**Responsabilidades:**
|
|
77
|
-
- Crud de subscriptions
|
|
78
|
-
- Validar transições de plano
|
|
79
|
-
- Registrar eventos de negócio
|
|
80
|
-
- Integrar com billing
|
|
81
|
-
|
|
82
|
-
**Não faz**: Processar pagamentos (vê Billing Agent)
|
|
83
|
-
|
|
84
|
-
---
|
|
85
|
-
|
|
86
|
-
### Billing Agent
|
|
87
|
-
**Entrada**: Subscriptions Agent
|
|
88
|
-
**Saída**: Mock payment gateway, invoices
|
|
89
|
-
|
|
90
|
-
**Responsabilidades:**
|
|
91
|
-
- Processar pagamentos (mock Stripe)
|
|
92
|
-
- Gerar invoices
|
|
93
|
-
- Registrar transações
|
|
94
|
-
- Webhook handlers
|
|
95
|
-
|
|
96
|
-
**Não faz**: Validar planos (vê Subscriptions)
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
### Organizations Agent
|
|
101
|
-
**Entrada**: Setup Agent
|
|
102
|
-
**Saída**: Multi-tenant structure, org management
|
|
103
|
-
|
|
104
|
-
**Responsabilidades:**
|
|
105
|
-
- CRUD de organizations
|
|
106
|
-
- Tenant isolation validation
|
|
107
|
-
- Invite members
|
|
108
|
-
- Org settings
|
|
109
|
-
|
|
110
|
-
**Não faz**: Auth (vê Auth Agent), roles (vê Users Agent)
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
### Users Agent
|
|
115
|
-
**Entrada**: Auth Agent + Organizations Agent
|
|
116
|
-
**Saída**: User management com RBAC
|
|
117
|
-
|
|
118
|
-
**Responsabilidades:**
|
|
119
|
-
- CRUD de users
|
|
120
|
-
- Atribuir roles
|
|
121
|
-
- Gerenciar permissions
|
|
122
|
-
- Audit logging
|
|
123
|
-
|
|
124
|
-
**Não faz**: Autenticação (vê Auth Agent)
|
|
125
|
-
|
|
126
|
-
---
|
|
127
|
-
|
|
128
|
-
### Analytics Agent
|
|
129
|
-
**Entrada**: Todos agentes com eventos registrados
|
|
130
|
-
**Saída**: Métricas e insights
|
|
131
|
-
|
|
132
|
-
**Responsabilidades:**
|
|
133
|
-
- Agregar eventos
|
|
134
|
-
- Calcular churn rate
|
|
135
|
-
- MRR tracking
|
|
136
|
-
- Dashboard data
|
|
137
|
-
|
|
138
|
-
**Não faz**: Implementar eventos (cada agente registra seu próprio)
|
|
139
|
-
|
|
140
|
-
## 3. Contrato de Entrada/Saída
|
|
141
|
-
|
|
142
|
-
Cada agente declara:
|
|
143
|
-
|
|
144
|
-
```markdown
|
|
145
|
-
## Agent: Subscriptions Agent
|
|
146
|
-
|
|
147
|
-
### Entrada Obrigatória
|
|
148
|
-
- [ ] Auth Agent concluído
|
|
149
|
-
- [ ] Users Agent concluído
|
|
150
|
-
- [ ] PostgreSQL + Redis rodando
|
|
151
|
-
- [ ] Environment: memory/30-domains/subscriptions/context.md
|
|
152
|
-
|
|
153
|
-
### Saída Entregue
|
|
154
|
-
- [ ] POST /api/subscriptions (create)
|
|
155
|
-
- [ ] GET /api/subscriptions/:id (read)
|
|
156
|
-
- [ ] PUT /api/subscriptions/:id (update plan)
|
|
157
|
-
- [ ] Testes E2E passando
|
|
158
|
-
- [ ] Run document em 60-runs/
|
|
159
|
-
|
|
160
|
-
### Erro = Bloqueador
|
|
161
|
-
Se alguma entrada não estiver pronta, registrar em:
|
|
162
|
-
- memory/40-delivery/backlog.md (como bloqueador)
|
|
163
|
-
- Não prosseguir (avoid broken dependencies)
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
## 4. Handoff Protocol
|
|
167
|
-
|
|
168
|
-
Quando agente completa, cria `50-orchestration/handoffs/{timestamp}-{agent}-{next-agent}.md`:
|
|
169
|
-
|
|
170
|
-
```markdown
|
|
171
|
-
# Handoff: Auth Agent → Subscriptions Agent
|
|
172
|
-
**Timestamp**: 2024-01-15 14:30:00
|
|
173
|
-
**Status**: ✅ Ready
|
|
174
|
-
|
|
175
|
-
## O que foi entregue
|
|
176
|
-
- ✅ JWT auth funcional
|
|
177
|
-
- ✅ Login/signup endpoints
|
|
178
|
-
- ✅ User entity com roles
|
|
179
|
-
- ✅ All E2E tests passing
|
|
180
|
-
|
|
181
|
-
## Estado atual do código
|
|
182
|
-
- Branch: feature/auth
|
|
183
|
-
- Tests: 42 passing, 0 failing
|
|
184
|
-
- Coverage: 89%
|
|
185
|
-
|
|
186
|
-
## Dependências resolvidas
|
|
187
|
-
- [ ] JWT config (✅ done)
|
|
188
|
-
- [ ] User schema (✅ done)
|
|
189
|
-
- [ ] Password hashing (✅ done)
|
|
190
|
-
|
|
191
|
-
## Próximo agente deve
|
|
192
|
-
1. Cherry-pick User entity changes
|
|
193
|
-
2. Implementar subscription CRUD
|
|
194
|
-
3. Testar isolamento de tenant
|
|
195
|
-
4. Criar handoff para Billing Agent
|
|
196
|
-
|
|
197
|
-
## Issues conhecidas
|
|
198
|
-
- None
|
|
199
|
-
|
|
200
|
-
## Prioridade
|
|
201
|
-
🔴 Critical | 🟡 High | 🟢 Medium | ⚪ Low
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
## 5. Error Recovery
|
|
205
|
-
|
|
206
|
-
**Se agente falha:**
|
|
207
|
-
1. Registrar erro em 60-runs/{timestamp}-ERROR.md
|
|
208
|
-
2. Rollback de changes (não quebra main)
|
|
209
|
-
3. Criação de ADR explicando causa
|
|
210
|
-
4. Reatribuir com contexto do erro
|
|
211
|
-
|
|
212
|
-
**Se dependência não disponível:**
|
|
213
|
-
1. Registrar em 40-delivery/backlog.md como bloqueador
|
|
214
|
-
2. Não prosseguir (falhar rápido)
|
|
215
|
-
3. Notificar responsável da dependência
|
|
216
|
-
|
|
217
|
-
## 6. Qualidade de Código
|
|
218
|
-
|
|
219
|
-
Todo agent output deve passar:
|
|
220
|
-
- [ ] TypeScript strict mode (no `any`)
|
|
221
|
-
- [ ] ESLint + Prettier
|
|
222
|
-
- [ ] Unit tests (>80% coverage)
|
|
223
|
-
- [ ] E2E tests para happy paths
|
|
224
|
-
- [ ] No breaking changes em existing APIs
|
|
225
|
-
- [ ] Documentado em memory/
|
|
226
|
-
|
|
227
|
-
**Violação = Pull request rejection**
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
# Política de Contexto & Gestão de Memória
|
|
2
|
-
|
|
3
|
-
## 1. Estrutura de Níveis
|
|
4
|
-
|
|
5
|
-
A memória está organizada em 10 níveis que crescem em especificidade:
|
|
6
|
-
|
|
7
|
-
| Nível | Escopo | Uso |
|
|
8
|
-
|-------|--------|-----|
|
|
9
|
-
| 00 | Global | Mission, patterns, policies |
|
|
10
|
-
| 10 | Product | Visão, personas, regras |
|
|
11
|
-
| 20 | Architecture | Decisões técnicas |
|
|
12
|
-
| 30 | Domains | Context por domínio de negócio |
|
|
13
|
-
| 40 | Delivery | Roadmap, sprints |
|
|
14
|
-
| 50 | Orchestration | Topologia de agents |
|
|
15
|
-
| 60 | Runs | Logs de execução |
|
|
16
|
-
| 70 | Summaries | Sínteses executivas |
|
|
17
|
-
| 80 | Data | Schemas, migrations |
|
|
18
|
-
| 90 | Decisions | ADRs (Architecture Decision Records) |
|
|
19
|
-
|
|
20
|
-
## 2. Fluxo de Leitura de Context
|
|
21
|
-
|
|
22
|
-
**Ordem de prioridade** para agente decidir ação:
|
|
23
|
-
1. Domínio específico (30-domains/X/)
|
|
24
|
-
2. Architecture decisão (20-architecture/)
|
|
25
|
-
3. Padrões globais (00-global/patterns.md)
|
|
26
|
-
4. Regras de produto (10-product/business-rules.md)
|
|
27
|
-
|
|
28
|
-
**Exemplo**: Para implementar "upgrade de subscription":
|
|
29
|
-
1. Ler `30-domains/subscriptions/context.md` (o que é upgrade aqui)
|
|
30
|
-
2. Ler `30-domains/billing/context.md` (impacto no billing)
|
|
31
|
-
3. Ler `20-architecture/backend.md` (padrão de implementação)
|
|
32
|
-
4. Aplicar padrão de service/controller de `patterns.md`
|
|
33
|
-
|
|
34
|
-
## 3. Gestão de Estado em Runs
|
|
35
|
-
|
|
36
|
-
Cada execução de agente registra:
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
60-runs/
|
|
40
|
-
├── 2024-01-15-auth-setup.md
|
|
41
|
-
├── 2024-01-15-subscription-endpoint.md
|
|
42
|
-
└── index.md (lista de todas as runs)
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
**Formato de run:**
|
|
46
|
-
```markdown
|
|
47
|
-
# Auth Setup - 2024-01-15 10:30:00
|
|
48
|
-
|
|
49
|
-
## Agente
|
|
50
|
-
Setup Agent
|
|
51
|
-
|
|
52
|
-
## Tarefa
|
|
53
|
-
Inicializar módulo de autenticação
|
|
54
|
-
|
|
55
|
-
## Output
|
|
56
|
-
- ✅ JWT config criado
|
|
57
|
-
- ✅ Local strategy implementada
|
|
58
|
-
- ✅ Login endpoint funcional
|
|
59
|
-
|
|
60
|
-
## Issues
|
|
61
|
-
- Nenhum
|
|
62
|
-
|
|
63
|
-
## Próximos passos
|
|
64
|
-
- Implementar refresh token
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## 4. Atualização de Summaries
|
|
68
|
-
|
|
69
|
-
**Global summary** (`70-summaries/global.md`):
|
|
70
|
-
- Atualizado diariamente
|
|
71
|
-
- Lista funcionalidades implementadas
|
|
72
|
-
- Identifica bloqueadores
|
|
73
|
-
|
|
74
|
-
**Domain summaries** (`70-summaries/{domain}.md`):
|
|
75
|
-
- Atualizado quando módulo completa feature
|
|
76
|
-
- Estado de cada endpoint
|
|
77
|
-
- Issues conhecidas
|
|
78
|
-
|
|
79
|
-
## 5. Versionamento de Memória
|
|
80
|
-
|
|
81
|
-
Quando política muda:
|
|
82
|
-
1. Criar ADR em `90-decisions/adr-YYYYMMDD-{titulo}.md`
|
|
83
|
-
2. Atualizar arquivo afetado com timestamp
|
|
84
|
-
3. Registrar em `90-decisions/index.md`
|
|
85
|
-
|
|
86
|
-
**Exemplo de ADR:**
|
|
87
|
-
```
|
|
88
|
-
# ADR-20240115-001: JWT expiry strategy
|
|
89
|
-
|
|
90
|
-
## Context
|
|
91
|
-
Tokens devem expirar, mas user experience deve ser suave
|
|
92
|
-
|
|
93
|
-
## Decision
|
|
94
|
-
- Access token: 15 minutos
|
|
95
|
-
- Refresh token: 7 dias
|
|
96
|
-
- Silent refresh em background
|
|
97
|
-
|
|
98
|
-
## Consequences
|
|
99
|
-
- Melhor segurança, mais chamadas à API
|
|
100
|
-
- Melhor UX com refresh automático
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## 6. Quem Atualiza Cada Seção
|
|
104
|
-
|
|
105
|
-
| Seção | Quem |
|
|
106
|
-
|-------|-----|
|
|
107
|
-
| 00-global | Tech lead, architect |
|
|
108
|
-
| 10-product | Product manager, PO |
|
|
109
|
-
| 20-architecture | Tech lead |
|
|
110
|
-
| 30-domains | Agentes de domínio |
|
|
111
|
-
| 40-delivery | Scrum master, tech lead |
|
|
112
|
-
| 50-orchestration | Tech lead, setup agent |
|
|
113
|
-
| 60-runs | Cada agente após execução |
|
|
114
|
-
| 70-summaries | Summary agent (rotina diária) |
|
|
115
|
-
| 80-data | Data agent, migrations |
|
|
116
|
-
| 90-decisions | Tech lead, architect |
|
|
117
|
-
|
|
118
|
-
## 7. Context Freshness
|
|
119
|
-
|
|
120
|
-
**Staleness rules:**
|
|
121
|
-
- Padrões (00-global): OK até 3 meses sem atualização
|
|
122
|
-
- Domain context (30-domains): AVISO se > 1 sprint
|
|
123
|
-
- Runs (60-runs): OBRIGATÓRIO após cada execução
|
|
124
|
-
- Summaries: AVISO se > 1 dia
|
|
125
|
-
- Decisions: Nunca ficam obsoletos (imutáveis)
|
|
126
|
-
|
|
127
|
-
## 8. Limpeza de Contexto
|
|
128
|
-
|
|
129
|
-
Trimestral:
|
|
130
|
-
1. Arquivar runs antigas (60-runs → 60-runs/archive/)
|
|
131
|
-
2. Consolidar learnings em 70-summaries
|
|
132
|
-
3. Atualizar ADRs obsoletos
|
|
133
|
-
4. Verificar alinhamento de 10-product com 30-domains
|
|
134
|
-
|
|
135
|
-
## 9. Conflitos de Contexto
|
|
136
|
-
|
|
137
|
-
Se dois documentos dizem coisas diferentes:
|
|
138
|
-
1. Ordem de precedência: Decisão > Domain > Architecture > Pattern
|
|
139
|
-
2. ADR mais recente vence
|
|
140
|
-
3. Registrar conflito em `90-decisions/conflicts.md`
|
|
141
|
-
4. Resolver em pair programming ou architecture review
|