# shankar7055/cognify architecture

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

- Interactive diagram: https://gitdiagram.com/shankar7055/cognify
- Repository: https://github.com/shankar7055/cognify

## Overview

#### 1. System Purpose and Entry Points
Cognify is a SaaS AI-operations platform for team-scoped workflow automation, multi-agent chat, document/vector memory, collaboration, analytics, and subscription billing. It is a split React SPA and Express API/worker system.
- Client bootstrap and route composition: `cognify-client/src/main.tsx`, `cognify-client/src/App.tsx`
- Server bootstrap/application wiring: `cognify-server/src/server.ts`, `cognify-server/src/app.ts`

#### 2. Frontend Application Surfaces
The Vite/React/TypeScript client separates public marketing/auth screens from the authenticated operational dashboard. Dashboard pages expose the platform domains—chat, agents, workflows, files, memory, teams, integrations, analytics, billing, and settings.
- Dashboard shell and domain routes: `cognify-client/src/pages/dashboard/DashboardLayout.tsx`, `cognify-client/src/pages/dashboard/ExecutiveDashboard.tsx`
- AI chat composition: `cognify-client/src/pages/dashboard/AIChat.tsx`, `cognify-client/src/pages/dashboard/chat/ChatMain.tsx`
- Browser-to-API boundary: `cognify-client/src/utils/api.ts`

#### 3. HTTP API, Identity, and Workspace Boundary
Express routes organize the API by product domain. Requests pass through authentication, validation/rate limiting, feature gates, API-key checks where applicable, and workspace membership authorization before services access tenant-owned data.
- Route boundary: `cognify-server/src/routes/chat.routes.ts`, `cognify-server/src/routes/workflows.routes.ts`, `cognify-server/src/routes/workspace.routes.ts`
- Cross-cutting authorization: `cognify-server/src/middleware/auth.middleware.ts`, `cognify-server/src/middleware/workspaceAccess.middleware.ts`, `cognify-server/src/middleware/apiKey.middleware.ts`
- Auth and workspace domain logic: `cognify-server/src/services/auth/auth.service.ts`, `cognify-server/src/services/workspace/workspace.service.ts`

#### 4. Persistent Tenant Data and Storage
PostgreSQL, accessed through Prisma, is the system of record for users, workspaces, memberships, files, AI requests, embeddings, API keys, subscriptions, messages, prompts, and costs. File handling forms a separate storage/ingestion boundary backed by S3-compatible configuration.
- Schema and evolution: `cognify-server/prisma/schema.prisma`, `cognify-server/prisma/migrations/`
- Storage pipeline: `cognify-server/src/services/storage/s3.service.ts`, `cognify-server/src/services/storage/fileParser.service.ts`
- Infrastructure clients: `cognify-server/src/config/db.ts`, `cognify-server/src/config/s3.ts`

#### 5. AI Execution and Memory Pipeline
Chat or agent requests are routed through an AI manager/model and agent router to specialized or autonomous agents. Provider adapters isolate external model APIs; tool routing exposes controlled capabilities. Embedding/vector-memory services support semantic retrieval over ingested workspace material, while streaming delivers incremental responses.
- Orchestration: `cognify-server/src/services/ai/aiManager.service.ts`, `cognify-server/src/services/ai/agentRouter.service.ts`, `cognify-server/src/services/ai/modelRouter.service.ts`
- Providers and agents: `cognify-server/src/services/ai/providers/`, `cognify-server/src/services/ai/agents/`
- Retrieval/stream boundary: `cognify-server/src/services/ai/embedding.service.ts`, `cognify-server/src/services/ai/vectorMemory.service.ts`, `cognify-server/src/services/ai/stream.service.ts`

#### 6. Async Automation, Analytics, and Notifications
Redis/BullMQ decouples long-running AI work, workflow execution, usage aggregation, and email delivery from HTTP requests. Workflow services define triggers and step execution; workers consume queued jobs. Socket and email services provide user-facing asynchronous notifications.
- Queues/workers: `cognify-server/src/queues/aiQueue.ts`, `cognify-server/src/queues/workers/workflow.worker.ts`, `cognify-server/src/config/redis.ts`
- Automation engine: `cognify-server/src/services/automation/workflow.service.ts`, `cognify-server/src/services/automation/triggerEngine.service.ts`
- Analytics/notifications: `cognify-server/src/services/analytics/usage.service.ts`, `cognify-server/src/services/notification/socket.service.ts`

#### 7. Commercial Integrations and Deployment
Billing routes/services mediate Stripe subscriptions/webhooks and Razorpay configuration. The service runs on Node.js with PostgreSQL, Redis, S3, external AI providers, Stripe, Razorpay, and integrations for Slack, Notion, and Sheets. Production supports Docker Compose and PM2 clustered deployment; the SPA has Vercel configuration.
- Billing boundary: `cognify-server/src/services/billing/stripe.service.ts`, `cognify-server/src/services/billing/webhook.service.ts`, `cognify-server/src/config/razorpay.ts`
- Third-party integrations: `cognify-server/src/services/integrations/slack.service.ts`, `cognify-server/src/services/integrations/notion.service.ts`
- Runtime/deployment: `cognify-server/Dockerfile`, `cognify-server/docker-compose.yml`, `cognify-server/ecosystem.config.js`, `cognify-client/vercel.json`

