# avakconta91-gif/8n8 architecture

> Architecture diagram of the GitHub repository avakconta91-gif/8n8, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/avakconta91-gif/8n8
- Repository: https://github.com/avakconta91-gif/8n8

## Overview

This repo is a small orchestration platform for handling incoming WhatsApp-like events, routing them into document/media processing pipelines, and persisting or summarizing results. It is not a single-purpose app; it is a set of bridges (“ponte-*”) plus queues and processors around a central dispatcher.

1. Core runtime
- The main runtime is Node.js.
- `server.js`, `app.js`, and `router.js` suggest an HTTP service with route-based entry points.
- `env` indicates runtime configuration is externalized rather than hardcoded.

2. Event intake and dispatch
- `dispatcher.js` appears to be the central coordination layer.
- It likely receives inbound events from the server/router and decides whether to send them to media, document, OCR, audio, or AI processing.
- `evolution.js` suggests integration with an external messaging/event provider, probably the source of incoming chat events.

3. Queue-based processing
- `documentQueue.js` and `mediaQueue.js` indicate asynchronous work queues for different payload types.
- This is an important architectural boundary: intake is separated from heavy processing so the system can continue accepting events while work is processed in the background.
- Queues likely protect the system from bursts of media or document uploads.

4. Document pipeline
- `processDocument.js` is the document-specific processing stage.
- `ponte-documento.js` likely acts as the adapter for extracting or normalizing document inputs before processing.
- The presence of `por.traineddata` strongly suggests OCR for Portuguese text recognition.

5. OCR boundary
- `ocr.py` is a separate Python component, likely used because OCR tooling is easier or more reliable in Python.
- This creates a cross-runtime boundary: Node.js orchestrates the workflow, while Python performs OCR extraction.
- `ponte-ocr.js` likely bridges the Node side to the Python OCR process.

6. Media and audio handling
- `media-downloader.js` suggests fetching attachments or remote media into local processing.
- `ponte-audio.js` and `ponte-whatsapp.js` indicate adapter layers for audio-related events and WhatsApp integration.
- This implies the system handles more than text: audio inputs are probably downloaded, normalized, and then passed into downstream analysis.

7. AI / language integration
- `groq.js` and `ponte-ia.js` point to an AI inference layer, likely using Groq as the model provider.
- This is probably where extracted text, OCR output, or transcript content is summarized, classified, or transformed.
- `resumo.html` reinforces that summarization is an important output path.

8. Persistence and external services
- `supabase.js` indicates Supabase is used as the backend data store or metadata store.
- The architecture likely persists job status, extracted content, or conversation/document records there.
- This creates a clear separation between transient queue/workflow state and durable application data.

9. Presentation layer
- `index.html` and `resumo.html` are static UI entry points.
- They likely expose operational views, summaries, or a lightweight dashboard rather than a full SPA.
- The UI seems secondary to the processing pipeline, not the core of the system.

10. Main data flow
- Incoming message/media event enters through the server/router.
- Dispatcher classifies the payload and hands it to the appropriate queue.
- Media/document content is downloaded or normalized.
- OCR/audio/AI bridges perform extraction or generation.
- Results are stored in Supabase and may be surfaced in the HTML views or sent back through the messaging bridge.

11. Important boundaries for a diagram
- Node.js orchestration vs Python OCR execution is a major boundary.
- Synchronous request handling vs queued background processing is another major boundary.
- External integrations are likely: WhatsApp/evolution-style messaging, Groq AI, and Supabase storage.

12. What to emphasize in the architecture diagram
- A central dispatcher with specialized adapters around it.
- Separate pipelines for document, media, OCR, audio, and AI work.
- Durable storage in Supabase.
- Static browser-facing pages as a small presentation surface.
- Environment-driven configuration and an OCR-trained data file as supporting infrastructure.

