# mohammadali-2000/twinops-enterprise architecture

> Architecture diagram of the GitHub repository mohammadali-2000/twinops-enterprise, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mohammadali-2000/twinops-enterprise
- Repository: https://github.com/mohammadali-2000/twinops-enterprise

## Overview

TwinOps builds workplace digital twins from enterprise knowledge, then serves grounded answers and coordination through its web app and Slack/Teams channels. The main path is ingest or sync organizational sources into searchable memory, retrieve that context for a clone, generate a response, and deliver it to the requester. Separate TwinOps workflows provide organization-wide insights, onboarding briefs, and offboarding handoffs. The map emphasizes relationships explicit in the sampled routes and README; unsampled subsystem wiring is omitted.

Main entry points: [`lib/core/supabase/server.ts`](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/core/supabase/server.ts) (Supabase PostgreSQL), [`app/api/chat/route.ts`](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/chat/route.ts) (Clone Chat API), [`app/api/slack/events/route.ts`](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/slack/events/route.ts) (Slack Events), [`app/api/teams/events/route.ts`](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/teams/events/route.ts) (Teams Events)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_product["Web Product"]
  node_web["TwinOps Web UI<br/>[page.tsx]"]
  node_chatapi["Clone Chat API<br/>[route.ts]"]
  node_twchat["TwinOps Chat API<br/>[route.ts]"]
end

subgraph group_runtime["Twin Reasoning"]
  node_brain["Clone Brain<br/>[clone-brain.ts]"]
  node_collab["Agent Collaboration<br/>[collaboration.ts]"]
end

subgraph group_knowledge["Knowledge Pipeline"]
  node_memory["Memory Services<br/>[index.ts]"]
  node_clone_repo["Clone Repository"]
  node_database[("Supabase PostgreSQL<br/>[server.ts]")]
  node_ingest["Document Ingestion<br/>[route.ts]"]
  node_synthetic["Synthetic Ingestion<br/>[route.ts]"]
  node_integrations_api["Integration Sync API<br/>[route.ts]"]
  node_connectors["Source Connectors<br/>[index.ts]"]
end

subgraph group_channels["Enterprise Channels"]
  node_slack["Slack Events<br/>[route.ts]"]
  node_teams["Teams Events<br/>[route.ts]"]
  node_teams_api["Teams Connector<br/>[teams.ts]"]
end

subgraph group_operations["Workforce Operations"]
  node_insights["Organization Insights<br/>[route.ts]"]
  node_onboarding["Onboarding Brief<br/>[route.ts]"]
  node_offboarding["Offboarding Handoff<br/>[route.ts]"]
  node_documents["Memory Explorer<br/>[route.ts]"]
end

node_employee(("Employee"))
node_model{{"OpenAI"}}
node_enterprise_sources{{"Enterprise Systems"}}
node_slack_service{{"Slack"}}
node_teams_service{{"Microsoft Teams"}}

node_employee -->|"uses"| node_web
node_web -->|"sends chat"| node_chatapi
node_chatapi -->|"loads clone"| node_clone_repo
node_chatapi -->|"retrieves context"| node_memory
node_chatapi -->|"builds prompt"| node_brain
node_chatapi -->|"consults clone"| node_collab
node_chatapi -->|"generates response"| node_model
node_chatapi -->|"learns from chat"| node_memory
node_twchat -->|"reads clone and memories"| node_database
node_twchat -->|"streams response"| node_model
node_ingest -->|"writes document"| node_database
node_synthetic -->|"writes memories"| node_database
node_synthetic -->|"creates embeddings"| node_model
node_integrations_api -->|"starts sync"| node_connectors
node_connectors -->|"fetches records"| node_enterprise_sources
node_integrations_api -->|"reads configuration"| node_database
node_slack_service -->|"sends events"| node_slack
node_slack -->|"stores message memories"| node_database
node_slack -->|"embeds message"| node_model
node_slack -->|"learns facts"| node_memory
node_teams_service -->|"sends queries"| node_teams
node_teams -->|"stores and searches"| node_database
node_teams -->|"searches fallback"| node_memory
node_teams -->|"sends reply card"| node_teams_api
node_teams_api -->|"delivers card"| node_teams_service
node_insights -->|"queries memories"| node_database
node_insights -->|"summarizes findings"| node_model
node_onboarding -->|"reads clone context"| node_database
node_offboarding -->|"reads memories and clones"| node_database
node_documents -->|"queries documents"| node_database

