# grupototum/totum-system architecture

> Architecture diagram of the GitHub repository grupototum/totum-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/grupototum/totum-system
- Repository: https://github.com/grupototum/totum-system

## Overview

1. This repository is a multi-surface operational platform, not a single app. The main product is the TOTUM ecosystem: a React/Vite frontend, a Supabase-backed data layer, a small Node/TypeScript API for tasks, and a set of AI/automation scripts around agents, knowledge ingestion, transcription, and publishing.

2. The primary user interface lives under `src/`. It is a large React application organized by domain pages and reusable components. The main boundaries are visible in `src/pages/` and `src/components/`: tasks, clients, projects, financial, agents, Alexandria/knowledge, admin/settings, and workspace/ops.

3. The frontend is stateful through React contexts and hooks rather than a single global store. `src/contexts/` handles auth, theme, demo/loading state; `src/hooks/` contains domain accessors such as tasks, clients, agents, Asaas, RAG, permissions, dashboards, and transcription. This is where UI components connect to backend services.

4. Supabase is the central persistence and backend platform. The repo contains extensive migration history in `supabase/migrations/` and feature functions in `supabase/functions/`, including recurring task generation, checklist generation, task archiving, admin bootstrap, and Asaas proxy/webhook handling. The frontend uses the Supabase client in `src/integrations/supabase/`.

5. The data model is broad and business-oriented: tasks, projects, clients, contracts, users/roles, financial entries, packages, registries, delivery checklists, SLA rules, and agent logs. The UI modules mirror these tables closely, so the architecture diagram should show tight coupling between feature pages and Supabase tables/functions.

6. There is a secondary backend service in `src/stark-api/`. It is a standalone Node/TypeScript API with its own build output, routes, controllers, and Supabase connection, centered on task operations. Architecturally, it sits beside the main frontend/Supabase flow as a dedicated service boundary rather than part of the React app.

7. The AI/knowledge subsystem is split from the core business UI. `src/components/alexandria/`, `src/pages/alexandria/`, `src/hooks/useRAG.ts`, and `src/services/embeddingService.ts` define the knowledge hub in the frontend, while `src/context_hub/core/` contains Python code for a curator agent and vector store. This suggests a retrieval/curation pipeline that feeds the Alexandria portal and related skills/context screens.

8. Agent orchestration is a major concept throughout the repo. There are agent definitions in `src/agents/`, richer agent UI in `src/components/agents/` and `src/pages/agents/`, plus catalogs and docs under `agents/`, `apps/alexandria/`, and `tarefas/`. The architecture likely treats agents as first-class operational entities with hierarchy, metrics, chat, tasks, and execution logs.

9. Automation and content pipelines live in `scripts/` and `data/`. These scripts process transcriptions, ingest content to Supabase, generate daily reports, handle Ollama fallbacks, simulate or publish content for Wanda/Scrivo, and interface with TikTok and Telegram. The `data/outputs/`, `data/logs/`, `data/backups/`, and local `.db` files act as file-based working storage and audit artifacts for those jobs.

10. External services materially shaping the design are Supabase, Asaas, TikTok, Ollama, Gemini/Groq, Telegram, and sometimes Google Drive/n8n. You can see setup and integration docs for each, plus edge functions and scripts that act as adapters. These are not incidental; they are the integration layer around the product.

11. The repo also includes deployment and operational infrastructure in `infra/`, with Docker Compose, shell scripts, monitoring, sync, backup, and bootstrap tooling. CI is present via GitHub Actions, and there are local configuration files for environment and workspace state. This makes the system deployable as a mix of frontend, backend, edge functions, and worker scripts.

12. There are multiple UI variants and snapshots, but they are secondary to the main `src/` application: `apps/totum/` is a standalone packaged frontend, and `data-unifica-agentes-ui/` is another agent/dashboard UI prototype. For an architecture diagram, treat these as adjacent presentation surfaces or derivative apps, not the central platform.

13. In practice, the core data flow is: user action in React UI → hook/service layer → Supabase or `stark-api` → persisted tables/functions → updated dashboards/agent views. Around that core, the AI pipelines ingest documents/transcriptions into local artifacts or vectors, then surface results back into the Alexandria, agents, and content modules.