Main entry points: [`cognify-server/src/routes/chat.routes.ts`](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/routes/chat.routes.ts) (Domain routes), [`cognify-server/src/services/ai/aiManager.service.ts`](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/ai/aiManager.service.ts) (AI orchestration), [`cognify-server/src/queues/aiQueue.ts`](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/queues/aiQueue.ts) (BullMQ queues), [`cognify-server/src/queues/workers/workflow.worker.ts`](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/queues/workers/workflow.worker.ts) (Queue workers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React SPA"]
  node_client_bootstrap["Client bootstrap<br/>Vite React entry<br/>[main.tsx]"]
  node_dashboard["Dashboard surfaces<br/>React routes"]
  node_client_api["API client<br/>browser API boundary<br/>[api.ts]"]
end

subgraph group_api["Node API"]
  node_server["Express application<br/>HTTP API<br/>[app.ts]"]
  node_routes["Domain routes<br/>route layer<br/>[chat.routes.ts]"]
  node_access["Tenant access controls<br/>middleware"]
  node_workspace["Auth and workspace<br/>domain services"]
  node_ai_manager["AI orchestration<br/>AI manager and router"]
  node_memory["Vector memory and streaming<br/>retrieval service"]
  node_storage["File ingestion<br/>S3 and parser services"]
end

subgraph group_async["Async processing"]
  node_workflow["Workflow engine<br/>automation service"]
  node_queues["BullMQ queues<br/>job queues<br/>[aiQueue.ts]"]
  node_workers["Queue workers<br/>background workers<br/>[workflow.worker.ts]"]
  node_notifications["Usage and notifications<br/>analytics and socket services<br/>[socket.service.ts]"]
end

subgraph group_data["Tenant data"]
  node_postgres[("PostgreSQL tenant record<br/>Prisma database<br/>[schema.prisma]")]
  node_redis[("Redis<br/>queue backend<br/>[redis.ts]")]
end

subgraph group_external["External services"]
  node_model_providers{{"AI model providers<br/>external AI APIs<br/>[base.providers.ts]"}}
  node_billing{{"Billing providers<br/>Stripe and Razorpay<br/>[stripe.service.ts]"}}
  node_integrations{{"Collaboration integrations<br/>Slack and Notion<br/>[slack.service.ts]"}}
end

node_client_bootstrap -->|"renders"| node_dashboard
node_dashboard -->|"calls"| node_client_api
node_client_api -->|"HTTPS"| node_server
node_server -->|"mounts"| node_routes
node_routes -->|"enforces access"| node_access
node_access -->|"authorizes tenant"| node_workspace
node_workspace -->|"reads and writes"| node_postgres
node_routes -->|"chat and agent requests"| node_ai_manager
node_ai_manager -->|"retrieves context"| node_memory
node_memory -->|"stores embeddings"| node_postgres
node_ai_manager -->|"invokes models"| node_model_providers
node_routes -->|"file requests"| node_storage
node_storage -->|"ingested content"| node_memory
node_routes -->|"workflow requests"| node_workflow
node_workflow -->|"enqueues execution"| node_queues
node_ai_manager -->|"enqueues long jobs"| node_queues
node_queues -->|"uses"| node_redis
node_workers -->|"consumes"| node_queues
node_workers -->|"executes"| node_workflow
node_workers -->|"emits updates"| node_notifications
node_notifications -->|"records usage"| node_postgres
node_routes -->|"subscription and webhooks"| node_billing
node_routes -->|"connects"| node_integrations

click node_client_bootstrap "https://github.com/shankar7055/cognify/blob/main/cognify-client/src/main.tsx"
click node_dashboard "https://github.com/shankar7055/cognify/blob/main/cognify-client/src/pages/dashboard/DashboardLayout.tsx"
click node_client_api "https://github.com/shankar7055/cognify/blob/main/cognify-client/src/utils/api.ts"
click node_server "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/app.ts"
click node_routes "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/routes/chat.routes.ts"
click node_access "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/middleware/workspaceAccess.middleware.ts"
click node_workspace "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/workspace/workspace.service.ts"
click node_ai_manager "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/ai/aiManager.service.ts"
click node_memory "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/ai/vectorMemory.service.ts"
click node_storage "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/storage/fileParser.service.ts"
click node_workflow "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/automation/workflow.service.ts"
click node_queues "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/queues/aiQueue.ts"
click node_workers "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/queues/workers/workflow.worker.ts"
click node_notifications "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/notification/socket.service.ts"
click node_postgres "https://github.com/shankar7055/cognify/blob/main/cognify-server/prisma/schema.prisma"
click node_redis "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/config/redis.ts"
click node_model_providers "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/ai/providers/base.providers.ts"
click node_billing "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/billing/stripe.service.ts"
click node_integrations "https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/integrations/slack.service.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_client_bootstrap,node_dashboard,node_client_api toneBlue
class node_server,node_routes,node_access,node_workspace,node_ai_manager,node_memory,node_storage toneAmber
class node_workflow,node_queues,node_workers,node_notifications toneMint
class node_postgres,node_redis toneRose
class node_model_providers,node_billing,node_integrations toneIndigo
```

## Components

### React SPA

- [Client bootstrap](https://github.com/shankar7055/cognify/blob/main/cognify-client/src/main.tsx): Vite React entry · `cognify-client/src/main.tsx`
- [Dashboard surfaces](https://github.com/shankar7055/cognify/blob/main/cognify-client/src/pages/dashboard/DashboardLayout.tsx): React routes · Chat, agents, workflows, files, memory, teams, analytics, and billing. · `cognify-client/src/pages/dashboard/DashboardLayout.tsx`
- [API client](https://github.com/shankar7055/cognify/blob/main/cognify-client/src/utils/api.ts): browser API boundary · `cognify-client/src/utils/api.ts`

### Node API

- [Express application](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/app.ts): HTTP API · `cognify-server/src/app.ts`
- [Domain routes](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/routes/chat.routes.ts): route layer · Serves chat, workflow, and workspace product APIs. · `cognify-server/src/routes/chat.routes.ts`
- [Tenant access controls](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/middleware/workspaceAccess.middleware.ts): middleware · Authenticates callers and enforces workspace membership or API-key access. · `cognify-server/src/middleware/workspaceAccess.middleware.ts`
- [Auth and workspace](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/workspace/workspace.service.ts): domain services · `cognify-server/src/services/workspace/workspace.service.ts`
- [AI orchestration](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/ai/aiManager.service.ts): AI manager and router · Routes chat and agent work to models, agents, and tools. · `cognify-server/src/services/ai/aiManager.service.ts`
- [Vector memory and streaming](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/ai/vectorMemory.service.ts): retrieval service · Retrieves workspace context and streams model output. · `cognify-server/src/services/ai/vectorMemory.service.ts`
- [File ingestion](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/storage/fileParser.service.ts): S3 and parser services · Stores files and parses source material for memory. · `cognify-server/src/services/storage/fileParser.service.ts`

### Async processing

- [Workflow engine](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/automation/workflow.service.ts): automation service · Defines triggers and executes workflow steps. · `cognify-server/src/services/automation/workflow.service.ts`
- [BullMQ queues](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/queues/aiQueue.ts): job queues · Decouples AI, workflows, usage aggregation, and email work. · `cognify-server/src/queues/aiQueue.ts`
- [Queue workers](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/queues/workers/workflow.worker.ts): background workers · `cognify-server/src/queues/workers/workflow.worker.ts`
- [Usage and notifications](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/notification/socket.service.ts): analytics and socket services · `cognify-server/src/services/notification/socket.service.ts`

### Tenant data

- [PostgreSQL tenant record](https://github.com/shankar7055/cognify/blob/main/cognify-server/prisma/schema.prisma): Prisma database · System of record for tenant data, messages, embeddings, subscriptions, and costs. · `cognify-server/prisma/schema.prisma`
- [Redis](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/config/redis.ts): queue backend · `cognify-server/src/config/redis.ts`

### External services

- [AI model providers](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/ai/providers/base.providers.ts): external AI APIs · `cognify-server/src/services/ai/providers/base.providers.ts`
- [Billing providers](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/billing/stripe.service.ts): Stripe and Razorpay · Subscriptions and webhook processing. · `cognify-server/src/services/billing/stripe.service.ts`
- [Collaboration integrations](https://github.com/shankar7055/cognify/blob/main/cognify-server/src/services/integrations/slack.service.ts): Slack and Notion · `cognify-server/src/services/integrations/slack.service.ts`

## Connections

- Client bootstrap → Dashboard surfaces: renders
- Dashboard surfaces → API client: calls
- API client → Express application: HTTPS
- Express application → Domain routes: mounts
- Domain routes → Tenant access controls: enforces access
- Tenant access controls → Auth and workspace: authorizes tenant
- Auth and workspace → PostgreSQL tenant record: reads and writes
- Domain routes → AI orchestration: chat and agent requests
- AI orchestration → Vector memory and streaming: retrieves context
- Vector memory and streaming → PostgreSQL tenant record: stores embeddings
- AI orchestration → AI model providers: invokes models
- Domain routes → File ingestion: file requests
- File ingestion → Vector memory and streaming: ingested content
- Domain routes → Workflow engine: workflow requests
- Workflow engine → BullMQ queues: enqueues execution
- AI orchestration → BullMQ queues: enqueues long jobs
- BullMQ queues → Redis: uses
- Queue workers → BullMQ queues: consumes
- Queue workers → Workflow engine: executes
- Queue workers → Usage and notifications: emits updates
- Usage and notifications → PostgreSQL tenant record: records usage
- Domain routes → Billing providers: subscription and webhooks
- Domain routes → Collaboration integrations: connects
