Pular para conteúdo

Arquitetura — Chronicle

Visao Geral

graph TB
    subgraph Frontend
        FE[Next.js<br/>:3040]
    end

    subgraph Backend
        BE[Quarkus<br/>:8080]
        WS[WebSocket<br/>/ws/board]
    end

    subgraph Dados
        PG[(PostgreSQL<br/>:5436)]
        REDIS[(Redis<br/>:6379)]
    end

    subgraph Servicos Haus
        OATH[OATH<br/>:5001]
        GUILD[Guild<br/>:5002]
        HERALD[Herald<br/>:5004]
        VAULT[Vault<br/>:5006]
        SCROLLS[Scrolls<br/>:5003]
    end

    FE --> BE
    FE <--> WS
    BE --> PG
    BE --> REDIS
    BE --> OATH
    BE --> GUILD
    BE --> HERALD
    BE --> VAULT
    BE --> SCROLLS

Backend

Camadas

chronicle/
├── api/
│   ├── bff/               # BFF controllers (/bff/*)
│   ├── publicapi/         # API publica (/api/v1/* — API Keys)
│   └── websocket/         # WebSocket (/ws/board/{pipeId})
├── application/
│   └── services/          # Business logic
├── domain/
│   ├── entities/          # JPA entities
│   └── enums/
└── infrastructure/
    ├── clients/           # REST clients
    ├── security/          # Auth + API Key filters
    ├── cache/             # CacheService (Redis)
    └── broadcast/         # BoardBroadcastService

Endpoints BFF

Controller Path Funcao
BffAuthController /bff/auth Login, signup, OAuth2, OTP
BffOrganizationsController /bff/organizations CRUD orgs + membros
BffPipesController /bff CRUD pipes
BffStagesController /bff CRUD stages + reorder
BffCardsController /bff/cards CRUD cards + move + search
BffFieldsController /bff CRUD fields + reorder
BffAutomationsController /bff/automations CRUD automacoes
BffFormsController /bff CRUD formularios publicos
BffReportsController /bff/reports Estatisticas e analytics
BffDatabasesController /bff CRUD databases

Entidades Principais

erDiagram
    Organization ||--o{ Pipe : "tem"
    Organization ||--o{ OrganizationMember : "tem"
    Organization ||--o{ Database : "tem"
    Organization ||--o{ ApiKey : "tem"
    Pipe ||--o{ Stage : "tem"
    Pipe ||--o{ Field : "tem"
    Pipe ||--o{ Card : "tem"
    Pipe ||--o{ Automation : "tem"
    Pipe ||--o{ Label : "tem"
    Pipe ||--o{ PublicForm : "tem"
    Stage ||--o{ Card : "contem"
    Card ||--o{ CardData : "tem"
    Card ||--o{ CardComment : "tem"
    Card ||--o{ CardFile : "tem"
    Card ||--o{ CardEmail : "tem"
    Card ||--o{ CardDependency : "tem"
    Automation ||--o{ AutomationExecution : "registra"

Cache (Redis)

Recurso TTL Chave
Pipes 300s pipe:{id}
Stages 300s stage:{pipeId}
Cards 60s card:{id}
Organizations 600s org:{id}
Board Views 60s board:{pipeId}

Automacoes — Fluxo de Execucao

flowchart TD
    E[Evento no Card] --> F[AutomationExecutorService]
    F --> G{Buscar automacoes<br/>para trigger}
    G --> H{Avaliar condicoes}
    H -->|Match| I[Executar acao]
    H -->|No match| J[Ignorar]
    I --> K{Profundidade < 5?}
    K -->|Sim| L[Pode triggerar<br/>novas automacoes]
    K -->|Nao| M[Para execucao<br/>previne loop]
    I --> N[Registrar AutomationExecution]

Migrations

  • Flyway para migracoes automaticas
  • Diretorio: db/migrations
  • Execucao no startup da aplicacao

Frontend

Arquitetura

chronicle-frontend/
├── src/
│   ├── app/               # Next.js App Router
│   │   ├── (auth)/        # Login, signup
│   │   ├── orgs/          # Organizations + Pipes
│   │   ├── forms/         # Public forms
│   │   └── invite/        # Convites
│   ├── components/
│   │   ├── board/         # Kanban board
│   │   ├── cards/         # Card detail drawer
│   │   ├── editor/        # Pipe configuration
│   │   ├── automations/   # Automation builder
│   │   ├── forms/         # Form builder
│   │   └── databases/     # Database builder
│   ├── stores/            # Zustand
│   │   ├── authStore.ts   # Token + user
│   │   ├── boardStore.ts  # Board + cards + WebSocket
│   │   └── orgStore.ts    # Organization context
│   ├── hooks/
│   │   └── useBoardWebSocket.ts
│   ├── lib/
│   │   └── api.ts         # Axios + endpoints
│   └── types/
│       └── index.ts       # TypeScript types

WebSocket (Frontend)

O hook useBoardWebSocket gerencia a conexao em tempo real:

  • Auto-reconnect com backoff exponencial: 1s, 2s, 5s, 10s, 30s
  • Ping/pong a cada 30s (timeout 10s)
  • Eventos atualizados no boardStore automaticamente
  • Indicador de conexao visivel no board

State Management

Store Persistencia Dados
authStore localStorage (chronicle-auth) Token (apenas)
boardStore Nenhuma (session) Pipe, stages, cards, drawer
orgStore localStorage (chronicle-org) Organizacao atual

Configuracao

Backend

# Banco
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost:5436/chronicledb

# Redis
quarkus.redis.hosts=redis://localhost:6379

# Servicos
quarkus.rest-client.oath-api.url=http://localhost:5001
quarkus.rest-client.guild-api.url=http://localhost:5002
quarkus.rest-client.herald-api.url=http://localhost:5004
quarkus.rest-client.scrolls-api.url=http://localhost:5003
vault.url=http://localhost:5006

Frontend

NEXT_PUBLIC_API_URL=http://localhost:5040

Observabilidade

  • Prometheus: /q/metrics
  • Jaeger: OpenTelemetry (opcional)
  • Logs JSON: Grafana/Loki
  • Scrolls: 12+ tipos de eventos logados (card.created, card.moved, etc.)