Main entry points: [`src/pages`](https://github.com/grupototum/totum-system/tree/main/src/pages) (Business Pages), [`scripts`](https://github.com/grupototum/totum-system/tree/main/scripts) (Pipeline Scripts), [`src/contexts`](https://github.com/grupototum/totum-system/tree/main/src/contexts) (State Hooks), [`src/components`](https://github.com/grupototum/totum-system/tree/main/src/components) (Feature UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Main UI"]
  node_src_app["TOTUM UI<br/>React app<br/>[App.tsx]"]
  node_src_pages_business["Business Pages<br/>domain pages"]
  node_src_components_business["Feature UI<br/>feature components"]
  node_src_contexts_hooks(("State Hooks<br/>contexts and hooks"))
end

subgraph group_backend["Backend Data"]
  node_supabase_client["Supabase Client<br/>db client<br/>[client.ts]"]
  node_supabase_migrations[("Schema Migrations<br/>database schema")]
  node_supabase_functions["Edge Functions<br/>serverless functions"]
  node_stark_api["Stark API<br/>node api<br/>[index.ts]"]
  node_stark_tasks["Task Controller<br/>task service"]
end

subgraph group_agents["Agents & AI"]
  node_agents_ui["Agents UI<br/>agent screens"]
  node_agents_defs["Agent Catalog<br/>agent definitions"]
  node_alexandria_ui["Alexandria Hub<br/>knowledge ui"]
  node_alexandria_services["RAG Services<br/>retrieval services<br/>[useRAG.ts]"]
  node_context_hub["Curator Core<br/>python pipeline"]
  node_ai_services["AI Services<br/>ai adapters"]
end

subgraph group_automation["Automation Pipelines"]
  node_scripts_pipeline["Pipeline Scripts<br/>automation scripts"]
  node_data_store[("Working Data<br/>artifacts")]
end

subgraph group_ops["Ops & Infra"]
  node_infra_stack["Infra Stack<br/>deploy tooling"]
end

node_src_app -->|"routes to"| node_src_pages_business
node_src_app -->|"composes"| node_src_components_business
node_src_pages_business -->|"uses state"| node_src_contexts_hooks
node_src_components_business -->|"binds to"| node_src_contexts_hooks
node_src_contexts_hooks -->|"fetches data"| node_supabase_client
node_supabase_client -.->|"reads schema"| node_supabase_migrations
node_src_pages_business -.->|"mirrors tables"| node_supabase_migrations
node_supabase_functions -->|"operates on"| node_supabase_migrations
node_stark_api -->|"exposes"| node_stark_tasks
node_stark_tasks -->|"persists via"| node_supabase_client
node_src_pages_business -.->|"delegates tasks"| node_stark_api
node_agents_ui -->|"renders"| node_agents_defs
node_agents_ui -->|"uses state"| node_src_contexts_hooks
node_alexandria_ui -->|"uses retrieval"| node_alexandria_services
node_alexandria_services -->|"feeds curator"| node_context_hub
node_ai_services -->|"supports"| node_alexandria_services
node_scripts_pipeline -->|"writes artifacts"| node_data_store
node_scripts_pipeline -.->|"ingests to"| node_supabase_functions
node_scripts_pipeline -->|"calls models"| node_ai_services
node_infra_stack -.->|"runs jobs"| node_scripts_pipeline
node_infra_stack -.->|"deploys"| node_supabase_functions
node_src_components_business -.->|"links ops"| node_agents_ui

click node_src_app "https://github.com/grupototum/totum-system/blob/main/src/App.tsx"
click node_src_pages_business "https://github.com/grupototum/totum-system/tree/main/src/pages"
click node_src_components_business "https://github.com/grupototum/totum-system/tree/main/src/components"
click node_src_contexts_hooks "https://github.com/grupototum/totum-system/tree/main/src/contexts"
click node_supabase_client "https://github.com/grupototum/totum-system/blob/main/src/integrations/supabase/client.ts"
click node_supabase_migrations "https://github.com/grupototum/totum-system/tree/main/supabase/migrations"
click node_supabase_functions "https://github.com/grupototum/totum-system/tree/main/supabase/functions"
click node_stark_api "https://github.com/grupototum/totum-system/blob/main/src/stark-api/src/index.ts"
click node_stark_tasks "https://github.com/grupototum/totum-system/blob/main/src/stark-api/src/controllers/tarefasController.ts"
click node_agents_ui "https://github.com/grupototum/totum-system/tree/main/src/components/agents"
click node_agents_defs "https://github.com/grupototum/totum-system/tree/main/src/agents"
click node_alexandria_ui "https://github.com/grupototum/totum-system/tree/main/src/pages/alexandria"
click node_alexandria_services "https://github.com/grupototum/totum-system/blob/main/src/hooks/useRAG.ts"
click node_context_hub "https://github.com/grupototum/totum-system/tree/main/src/context_hub/core"
click node_ai_services "https://github.com/grupototum/totum-system/tree/main/src/services"
click node_scripts_pipeline "https://github.com/grupototum/totum-system/tree/main/scripts"
click node_data_store "https://github.com/grupototum/totum-system/tree/main/data"
click node_infra_stack "https://github.com/grupototum/totum-system/tree/main/infra"

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_src_app,node_src_pages_business,node_src_components_business,node_src_contexts_hooks toneBlue
class node_supabase_client,node_supabase_migrations,node_supabase_functions,node_stark_api,node_stark_tasks toneAmber
class node_agents_ui,node_agents_defs,node_alexandria_ui,node_alexandria_services,node_context_hub,node_ai_services toneMint
class node_scripts_pipeline,node_data_store toneRose
class node_infra_stack toneIndigo
```

## Components

### Main UI

Primary React/Vite application for the TOTUM ecosystem.

- [TOTUM UI](https://github.com/grupototum/totum-system/blob/main/src/App.tsx): React app · Main multi-domain frontend shell and navigation. · `src/App.tsx`
- [Business Pages](https://github.com/grupototum/totum-system/tree/main/src/pages): domain pages · Core operational screens for tasks, clients, projects, financial, reports, and settings. · `src/pages`
- [Feature UI](https://github.com/grupototum/totum-system/tree/main/src/components): feature components · Reusable UI for tasks, clients, contracts, financial, registries, POP/SLA, and workspace views. · `src/components`
- [State Hooks](https://github.com/grupototum/totum-system/tree/main/src/contexts): contexts and hooks · Auth, demo, loading, permissions, dashboard, and domain access hooks. · `src/contexts`

### Backend Data

Supabase persistence, edge functions, and the small task API service.

- [Supabase Client](https://github.com/grupototum/totum-system/blob/main/src/integrations/supabase/client.ts): db client · Frontend integration point for Supabase auth and data access. · `src/integrations/supabase/client.ts`
- [Schema Migrations](https://github.com/grupototum/totum-system/tree/main/supabase/migrations): database schema · Business data model history for tasks, clients, contracts, financials, agents, and permissions. · `supabase/migrations`
- [Edge Functions](https://github.com/grupototum/totum-system/tree/main/supabase/functions): serverless functions · Automation endpoints for recurring tasks, checklists, archiving, admin bootstrap, and Asaas proxy/webhooks. · `supabase/functions`
- [Stark API](https://github.com/grupototum/totum-system/blob/main/src/stark-api/src/index.ts): node api · Standalone Node/TypeScript service for task operations with its own routes and controllers. · `src/stark-api/src/index.ts`
- [Task Controller](https://github.com/grupototum/totum-system/blob/main/src/stark-api/src/controllers/tarefasController.ts): task service · Task routes and controller logic served by the Stark API boundary. · `src/stark-api/src/controllers/tarefasController.ts`

### Agents & AI

Agent UI, orchestration, knowledge retrieval, and AI services.

- [Agents UI](https://github.com/grupototum/totum-system/tree/main/src/components/agents): agent screens · Agent dashboards, chat surfaces, hierarchy views, and execution logs in the frontend. · `src/components/agents`
- [Agent Catalog](https://github.com/grupototum/totum-system/tree/main/src/agents): agent definitions · Markdown-defined agents, roles, and operational prompts used across the platform. · `src/agents`
- [Alexandria Hub](https://github.com/grupototum/totum-system/tree/main/src/pages/alexandria): knowledge ui · Knowledge, skills, and context portal for curation and retrieval workflows. · `src/pages/alexandria`
- [RAG Services](https://github.com/grupototum/totum-system/blob/main/src/hooks/useRAG.ts): retrieval services · Frontend RAG hooks and embedding services backing Alexandria experiences. · `src/hooks/useRAG.ts`
- [Curator Core](https://github.com/grupototum/totum-system/tree/main/src/context_hub/core): python pipeline · Python curator agent and vector store for local knowledge processing. · `src/context_hub/core`
- [AI Services](https://github.com/grupototum/totum-system/tree/main/src/services): ai adapters · Integration layer for Gemini, Ollama, transcription, embeddings, skills, and Telegram. · `src/services`

### Automation Pipelines

Scripts and local artifacts for ingestion, transcription, publishing, and reporting.

- [Pipeline Scripts](https://github.com/grupototum/totum-system/tree/main/scripts): automation scripts · Batch jobs for ingestion, transcription processing, fallback generation, and publishing automation. · `scripts`
- [Working Data](https://github.com/grupototum/totum-system/tree/main/data): artifacts · Local outputs, logs, backups, and embedded working files for automation jobs. · `data`

### Ops & Infra

Deployment, sync, backup, and environment tooling.

- [Infra Stack](https://github.com/grupototum/totum-system/tree/main/infra): deploy tooling · Docker, sync, monitoring, and bootstrap scripts for local and server deployment. · `infra`

## Connections

- TOTUM UI → Business Pages: routes to · Main shell routes users into the business and operational screens.
- TOTUM UI → Feature UI: composes · The UI shell is assembled from reusable domain components.
- Business Pages → State Hooks: uses state · Pages rely on hooks and contexts for auth, permissions, data, and dashboard state.
- Feature UI → State Hooks: binds to · Feature components read/write domain state through hooks.
- State Hooks → Supabase Client: fetches data · Hooks bridge UI state to Supabase auth and data access.
- Supabase Client → Schema Migrations: reads schema · Client-side models reflect the migrated database schema.
- Business Pages → Schema Migrations: mirrors tables · Business pages map closely to the underlying business tables and views.
- Edge Functions → Schema Migrations: operates on · Edge functions implement workflows over persisted tables and rules.
- Stark API → Task Controller: exposes · The Stark API hosts task-focused routes and controllers.
- Task Controller → Supabase Client: persists via · Task operations are stored through Supabase connectivity.
- Business Pages → Stark API: delegates tasks · The main UI can use the dedicated task service boundary for task operations.
- Agents UI → Agent Catalog: renders · Agent screens surface the markdown-based agent catalog and roles.
- Agents UI → State Hooks: uses state · Agent dashboards and chat use hooks for execution, classification, and task data.
- Alexandria Hub → RAG Services: uses retrieval · Alexandria screens consume RAG and embedding services.
- RAG Services → Curator Core: feeds curator · Frontend retrieval features connect to the curator/vector-store pipeline.
- AI Services → RAG Services: supports · AI adapters provide embeddings, model calls, and transcription support to RAG flows.
- Pipeline Scripts → Working Data: writes artifacts · Automation jobs produce logs, outputs, backups, and processed media artifacts.
- Pipeline Scripts → Edge Functions: ingests to · Scripts coordinate with Supabase-backed workflows and edge endpoints.
- Pipeline Scripts → AI Services: calls models · Batch pipelines use Ollama, Gemini, Whisper, and Telegram integrations.
- Infra Stack → Pipeline Scripts: runs jobs · Deployment and bootstrap tooling support the automation scripts and workers.
- Infra Stack → Edge Functions: deploys · Infra scripts support local and server-side Supabase function operations.
- Feature UI → Agents UI: links ops · Operational components expose agent-centric views, metrics, and execution controls.
