Files
B2BCall-dialer/TODO.md
Matheus 68b403a7ff feat: add apps/api (NestJS + Fastify) with authentication endpoints
- POST /auth/login, /auth/refresh, /auth/logout, /auth/select-tenant,
  /auth/change-password, GET /auth/tenants — wired to packages/auth
- JwtAuthGuard + DomainExceptionFilter (401/403 without leaking internals)
- LoginRateLimitGuard: Redis-backed 5/min per IP and per email (agente.md
  secao 149), safe across multiple API instances
- helmet + restrictive cors (deny-by-default) + global rate limit
- GET /health, /health/live, /health/ready checking Postgres and Redis
- changePassword() added to packages/auth for the mustChangePassword flow
- fixed REDIS_HOST/POSTGRES_HOST docker-compose-only hostnames not
  resolving from the host process; added REDIS_URL for host-side use
- verified end-to-end with curl: login, wrong password / unknown email
  (same generic error), authenticated route, missing token, refresh
  rotation, logout revocation, and the 429 rate limit kicking in after 5
  attempts
2026-08-28 06:12:34 -03:00

3.2 KiB

TODO — B2BCall

PHASE 01 — Infrastructure

  • Diagnóstico do servidor (Debian 13, 2 vCPU, ~1.9GB RAM, 26GB disco livre)
  • Docker + Docker Compose instalados
  • Estrutura de monorepo criada (apps/, packages/, infrastructure/, scripts/, docs/)
  • PostgreSQL 18 (docker-compose, porta 127.0.0.1:5432)
  • Redis 7 (docker-compose, porta 127.0.0.1:6379)
  • Secrets gerados em .env (POSTGRES_PASSWORD, REDIS_PASSWORD, JWT_SECRET, JWT_REFRESH_SECRET, ENCRYPTION_KEY, ESL_PASSWORD)
  • FREESWITCH_PAT configurado em .env (não commitado)
  • FreeSWITCH (build/imagem própria, ver risco de RAM abaixo)
  • nginx (reverse proxy)

PHASE 02 — SaaS Core

  • Monorepo Node.js/TypeScript (pnpm workspaces, tsconfig base)
  • Node 22 LTS + pnpm instalados no host
  • packages/database (Prisma 7 + driver adapter pg, migration inicial)
  • packages/types (TenantStatus, AgentState), packages/shared
  • Tabela tenants criada via migration (seção 29 do agente.md)

PHASE 03 — Tenant Isolation

  • Tabelas users + tenant_memberships (tenant-scoped)
  • RLS (ENABLE/FORCE ROW LEVEL SECURITY + policy) em tenant_memberships
  • Tenant context via set_config('app.current_tenant_id', ..., true) (transaction-local)
  • Helper withTenantContext() em packages/database
  • Role de banco separado para runtime (b2bcall_app, sem SUPERUSER/BYPASSRLS) — achado crítico: o role padrão do Docker Postgres é SUPERUSER e SEMPRE ignora RLS, até com FORCE. Ver docs/TENANT_ISOLATION.md.
  • Teste automatizado de isolamento (pnpm --filter @b2bcall/database run test:isolation)

PHASE 04 — Authentication / RBAC

  • packages/auth: hash Argon2id (@node-rs/argon2), JWT access token (jose), refresh token opaco com rotation
  • Tabelas roles, permissions, role_permissions, user_roles, sessions, audit_logs
  • login() / refreshSession() / logout() / listUserTenants() / setActiveTenant()
  • userHasPermission() (RBAC com scope PLATFORM/TENANT)
  • Seed: catálogo de permissions + roles de sistema + Platform Super Admin inicial (senha em FIRST_LOGIN.txt, fora do Git, mustChangePassword=true)
  • Teste automatizado (pnpm --filter @b2bcall/auth run test:auth)
  • apps/api (NestJS + Fastify): endpoints de auth, JwtAuthGuard, DomainExceptionFilter, rate limit de login via Redis (5/min por IP e por e-mail), helmet/cors, health checks — testado ponta a ponta com curl (login, refresh rotation, logout, RBAC, 401/403/429)
  • Password reset por e-mail — depende de SMTP configurado

PHASE 05+ — ver agente.md seções 15 em diante (FreeSWITCH, Telefonia, Call Center,

Predictive Dialer, Recordings, AI, Billing, Frontend, Reports, Security, Tests)


Riscos conhecidos

  • RAM da VM (1.9GB total): insuficiente para rodar toda a stack (Postgres + Redis + FreeSWITCH + múltiplos workers Node + Next.js) simultaneamente sem swap/OOM. Avaliar upgrade de RAM antes de subir FreeSWITCH + frontend + workers juntos.
  • Disco (26GB livre): build do FreeSWITCH + imagens Docker + gravações vão consumir espaço rápido. Monitorar com df -h.