Main entry points: [`ponte.js`](https://github.com/avakconta91-gif/8n8/blob/main/ponte.js) (Bridge core), [`ponte-ia.js`](https://github.com/avakconta91-gif/8n8/blob/main/ponte-ia.js) (AI bridge), [`app.js`](https://github.com/avakconta91-gif/8n8/blob/main/app.js) (App), [`processDocument.js`](https://github.com/avakconta91-gif/8n8/blob/main/processDocument.js) (Document proc)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Node.js runtime"]
  node_server["Server<br/>HTTP entrypoint<br/>[server.js]"]
  node_app["App<br/>service setup<br/>[app.js]"]
  node_router["Router<br/>route dispatch<br/>[router.js]"]
  node_env["Env<br/>configuration"]
  node_dispatcher{{"Dispatcher<br/>event coordinator<br/>[dispatcher.js]"}}
end

subgraph group_pipelines["Processing pipelines"]
  node_document_queue["Doc queue<br/>work queue<br/>[documentQueue.js]"]
  node_media_queue["Media queue<br/>work queue<br/>[mediaQueue.js]"]
  node_ponte_documento["Doc bridge<br/>adapter<br/>[ponte-documento.js]"]
  node_process_document["Document proc<br/>pipeline stage<br/>[processDocument.js]"]
  node_media_downloader["Media downloader<br/>fetch stage"]
  node_ponte_ocr["OCR bridge<br/>cross-runtime adapter<br/>[ponte-ocr.js]"]
  node_ocr_py["OCR engine<br/>python worker<br/>[ocr.py]"]
  node_ponte_audio["Audio bridge<br/>adapter<br/>[ponte-audio.js]"]
  node_ponte_ia["AI bridge<br/>adapter<br/>[ponte-ia.js]"]
  node_traineddata["OCR data<br/>language data<br/>[por.traineddata]"]
end

subgraph group_integrations["External services"]
  node_evolution["Evolution<br/>event bridge<br/>[evolution.js]"]
  node_ponte_whatsapp["WhatsApp bridge<br/>adapter<br/>[ponte-whatsapp.js]"]
  node_ponte["Bridge core<br/>adapter core<br/>[ponte.js]"]
  node_groq["Groq<br/>AI provider<br/>[groq.js]"]
  node_supabase[("Supabase<br/>data store<br/>[supabase.js]")]
end

subgraph group_ui["Presentation"]
  node_index_html["Home UI<br/>static page<br/>[index.html]"]
  node_resumo_html["Summary UI<br/>static page<br/>[resumo.html]"]
end

node_server -->|"bootstraps"| node_app
node_app -->|"routes"| node_router
node_app -->|"wires"| node_dispatcher
node_app -->|"reads"| node_env
node_router -->|"ingests"| node_evolution
node_evolution -->|"adapts"| node_ponte_whatsapp
node_ponte_whatsapp -->|"dispatches"| node_dispatcher
node_dispatcher -->|"enqueues"| node_document_queue
node_dispatcher -->|"enqueues"| node_media_queue
node_document_queue -->|"normalizes"| node_ponte_documento
node_ponte_documento -->|"processes"| node_process_document
node_process_document -->|"extracts"| node_ponte_ocr
node_ponte_ocr -->|"executes"| node_ocr_py
node_ocr_py -->|"uses"| node_traineddata
node_media_queue -->|"downloads"| node_media_downloader
node_media_downloader -->|"routes"| node_ponte_audio
node_process_document -->|"summarizes"| node_ponte_ia
node_ponte_audio -->|"transforms"| node_ponte_ia
node_ponte_ia -->|"calls"| node_groq
node_process_document -->|"persists"| node_supabase
node_ponte_ia -->|"stores"| node_supabase
node_supabase -->|"surfaces"| node_index_html
node_supabase -->|"surfaces"| node_resumo_html
node_ponte -.->|"shared core"| node_ponte_whatsapp
node_ponte -.->|"shared core"| node_ponte_documento
node_ponte -.->|"shared core"| node_ponte_audio
node_ponte -.->|"shared core"| node_ponte_ocr
node_ponte -.->|"shared core"| node_ponte_ia

click node_server "https://github.com/avakconta91-gif/8n8/blob/main/server.js"
click node_app "https://github.com/avakconta91-gif/8n8/blob/main/app.js"
click node_router "https://github.com/avakconta91-gif/8n8/blob/main/router.js"
click node_env "https://github.com/avakconta91-gif/8n8/tree/main/env"
click node_dispatcher "https://github.com/avakconta91-gif/8n8/blob/main/dispatcher.js"
click node_evolution "https://github.com/avakconta91-gif/8n8/blob/main/evolution.js"
click node_ponte_whatsapp "https://github.com/avakconta91-gif/8n8/blob/main/ponte-whatsapp.js"
click node_ponte "https://github.com/avakconta91-gif/8n8/blob/main/ponte.js"
click node_document_queue "https://github.com/avakconta91-gif/8n8/blob/main/documentQueue.js"
click node_media_queue "https://github.com/avakconta91-gif/8n8/blob/main/mediaQueue.js"
click node_ponte_documento "https://github.com/avakconta91-gif/8n8/blob/main/ponte-documento.js"
click node_process_document "https://github.com/avakconta91-gif/8n8/blob/main/processDocument.js"
click node_media_downloader "https://github.com/avakconta91-gif/8n8/blob/main/media-downloader.js"
click node_ponte_ocr "https://github.com/avakconta91-gif/8n8/blob/main/ponte-ocr.js"
click node_ocr_py "https://github.com/avakconta91-gif/8n8/blob/main/ocr.py"
click node_ponte_audio "https://github.com/avakconta91-gif/8n8/blob/main/ponte-audio.js"
click node_ponte_ia "https://github.com/avakconta91-gif/8n8/blob/main/ponte-ia.js"
click node_groq "https://github.com/avakconta91-gif/8n8/blob/main/groq.js"
click node_supabase "https://github.com/avakconta91-gif/8n8/blob/main/supabase.js"
click node_index_html "https://github.com/avakconta91-gif/8n8/blob/main/index.html"
click node_resumo_html "https://github.com/avakconta91-gif/8n8/blob/main/resumo.html"
click node_traineddata "https://github.com/avakconta91-gif/8n8/blob/main/por.traineddata"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_server,node_app,node_router,node_env,node_dispatcher toneBlue
class node_document_queue,node_media_queue,node_ponte_documento,node_process_document,node_media_downloader,node_ponte_ocr,node_ocr_py,node_ponte_audio,node_ponte_ia,node_traineddata toneAmber
class node_evolution,node_ponte_whatsapp,node_ponte,node_groq,node_supabase toneMint
class node_index_html,node_resumo_html toneRose
```

## Components

### Node.js runtime

HTTP entrypoints, routing, and orchestration code.

- [Server](https://github.com/avakconta91-gif/8n8/blob/main/server.js): HTTP entrypoint · Starts the application and exposes the service surface. · `server.js`
- [App](https://github.com/avakconta91-gif/8n8/blob/main/app.js): service setup · Wires application-level middleware and runtime composition. · `app.js`
- [Router](https://github.com/avakconta91-gif/8n8/blob/main/router.js): route dispatch · Directs inbound requests into the appropriate handlers. · `router.js`
- [Env](https://github.com/avakconta91-gif/8n8/tree/main/env): configuration · External runtime configuration and secrets. · `env`
- [Dispatcher](https://github.com/avakconta91-gif/8n8/blob/main/dispatcher.js): event coordinator · Central routing layer that classifies inbound events and chooses a processing path. · `dispatcher.js`

### Processing pipelines

Queued document, media, OCR, audio, and AI processing stages.

- [Doc queue](https://github.com/avakconta91-gif/8n8/blob/main/documentQueue.js): work queue · Async queue for document-related jobs. · `documentQueue.js`
- [Media queue](https://github.com/avakconta91-gif/8n8/blob/main/mediaQueue.js): work queue · Async queue for media-related jobs. · `mediaQueue.js`
- [Doc bridge](https://github.com/avakconta91-gif/8n8/blob/main/ponte-documento.js): adapter · Normalizes or extracts document inputs before processing. · `ponte-documento.js`
- [Document proc](https://github.com/avakconta91-gif/8n8/blob/main/processDocument.js): pipeline stage · Document processing logic after intake and normalization. · `processDocument.js`
- [Media downloader](https://github.com/avakconta91-gif/8n8/blob/main/media-downloader.js): fetch stage · Retrieves remote attachments or media for downstream work. · `media-downloader.js`
- [OCR bridge](https://github.com/avakconta91-gif/8n8/blob/main/ponte-ocr.js): cross-runtime adapter · Node-side bridge to the OCR execution boundary. · `ponte-ocr.js`
- [OCR engine](https://github.com/avakconta91-gif/8n8/blob/main/ocr.py): python worker · Python OCR component for text extraction. · `ocr.py`
- [Audio bridge](https://github.com/avakconta91-gif/8n8/blob/main/ponte-audio.js): adapter · Handles audio-related intake and normalization. · `ponte-audio.js`
- [AI bridge](https://github.com/avakconta91-gif/8n8/blob/main/ponte-ia.js): adapter · Routes extracted content into the AI/inference layer. · `ponte-ia.js`
- [OCR data](https://github.com/avakconta91-gif/8n8/blob/main/por.traineddata): language data · Portuguese OCR training data used by the OCR stage. · `por.traineddata`

### External services

Messaging, AI, and persistence boundaries.

- [Evolution](https://github.com/avakconta91-gif/8n8/blob/main/evolution.js): event bridge · Integration with the incoming messaging/event provider. · `evolution.js`
- [WhatsApp bridge](https://github.com/avakconta91-gif/8n8/blob/main/ponte-whatsapp.js): adapter · Adapter for WhatsApp-like message events. · `ponte-whatsapp.js`
- [Bridge core](https://github.com/avakconta91-gif/8n8/blob/main/ponte.js): adapter core · Shared bridge/orchestration helper used by the platform adapters. · `ponte.js`
- [Groq](https://github.com/avakconta91-gif/8n8/blob/main/groq.js): AI provider · External model/inference service used for generation or summarization. · `groq.js`
- [Supabase](https://github.com/avakconta91-gif/8n8/blob/main/supabase.js): data store · Durable storage for records, job state, or generated outputs. · `supabase.js`

### Presentation

Static HTML views for lightweight output and inspection.

- [Home UI](https://github.com/avakconta91-gif/8n8/blob/main/index.html): static page · Primary lightweight browser-facing page. · `index.html`
- [Summary UI](https://github.com/avakconta91-gif/8n8/blob/main/resumo.html): static page · Static page for summaries or operational output. · `resumo.html`

## Connections

- Server → App: bootstraps · Server starts the application runtime.
- App → Router: routes · Application hands requests to the router.
- App → Dispatcher: wires · Application connects intake to the central dispatcher.
- App → Env: reads · Runtime configuration is loaded externally.
- Router → Evolution: ingests · Routes inbound messaging/event traffic into the provider bridge.
- Evolution → WhatsApp bridge: adapts · Provider events are normalized through the WhatsApp bridge.
- WhatsApp bridge → Dispatcher: dispatches · Normalized message events are handed to the dispatcher.
- Dispatcher → Doc queue: enqueues · Document payloads are sent to asynchronous processing.
- Dispatcher → Media queue: enqueues · Media payloads are sent to asynchronous processing.
- Doc queue → Doc bridge: normalizes · Queued document jobs enter the document adapter.
- Doc bridge → Document proc: processes · Document inputs flow into the document pipeline.
- Document proc → OCR bridge: extracts · Document processing can invoke OCR when text needs extraction.
- OCR bridge → OCR engine: executes · Node bridges into the Python OCR worker.
- OCR engine → OCR data: uses · OCR consumes Portuguese trained language data.
- Media queue → Media downloader: downloads · Queued media jobs fetch remote attachments for local processing.
- Media downloader → Audio bridge: routes · Fetched media can be treated as audio when appropriate.
- Document proc → AI bridge: summarizes · Processed text or extracted content is passed to AI.
- Audio bridge → AI bridge: transforms · Audio-derived content can be forwarded into AI analysis.
- AI bridge → Groq: calls · AI bridge invokes the model provider.
- Document proc → Supabase: persists · Document results and metadata are stored durably.
- AI bridge → Supabase: stores · Generated summaries or classifications are persisted.
- Supabase → Home UI: surfaces · Stored data may be shown in the lightweight UI.
- Supabase → Summary UI: surfaces · Summaries or reports may be rendered in the summary page.
- Bridge core → WhatsApp bridge: shared core · Common bridge logic supports the WhatsApp adapter.
- Bridge core → Doc bridge: shared core · Common bridge logic supports the document adapter.
- Bridge core → Audio bridge: shared core · Common bridge logic supports the audio adapter.
- Bridge core → OCR bridge: shared core · Common bridge logic supports the OCR bridge.
- Bridge core → AI bridge: shared core · Common bridge logic supports the AI bridge.
