You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
graph LR
subgraph Frontend["Frontend (Next.js 14)"]
Pages["App Router Pages<br/>/dashboard<br/>/transfers<br/>/payments<br/>/cards<br/>/investments<br/>/loans<br/>/settings"]
Components["UI Components<br/>Charts, Forms, Tables<br/>Cards, Modals"]
Store["Zustand Store<br/>Auth, Transactions"]
API["Axios Client<br/>Interceptors"]
end
subgraph Backend["Backend (Express.js)"]
Routes["Routes<br/>Auth, Accounts<br/>Transactions, Cards<br/>Investments, Loans"]
Middleware["Middleware<br/>Auth, Rate Limit<br/>Validation, Audit<br/>Fraud Detection"]
Services["Services<br/>Business Logic<br/>Encryption, Stripe"]
Consumers["RabbitMQ Consumers<br/>Transactions<br/>Notifications<br/>Reconciliation"]
end
Pages --> Components
Pages --> Store
Store --> API
API --> Routes
Routes --> Middleware
Middleware --> Services
Services --> Consumers
style Frontend fill:#0ea5e9,color:#fff
style Backend fill:#0284c7,color:#fff
Loading
Diagrama de Implantação
graph TB
subgraph Docker["Docker Compose Environment"]
subgraph Network["fintech-network (bridge)"]
FE["frontend:3000<br/>Next.js Standalone"]
BE["backend:3001<br/>Express + Prisma"]
DB[("postgres:5432<br/>PostgreSQL 16")]
Cache[("redis:6379<br/>Redis 7")]
MQ[("rabbitmq:5672<br/>RabbitMQ 3 + UI:15672")]
end
Volumes["Docker Volumes<br/>postgres_data<br/>redis_data<br/>rabbitmq_data"]
end
User["👤 Browser"] -->|HTTP| FE
FE -->|API Calls| BE
BE -->|Prisma| DB
BE -->|ioredis| Cache
BE -->|amqplib| MQ
DB --> Volumes
Cache --> Volumes
MQ --> Volumes
style Docker fill:#1e293b,color:#fff
style Network fill:#334155,color:#fff
style User fill:#0ea5e9,color:#fff
Loading
Fluxos Principais
Fluxo de Autenticação
sequenceDiagram
participant U as Usuário
participant F as Frontend
participant B as Backend
participant DB as PostgreSQL
participant R as Redis
participant OTP as TOTP App
U->>F: Acessa /register
F->>U: Formulário multi-step
U->>F: Preenche dados
F->>B: POST /api/auth/register
B->>DB: Verifica email/CPF duplicado
alt Duplicado
B-->>F: 409 Conflict
F-->>U: Mostra erro
else Novo usuário
B->>DB: Cria User (senha hash bcrypt)
B->>DB: Cria conta corrente
B->>DB: Cria conta poupança
B-->>F: 201 Created
F-->>U: Redireciona /login
end
U->>F: Acessa /login
F->>U: Formulário email/senha
U->>F: Credenciais
F->>B: POST /api/auth/login
B->>DB: Busca usuário
B->>B: Verifica senha (bcrypt.compare)
alt 2FA habilitado
B-->>F: requires2FA: true
F->>U: Input código 6 dígitos
U->>F: Código TOTP
F->>B: POST /api/auth/2fa/verify
B->>OTP: Valida token (window: 1)
alt Código válido
B->>DB: Atualiza twoFactorEnabled
end
end
B->>B: Gera JWT (HS256)
B->>R: Cache sessão
B-->>F: 200 { token, user }
F->>F: Salva cookie + Zustand
F-->>U: Redireciona /dashboard
Loading
Fluxo de Transação
sequenceDiagram
participant U as Usuário
participant F as Frontend
participant Auth as Auth Middleware
participant Rate as Rate Limiter
participant Fraud as Fraud Detection
participant Svc as Transaction Service
participant DB as PostgreSQL
participant Cache as Redis
participant MQ as RabbitMQ
participant Consumer as Async Consumer
U->>F: Preenche formulário transferência
F->>F: Validação client-side
F->>Auth: POST /api/transactions/transfer + JWT
Auth->>Auth: Verifica token JWT
alt Token inválido
Auth-->>F: 401 Unauthorized
end
Auth->>Rate: Verifica rate limit
Rate->>Cache: incr ratelimit:{ip}
alt Excedido
Rate-->>F: 429 Too Many Requests
end
Auth->>Fraud: Fraud check
Fraud->>Cache: Verifica velocity
alt Valor > threshold
Fraud-->>F: 422 Fraud Detected
end
Fraud->>Svc: Processar transferência
Svc->>DB: Verifica saldo
alt Saldo insuficiente
Svc-->>F: 400 Insufficient funds
end
Svc->>DB: BEGIN TRANSACTION
Svc->>DB: UPDATE conta origem (decrement)
Svc->>DB: UPDATE conta destino (increment)
Svc->>DB: INSERT transaction (sender)
Svc->>DB: INSERT transaction (receiver)
Svc->>DB: COMMIT
Svc->>Cache: Invalidate balance cache
Svc->>DB: INSERT audit_log
Svc->>MQ: Publish to transactions queue
Svc->>MQ: Publish to notifications queue
Svc-->>F: 200 { transaction }
F-->>U: Confirmação + saldo atualizado
MQ->>Consumer: Process async
Consumer->>DB: Update status
Consumer->>DB: Log reconciliation
Loading
Fluxo de Investimento
sequenceDiagram
participant U as Usuário
participant F as Frontend
participant B as Backend
participant DB as PostgreSQL
participant Cache as Redis
U->>F: Acessa /investments
F->>B: GET /api/investments/products
B-->>F: Lista produtos (CDB, Tesouro, Ações)
F->>U: Exibe cards com yield/risco
U->>F: Seleciona produto + valor
F->>F: Valida valor mínimo
F->>B: POST /api/investments/apply
B->>DB: BEGIN TRANSACTION
B->>DB: Verifica saldo
B->>DB: UPDATE account (decrement)
B->>DB: INSERT investment
B->>DB: INSERT transaction (withdrawal)
B->>DB: COMMIT
B->>Cache: Invalidate balance
B-->>F: 200 { investment }
F->>U: Confirmação de aplicação
Note over U,Cache: Tempo passa...
U->>F: Solicita resgate
F->>B: POST /api/investments/redeem
B->>DB: Busca investimento
B->>B: Calcula yield (dias * taxa)
B->>DB: BEGIN TRANSACTION
B->>DB: UPDATE account (increment total)
B->>DB: UPDATE investment (redeemed)
B->>DB: INSERT transaction (deposit)
B->>DB: COMMIT
B->>Cache: Invalidate balance
B-->>F: 200 { redemption }
F->>U: Confirmação + valor recebido
Loading
Modelo de Dados
erDiagram
USER ||--o{ ACCOUNT : owns
USER ||--o{ AUDIT_LOG : generates
ACCOUNT ||--o{ TRANSACTION : has
ACCOUNT ||--o{ CARD : has
ACCOUNT ||--o{ INVESTMENT : has
ACCOUNT ||--o{ LOAN : has
ACCOUNT ||--o{ PAYMENT_SCHEDULE : has
USER {
string id PK
string email UK
string password
string name
string cpf UK
string phone
string twoFactorSecret
bool twoFactorEnabled
bool biometricEnabled
datetime createdAt
datetime updatedAt
}
ACCOUNT {
string id PK
string userId FK
string type "checking|savings"
decimal balance
string currency "BRL"
string status "active|blocked|closed"
datetime createdAt
datetime updatedAt
}
TRANSACTION {
string id PK
string accountId FK
string type "transfer|pix|payment|deposit|withdrawal"
decimal amount
string description
string status "pending|completed|failed"
string recipientAccount
string recipientName
string pixKey
string pixKeyType "cpf|email|phone|random"
datetime scheduledAt
datetime completedAt
datetime createdAt
}
CARD {
string id PK
string accountId FK
string number "encrypted"
string holderName
string expiryMonth
string expiryYear
string cvv "encrypted"
string type "virtual|physical"
string status "active|blocked|expired"
decimal limit
datetime createdAt
datetime updatedAt
}
INVESTMENT {
string id PK
string accountId FK
string type "cdb|treasury|stocks"
string productName
decimal amount
decimal yield
datetime appliedAt
datetime redeemedAt
string status "active|redeemed"
}
LOAN {
string id PK
string accountId FK
decimal amount
decimal interestRate
int term
decimal monthlyPayment
string status "pending|approved|rejected|active|paid"
datetime requestedAt
datetime approvedAt
}
AUDIT_LOG {
string id PK
string userId FK
string action
string entityType
string entityId
json details
string ipAddress
datetime createdAt
}
PAYMENT_SCHEDULE {
string id PK
string accountId FK
string payee
decimal amount
datetime dueDate
string status "active|completed|cancelled"
string recurrence "once|weekly|monthly|quarterly|yearly"
datetime createdAt
}
Rebuild com docker compose build --no-cache backend
Rate limit exceeded
Redis flush: docker compose exec redis redis-cli -a redis_pass_2024 FLUSHALL
Port already in use
Pare serviços locais ou altere portas no docker-compose.yml
Frontend não conecta ao backend
Verifique NEXT_PUBLIC_API_URL no .env.local
Logs
# Todos os logs
docker compose logs -f
# Apenas backend
docker compose logs -f backend
# Apenas frontend
docker compose logs -f frontend
# Últimas 50 linhas
docker compose logs --tail=50 backend
Reset Completo
# Para tudo e remove volumes
docker compose down -v
# Rebuild sem cache
docker compose build --no-cache
# Inicia do zero
docker compose up -d
# Aplica schema
docker compose exec backend npx prisma db push --accept-data-loss
License
MIT License - veja o arquivo LICENSE para detalhes.
Support
Para issues e feature requests, utilize GitHub Issues.
About
Complete digital banking platform built with Next.js 14, Express, PostgreSQL, Redis, and RabbitMQ.