click node_web "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/(app)/dashboard/page.tsx"
click node_chatapi "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/chat/route.ts"
click node_twchat "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/chat/route.ts"
click node_brain "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/agents/clone-brain.ts"
click node_collab "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/agents/collaboration.ts"
click node_memory "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/backend/memory/index.ts"
click node_clone_repo "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/backend/memory/clone-repository.ts"
click node_database "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/core/supabase/server.ts"
click node_ingest "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/ingest/route.ts"
click node_synthetic "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/ingest/synthetic/route.ts"
click node_integrations_api "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/integrations/route.ts"
click node_connectors "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/integrations/index.ts"
click node_slack "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/slack/events/route.ts"
click node_teams "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/teams/events/route.ts"
click node_teams_api "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/integrations/teams.ts"
click node_insights "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/insights/route.ts"
click node_onboarding "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/onboarding/route.ts"
click node_offboarding "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/offboarding/route.ts"
click node_documents "https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/documents/route.ts"

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_web,node_chatapi,node_twchat toneBlue
class node_brain,node_collab toneAmber
class node_memory,node_clone_repo,node_database,node_ingest,node_synthetic,node_integrations_api,node_connectors toneMint
class node_slack,node_teams,node_teams_api toneRose
class node_insights,node_onboarding,node_offboarding,node_documents,node_employee,node_model,node_enterprise_sources,node_slack_service,node_teams_service toneIndigo
```

## Components

### Web Product

- [TwinOps Web UI](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/(app)/dashboard/page.tsx): `app/(app)/dashboard/page.tsx`
- [Clone Chat API](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/chat/route.ts): `app/api/chat/route.ts`
- [TwinOps Chat API](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/chat/route.ts): `app/api/twinops/chat/route.ts`

### Twin Reasoning

- [Clone Brain](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/agents/clone-brain.ts): `lib/agents/clone-brain.ts`
- [Agent Collaboration](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/agents/collaboration.ts): `lib/agents/collaboration.ts`

### Knowledge Pipeline

- [Memory Services](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/backend/memory/index.ts): `backend/memory/index.ts`
- [Clone Repository](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/backend/memory/clone-repository.ts): `backend/memory/clone-repository.ts`
- [Supabase PostgreSQL](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/core/supabase/server.ts): `lib/core/supabase/server.ts`
- [Document Ingestion](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/ingest/route.ts): `app/api/ingest/route.ts`
- [Synthetic Ingestion](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/ingest/synthetic/route.ts): `app/api/ingest/synthetic/route.ts`
- [Integration Sync API](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/integrations/route.ts): `app/api/integrations/route.ts`
- [Source Connectors](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/integrations/index.ts): `lib/integrations/index.ts`

### Enterprise Channels

- [Slack Events](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/slack/events/route.ts): `app/api/slack/events/route.ts`
- [Teams Events](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/teams/events/route.ts): `app/api/teams/events/route.ts`
- [Teams Connector](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/lib/integrations/teams.ts): `lib/integrations/teams.ts`

### Workforce Operations

- [Organization Insights](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/insights/route.ts): `app/api/twinops/insights/route.ts`
- [Onboarding Brief](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/onboarding/route.ts): `app/api/twinops/onboarding/route.ts`
- [Offboarding Handoff](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/offboarding/route.ts): `app/api/twinops/offboarding/route.ts`
- [Memory Explorer](https://github.com/mohammadali-2000/twinops-enterprise/blob/main/app/api/twinops/documents/route.ts): `app/api/twinops/documents/route.ts`

### Other components

- **Employee**
- **OpenAI**
- **Enterprise Systems**
- **Slack**
- **Microsoft Teams**

## Connections

- Employee → TwinOps Web UI: uses
- TwinOps Web UI → Clone Chat API: sends chat
- Clone Chat API → Clone Repository: loads clone
- Clone Chat API → Memory Services: retrieves context
- Clone Chat API → Clone Brain: builds prompt
- Clone Chat API → Agent Collaboration: consults clone
- Clone Chat API → OpenAI: generates response
- Clone Chat API → Memory Services: learns from chat
- TwinOps Chat API → Supabase PostgreSQL: reads clone and memories
- TwinOps Chat API → OpenAI: streams response
- Document Ingestion → Supabase PostgreSQL: writes document
- Synthetic Ingestion → Supabase PostgreSQL: writes memories
- Synthetic Ingestion → OpenAI: creates embeddings
- Integration Sync API → Source Connectors: starts sync
- Source Connectors → Enterprise Systems: fetches records
- Integration Sync API → Supabase PostgreSQL: reads configuration
- Slack → Slack Events: sends events
- Slack Events → Supabase PostgreSQL: stores message memories
- Slack Events → OpenAI: embeds message
- Slack Events → Memory Services: learns facts
- Microsoft Teams → Teams Events: sends queries
- Teams Events → Supabase PostgreSQL: stores and searches
- Teams Events → Memory Services: searches fallback
- Teams Events → Teams Connector: sends reply card
- Teams Connector → Microsoft Teams: delivers card
- Organization Insights → Supabase PostgreSQL: queries memories
- Organization Insights → OpenAI: summarizes findings
- Onboarding Brief → Supabase PostgreSQL: reads clone context
- Offboarding Handoff → Supabase PostgreSQL: reads memories and clones
- Memory Explorer → Supabase PostgreSQL: queries documents
