Deployment — studyAI
Estratégia de deploy, ambientes, e infraestrutura.
Índice
- Ambientes
- Arquitetura de deploy
- Docker
- Variáveis de ambiente
- CI/CD
- Monitorização
- Escalabilidade
Ambientes
| Ambiente | Uso | URL |
|---|
| Local | Desenvolvimento | localhost:3000, localhost:8000 |
| Staging | Testes, preview | staging.studyai.example |
| Production | Utilizadores finais | app.studyai.example, api.studyai.example |
Arquitetura de deploy
Diagrama (produção)
A carregar diagrama…
Opções de hosting
| Componente | Opção A | Opção B |
|---|
| Frontend | Vercel | VM (Docker) |
| API | Railway, Render | VM (Docker) |
| DB | Supabase, Neon | VM (Postgres) |
| Redis | Upstash, Redis Cloud | VM (Redis) |
| Storage | R2, S3 | MinIO (self-hosted) |
| Workers | Celery + Redis | Inline (API) para MVP |
Docker
docker-compose.yml (dev)
version: '3.8'
services:
api:
build: ./api
ports: ["8000:8000"]
env_file: .env
depends_on: [db, redis]
volumes: [./api:/app]
web:
build: ./web
ports: ["3000:3000"]
env_file: .env
depends_on: [api]
volumes: [./web:/app]
db:
image: pgvector/pgvector:pg16
environment:
POSTGRES_USER: studyai
POSTGRES_PASSWORD: dev
POSTGRES_DB: studyai
ports: ["5432:5432"]
volumes: [pgdata:/var/lib/postgresql/data]
redis:
image: redis:7-alpine
ports: ["6379:6379"]
minio:
image: minio/minio
command: server /data
ports: ["9000:9000"]
volumes: [miniodata:/data]
volumes:
pgdata:
miniodata:
Dockerfile (API)
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
Dockerfile (Web)
FROM node:20-alpine
WORKDIR /app
COPY package*.json .
RUN npm ci
COPY . .
RUN npm run build
CMD ["npm", "start"]
Variáveis de ambiente
API
| Variável | Descrição | Exemplo |
|---|
| DATABASE_URL | Connection string Postgres | postgresql://user:pass@host:5432/db |
| REDIS_URL | Connection Redis | redis://localhost:6379 |
| STORAGE_ENDPOINT | S3 endpoint | http://minio:9000 (dev) |
| STORAGE_BUCKET | Bucket name | studyai-files |
| OPENAI_API_KEY | Chave OpenAI | sk-... |
| LANGCHAIN_TRACING_V2 | Ativar LangSmith | true |
| LANGCHAIN_API_KEY | API key LangSmith | lsv2_... |
| LANGCHAIN_PROJECT | Nome do projeto | studyai-dev |
| JWT_SECRET | Secret para JWT | random 32+ chars |
| CORS_ORIGINS | Origens permitidas | https://app.studyai.example |
| ENV | Ambiente | development | staging | production |
Web
CI/CD
Pipeline (exemplo: GitHub Actions)
# .github/workflows/ci.yml
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run API tests
run: |
cd api && pip install -r requirements.txt
pytest
- name: Run Web tests
run: |
cd web && npm ci
npm run build
Deploy
- Vercel: Auto-deploy do
web/ em push para main.
- API: Deploy manual ou CI que faz build + push para registry + deploy em VM/Railway.
- Migrations: Correr antes do deploy da API (
alembic upgrade head).
Monitorização
Health checks
GET /health — API está up
GET /health/db — Postgres conecta
GET /health/redis — Redis conecta
Métricas (futuro)
- Latência por endpoint
- Taxa de erro
- Uso de tokens (LLM)
- Custo por user/projeto
Alertas
- API down
- DB connection failures
- Rate limit 429 spike
- Erros 5xx
Ferramentas
- LLM tracing: LangSmith (recomendado) ou Langfuse — traces, token usage, evals
- Logs: Datadog, Axiom, ou self-hosted (Loki)
- APM: Datadog, Sentry
- Uptime: UptimeRobot, Better Uptime
Escalabilidade
Fase inicial
- 1 instância API
- 1 worker para jobs
- Postgres single instance
- Redis single instance
Crescimento
- API: Múltiplas instâncias atrás de load balancer (stateless)
- Workers: Escalar Celery workers conforme fila
- DB: Read replicas se necessário
- Vector DB: pgvector escala até ~1M chunks; depois considerar Qdrant/Pinecone
Custos
- LLM: Maior custo variável. Cache de respostas, rate limit.
- Storage: R2/S3 barato. Limitar tamanho por user.
- Compute: API e workers. Escalar sob demanda.