Pular para conteúdo

Setup do Ambiente

Pré-requisitos

  • .NET 8 SDK
  • Docker Desktop
  • Node.js (opcional, para ferramentas de dev)

Setup Rápido

1. Subir infraestrutura

docker-compose -f docker-compose.dev.yaml up -d

Isso inicia: - PostgreSQL 17 + pgvector na porta 5432 (com extensão vector para busca semântica) - Redis 7 na porta 6379 - Evolution API v2.3.7 na porta 8081 - Seq nas portas 5341 (ingestion) e 8082 (dashboard web) — centralizador de logs - Beszel na porta 8090 (hub + agent) — monitoramento leve de infraestrutura

2. Aplicar migrations

dotnet ef database update --project src/Ciba.Infrastructure --startup-project src/Ciba.Api --context AppDbContext

3. Executar seed (opcional)

docker exec -i ciba-postgres psql -U ciba -d ciba < infra/database/seed.sql

4. Rodar a aplicação

Em terminais separados:

# Backend (porta 5000)
dotnet run --project src/Ciba.Api

# Frontend (porta 5001)
dotnet run --project src/Ciba.Web

Ou use dotnet watch para hot reload:

dotnet watch --project src/Ciba.Api
dotnet watch --project src/Ciba.Web

Configuração

appsettings.Development.json (Api)

{
  "ConnectionStrings": {
    "PostgreSQL": "Host=localhost;Database=ciba;Username=ciba;Password=ciba123",
    "Redis": "localhost:6379"
  },
  "Jwt": {
    "Secret": "sua-chave-secreta-com-pelo-menos-32-caracteres",
    "Issuer": "ciba",
    "Audience": "ciba-users",
    "ExpirationMinutes": 60
  },
  "Llm": {
    "AnthropicApiKey": "sk-ant-...",
    "OpenAiApiKey": "sk-..."
  },
  "Evolution": {
    "BaseUrl": "http://localhost:8081",
    "ApiKey": "evolution-api-key-dev",
    "TimeoutSeconds": 10
  },
  "R2": {
    "AccountId": "...",
    "AccessKeyId": "...",
    "SecretAccessKey": "...",
    "BucketName": "ciba-dev",
    "PublicUrl": "https://cdn.exemplo.com"
  }
}

wwwroot/appsettings.json (Web)

{
  "ApiBaseUrl": "http://localhost:5000"
}

Credenciais de Desenvolvimento

Serviço Usuário Senha
PostgreSQL ciba ciba123
Evolution API - evolution-api-key-dev

Comandos Úteis

Migrations

# Criar nova migration
dotnet ef migrations add NomeDaMigration --project src/Ciba.Infrastructure --startup-project src/Ciba.Api --context AppDbContext

# Aplicar migrations
dotnet ef database update --project src/Ciba.Infrastructure --startup-project src/Ciba.Api --context AppDbContext

# Reverter última migration
dotnet ef database update PreviousMigrationName --project src/Ciba.Infrastructure --startup-project src/Ciba.Api --context AppDbContext

# Gerar script SQL
dotnet ef migrations script --project src/Ciba.Infrastructure --startup-project src/Ciba.Api --context AppDbContext

Docker

# Ver logs
docker logs ciba-postgres
docker logs ciba-redis
docker logs ciba-evolution

# Acessar PostgreSQL
docker exec -it ciba-postgres psql -U ciba -d ciba

# Acessar Redis
docker exec -it ciba-redis redis-cli

# Parar tudo
docker-compose -f docker-compose.dev.yaml down

# Parar e remover volumes
docker-compose -f docker-compose.dev.yaml down -v

Build

# Build completo
dotnet build

# Build em release
dotnet build -c Release

# Limpar
dotnet clean

Estrutura de Portas

Serviço Porta
CIBA API 5000
CIBA Web 5001
PostgreSQL 5432
Seq (Ingestion) 5341
Redis 6379
Evolution API 8081
Seq (Dashboard) 8082
Beszel (Hub) 8090

Troubleshooting

Evolution API não recebe webhooks

  1. Verifique se a API está rodando na porta 5000
  2. Confirme que host.docker.internal resolve para o host:
    docker exec ciba-evolution ping host.docker.internal
    
  3. Verifique os logs do Evolution:
    docker logs ciba-evolution
    

Erro de conexão com PostgreSQL

  1. Verifique se o container está rodando:
    docker ps | grep ciba-postgres
    
  2. Teste a conexão:
    docker exec -it ciba-postgres pg_isready -U ciba
    

Erro de conexão com Redis

  1. Verifique se o container está rodando:
    docker ps | grep ciba-redis
    
  2. Teste a conexão:
    docker exec -it ciba-redis redis-cli ping
    

Hot reload não funciona

Use dotnet watch com a flag de rebuild:

dotnet watch --project src/Ciba.Api --no-hot-reload

Blazor WASM lento no debug

Isso é normal em debug. Para performance real, use Release:

dotnet run --project src/Ciba.Web -c Release