# araveai99-glitch/execuai architecture

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

- Interactive diagram: https://gitdiagram.com/araveai99-glitch/execuai
- Repository: https://github.com/araveai99-glitch/execuai

## Overview

ExecuAI is an executive email triage and decision-support application: users connect mailboxes, review a unified inbox and its prioritization/risk classifications, then work with AI-assisted drafts. The sampled runtime also shows a separate provider-based ingestion path that queues triage work, and organization, access-control, and audit APIs. The README is only the generic Next.js starter, so product capabilities and links are grounded in the source index and excerpts; unsampled implementation details are not inferred.

Main entry points: [`src/app/api/v1/inbox/route.ts`](https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/inbox/route.ts) (Inbox API), [`src/lib/server/gmail-token-store.ts`](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/gmail-token-store.ts) (Mailbox credentials), [`src/app/api/v1/sync/route.ts`](https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/sync/route.ts) (Incremental sync API), [`src/app/api/v1/drafts/route.ts`](https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/drafts/route.ts) (Draft API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mail["Mailbox and triage"]
  node_inbox_api["Inbox API<br/>[route.ts]"]
  node_sync_api["Incremental sync API<br/>[route.ts]"]
  node_ingestion["Email ingestion"]
  node_email_queue["Triage queue<br/>[emailQueue.ts]"]
  node_inbox_ui["Inbox and decisions<br/>[page.tsx]"]
  node_email_detail["Email detail"]
  node_triage_service["Triage service<br/>[triage_service.py]"]
  node_llm_provider["LLM provider<br/>[llm_provider.py]"]
  node_fastapi["Triage API<br/>[main.py]"]
end

subgraph group_workflow["Draft workflow"]
  node_draft_api["Draft API<br/>[route.ts]"]
  node_draft_workbench["AI draft workbench"]
  node_policy["Policy engine<br/>[PolicyEngine.ts]"]
  node_controlled_send["Controlled sending"]
end

subgraph group_identity["Identity and organization"]
  node_session["Session identity<br/>[auth-session.ts]"]
  node_rbac["Role and tenant access<br/>[rbac.ts]"]
  node_org_store[("Organization store<br/>[org-store.ts]")]
  node_audit_store[("Audit log store<br/>[audit-store.ts]")]
  node_org_api["Organization APIs<br/>[route.ts]"]
end

subgraph group_platform["Data and providers"]
  node_gmail["Gmail API service<br/>[GmailApiService.ts]"]
  node_gmail_service["Gmail provider<br/>[GmailProvider.ts]"]
  node_zoho_service["Zoho provider<br/>[ZohoProvider.ts]"]
  node_provider_factory["Provider factory<br/>[ProviderFactory.ts]"]
  node_email_store[("Email store")]
  node_token_store[("Mailbox credentials")]
  node_prisma["Prisma database client<br/>[prisma-client.ts]"]
  node_supabase["Supabase server client<br/>[server.ts]"]
end

node_user(("Executive user"))
node_gmail_external(("Gmail"))

node_user -.->|"reviews mail"| node_inbox_ui
node_inbox_api -->|"resolves user"| node_session
node_inbox_api -->|"loads credentials"| node_token_store
node_inbox_api -->|"fetches messages"| node_gmail
node_inbox_api -->|"saves messages"| node_email_store
node_sync_api -->|"resolves user"| node_session
node_sync_api -->|"loads credentials"| node_token_store
node_sync_api -->|"fetches updates"| node_gmail
node_sync_api -->|"persists messages"| node_email_store
node_gmail -->|"calls Gmail"| node_gmail_external
node_inbox_ui -.->|"requests inbox"| node_inbox_api
node_inbox_ui -.->|"opens message"| node_email_detail
node_draft_api -->|"resolves user"| node_session
node_draft_api -->|"loads credentials"| node_token_store
node_draft_api -->|"uses Gmail service"| node_gmail
node_draft_workbench -.->|"requests drafts"| node_draft_api
node_ingestion -->|"selects provider"| node_provider_factory
node_ingestion -->|"enqueues triage"| node_email_queue
node_provider_factory -->|"constructs provider"| node_gmail_service
node_provider_factory -->|"constructs provider"| node_zoho_service
node_fastapi -->|"dispatches triage"| node_triage_service
node_fastapi -->|"uses provider"| node_llm_provider
node_rbac -->|"resolves identity"| node_session
node_rbac -->|"loads user and org"| node_org_store
node_org_api -->|"checks access"| node_rbac
node_org_api -->|"manages organization"| node_org_store
node_org_api -->|"records activity"| node_audit_store
node_org_store -->|"persists records"| node_prisma
node_audit_store -->|"persists audit events"| node_prisma
node_audit_store -->|"persists audit events"| node_supabase
node_token_store -->|"reads and writes tokens"| node_prisma
node_token_store -->|"reads and writes tokens"| node_supabase
node_email_store -->|"uses database"| node_prisma
node_email_store -->|"uses database"| node_supabase

click node_inbox_api "https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/inbox/route.ts"
click node_sync_api "https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/sync/route.ts"
click node_gmail "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/services/GmailApiService.ts"
click node_gmail_service "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/providers/GmailProvider.ts"
click node_zoho_service "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/providers/ZohoProvider.ts"
click node_provider_factory "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/providers/ProviderFactory.ts"
click node_ingestion "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/services/EmailIngestionPipeline.ts"
click node_email_queue "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/queue/emailQueue.ts"
click node_email_store "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/gmail-email-store.ts"
click node_token_store "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/gmail-token-store.ts"
click node_inbox_ui "https://github.com/araveai99-glitch/execuai/blob/main/src/app/app/inbox/page.tsx"
click node_email_detail "https://github.com/araveai99-glitch/execuai/blob/main/src/components/execuai/EmailDetailView.tsx"
click node_draft_api "https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/drafts/route.ts"
click node_draft_workbench "https://github.com/araveai99-glitch/execuai/blob/main/src/components/execuai/AIDraftWorkbench.tsx"
click node_policy "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/services/PolicyEngine.ts"
click node_controlled_send "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/services/ControlledSendService.ts"
click node_session "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/auth-session.ts"
click node_rbac "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/rbac.ts"
click node_org_store "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/org-store.ts"
click node_audit_store "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/audit-store.ts"
click node_org_api "https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/organization/route.ts"
click node_prisma "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/prisma-client.ts"
click node_supabase "https://github.com/araveai99-glitch/execuai/blob/main/src/lib/supabase/server.ts"
click node_triage_service "https://github.com/araveai99-glitch/execuai/blob/main/fastapi_backend/services/triage_service.py"
click node_llm_provider "https://github.com/araveai99-glitch/execuai/blob/main/fastapi_backend/services/llm_provider.py"
click node_fastapi "https://github.com/araveai99-glitch/execuai/blob/main/fastapi_backend/main.py"

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_inbox_api,node_sync_api,node_ingestion,node_email_queue,node_inbox_ui,node_email_detail,node_triage_service,node_llm_provider,node_fastapi,node_user toneBlue
class node_draft_api,node_draft_workbench,node_policy,node_controlled_send toneAmber
class node_session,node_rbac,node_org_store,node_audit_store,node_org_api toneMint
class node_gmail,node_gmail_service,node_zoho_service,node_provider_factory,node_email_store,node_token_store,node_prisma,node_supabase toneRose
class node_gmail_external toneIndigo
```

## Components

### Mailbox and triage

- [Inbox API](https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/inbox/route.ts): `src/app/api/v1/inbox/route.ts`
- [Incremental sync API](https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/sync/route.ts): `src/app/api/v1/sync/route.ts`
- [Email ingestion](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/services/EmailIngestionPipeline.ts): `src/lib/services/EmailIngestionPipeline.ts`
- [Triage queue](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/queue/emailQueue.ts): `src/lib/queue/emailQueue.ts`
- [Inbox and decisions](https://github.com/araveai99-glitch/execuai/blob/main/src/app/app/inbox/page.tsx): `src/app/app/inbox/page.tsx`
- [Email detail](https://github.com/araveai99-glitch/execuai/blob/main/src/components/execuai/EmailDetailView.tsx): `src/components/execuai/EmailDetailView.tsx`
- [Triage service](https://github.com/araveai99-glitch/execuai/blob/main/fastapi_backend/services/triage_service.py): `fastapi_backend/services/triage_service.py`
- [LLM provider](https://github.com/araveai99-glitch/execuai/blob/main/fastapi_backend/services/llm_provider.py): `fastapi_backend/services/llm_provider.py`
- [Triage API](https://github.com/araveai99-glitch/execuai/blob/main/fastapi_backend/main.py): `fastapi_backend/main.py`

### Draft workflow

- [Draft API](https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/drafts/route.ts): `src/app/api/v1/drafts/route.ts`
- [AI draft workbench](https://github.com/araveai99-glitch/execuai/blob/main/src/components/execuai/AIDraftWorkbench.tsx): `src/components/execuai/AIDraftWorkbench.tsx`
- [Policy engine](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/services/PolicyEngine.ts): `src/lib/services/PolicyEngine.ts`
- [Controlled sending](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/services/ControlledSendService.ts): `src/lib/services/ControlledSendService.ts`

### Identity and organization

- [Session identity](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/auth-session.ts): `src/lib/server/auth-session.ts`
- [Role and tenant access](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/rbac.ts): `src/lib/server/rbac.ts`
- [Organization store](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/org-store.ts): `src/lib/server/org-store.ts`
- [Audit log store](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/audit-store.ts): `src/lib/server/audit-store.ts`
- [Organization APIs](https://github.com/araveai99-glitch/execuai/blob/main/src/app/api/v1/organization/route.ts): `src/app/api/v1/organization/route.ts`

### Data and providers

- [Gmail API service](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/services/GmailApiService.ts): `src/lib/services/GmailApiService.ts`
- [Gmail provider](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/providers/GmailProvider.ts): `src/lib/providers/GmailProvider.ts`
- [Zoho provider](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/providers/ZohoProvider.ts): `src/lib/providers/ZohoProvider.ts`
- [Provider factory](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/providers/ProviderFactory.ts): `src/lib/providers/ProviderFactory.ts`
- [Email store](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/gmail-email-store.ts): `src/lib/server/gmail-email-store.ts`
- [Mailbox credentials](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/gmail-token-store.ts): `src/lib/server/gmail-token-store.ts`
- [Prisma database client](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/server/prisma-client.ts): `src/lib/server/prisma-client.ts`
- [Supabase server client](https://github.com/araveai99-glitch/execuai/blob/main/src/lib/supabase/server.ts): `src/lib/supabase/server.ts`

### Other components

- **Executive user**
- **Gmail**

## Connections

- Executive user → Inbox and decisions: reviews mail
- Inbox API → Session identity: resolves user (evidence: `src/app/api/v1/inbox/route.ts`)
- Inbox API → Mailbox credentials: loads credentials (evidence: `src/app/api/v1/inbox/route.ts`)
- Inbox API → Gmail API service: fetches messages (evidence: `src/app/api/v1/inbox/route.ts`)
- Inbox API → Email store: saves messages (evidence: `src/app/api/v1/inbox/route.ts`)
- Incremental sync API → Session identity: resolves user (evidence: `src/app/api/v1/sync/route.ts`)
- Incremental sync API → Mailbox credentials: loads credentials (evidence: `src/app/api/v1/sync/route.ts`)
- Incremental sync API → Gmail API service: fetches updates (evidence: `src/app/api/v1/sync/route.ts`)
- Incremental sync API → Email store: persists messages (evidence: `src/app/api/v1/sync/route.ts`)
- Gmail API service → Gmail: calls Gmail (evidence: `src/lib/services/GmailApiService.ts`)
- Inbox and decisions → Inbox API: requests inbox
- Inbox and decisions → Email detail: opens message
- Draft API → Session identity: resolves user (evidence: `src/app/api/v1/drafts/route.ts`)
- Draft API → Mailbox credentials: loads credentials (evidence: `src/app/api/v1/drafts/route.ts`)
- Draft API → Gmail API service: uses Gmail service (evidence: `src/app/api/v1/drafts/route.ts`)
- AI draft workbench → Draft API: requests drafts
- Email ingestion → Provider factory: selects provider (evidence: `src/lib/services/EmailIngestionPipeline.ts`)
- Email ingestion → Triage queue: enqueues triage (evidence: `src/lib/services/EmailIngestionPipeline.ts`)
- Provider factory → Gmail provider: constructs provider (evidence: `src/lib/providers/ProviderFactory.ts`)
- Provider factory → Zoho provider: constructs provider (evidence: `src/lib/providers/ProviderFactory.ts`)
- Triage API → Triage service: dispatches triage (evidence: `fastapi_backend/main.py`)
- Triage API → LLM provider: uses provider (evidence: `fastapi_backend/main.py`)
- Role and tenant access → Session identity: resolves identity (evidence: `src/lib/server/rbac.ts`)
- Role and tenant access → Organization store: loads user and org (evidence: `src/lib/server/rbac.ts`)
- Organization APIs → Role and tenant access: checks access (evidence: `src/app/api/v1/organization/route.ts`)
- Organization APIs → Organization store: manages organization (evidence: `src/app/api/v1/organization/route.ts`)
- Organization APIs → Audit log store: records activity (evidence: `src/app/api/v1/organization/route.ts`)
- Organization store → Prisma database client: persists records (evidence: `src/lib/server/org-store.ts`)
- Audit log store → Prisma database client: persists audit events (evidence: `src/lib/server/audit-store.ts`)
- Audit log store → Supabase server client: persists audit events (evidence: `src/lib/server/audit-store.ts`)
- Mailbox credentials → Prisma database client: reads and writes tokens (evidence: `src/lib/server/gmail-token-store.ts`)
- Mailbox credentials → Supabase server client: reads and writes tokens (evidence: `src/lib/server/gmail-token-store.ts`)
- Email store → Prisma database client: uses database (evidence: `src/lib/server/gmail-email-store.ts`)
- Email store → Supabase server client: uses database (evidence: `src/lib/server/gmail-email-store.ts`)
