# anugrah-singh/coordra architecture

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

- Interactive diagram: https://gitdiagram.com/anugrah-singh/coordra
- Repository: https://github.com/anugrah-singh/coordra

## Overview

#### Purpose and Entry Points
Coordra is a multi-tenant project/workspace coordination system with live collaboration and an approval-gated AI assistant (“Pulse”). The backend starts through `src/server.ts`, composing the Express API in `src/app.ts` and Socket.IO in `src/socket.ts`. The browser application is a Next.js App Router frontend rooted at `frontend/src/app/layout.tsx` and `frontend/src/app/page.tsx`.

#### API Boundary and Request Pipeline
Express exposes versioned/domain-organized HTTP endpoints through `src/domains/api.ts`. Each domain separates transport from business logic: routes parse requests and services enforce domain behavior, e.g. `src/domains/workspaces/route.ts`, `src/domains/workspaces/service.ts`, and `src/domains/tasks/service.ts`. Cross-cutting middleware establishes the security and API boundary: authentication, CSRF, validation, RBAC, rate limiting, normalized envelopes, and error handling under `src/middlewares/`.

#### Identity, Tenancy, and Collaboration
Workspace membership and roles are the central authorization model. Authentication is implemented in `src/domains/auth/service.ts`; authorization gates are `src/middlewares/auth.middleware.ts` and `src/middlewares/rbac.middleware.ts`. Workspace ownership, members, invitations, audit events, and notifications are persisted through schemas including `src/db/schema/workspaces.ts`, `src/db/schema/invites.ts`, and `src/db/schema/auditLogs.ts`. Invitation deep links enter through `frontend/src/app/invite/[token]/page.tsx`.

#### Project Delivery Domain
Work is organized as workspace → projects → task boards, with task comments, labels, assignments, dates, and status movement. Backend write/read services are concentrated in `src/domains/projects/service.ts`, `src/domains/tasks/service.ts`, and `src/domains/comments/service.ts`. The primary UI surfaces are workspace/project routes such as `frontend/src/app/app/workspaces/[workspaceId]/projects/[projectId]/page.tsx`, rendered by `frontend/src/features/projects/ProjectBoardPage.tsx` and `frontend/src/features/projects/KanbanBoard.tsx`.

#### Real-Time Consistency and Audit Flow
Socket.IO uses workspace-scoped rooms to broadcast relevant changes after backend mutations; the server boundary is `src/socket.ts`, with shared event definitions in `src/utils/socketEvents.ts`. The frontend subscribes at `frontend/src/features/collaboration/useWorkspaceSocket.ts`, then invalidates/refetches API-backed state rather than treating socket payloads as authoritative. Backend transactional mutation paths are responsible for associated audit history and live emission.

#### Pulse AI: Verified Reads, Proposed Writes
Pulse is a workspace-scoped assistant whose model access is mediated by deterministic tools and resolution logic, not raw database access. The AI layer is `src/ai/provider.ts`, `src/ai/tools.ts`, and `src/ai/risks.ts`; its HTTP/domain orchestration is `src/domains/assistant/service.ts`. It derives risks from verified tenant-scoped data, generates expiring pending action proposals, and requires an explicit, role-checked approval to execute a mutation. Proposal persistence is defined in `src/db/schema/aiActionProposals.ts`; the interactive client is `frontend/src/features/assistant/PulseDrawer.tsx`.

#### Persistence, Runtime, and Deployment
The Node.js/TypeScript API uses PostgreSQL through Drizzle (`src/db/index.ts`, `src/db/schema/index.ts`), with committed SQL migrations in `drizzle/`. The frontend is Next.js/React with Tailwind and is configured for Vercel in `frontend/vercel.json`; backend deployment configuration is `render.yaml`. External services are PostgreSQL/Neon-compatible database hosting, Groq through the Vercel AI SDK, and Socket.IO WebSockets. OpenAPI/Swagger documentation is mounted from `src/docs/openapi.ts`.

Main entry points: [`src/domains/api.ts`](https://github.com/anugrah-singh/coordra/blob/main/src/domains/api.ts) (Domain API routes), [`src/db/index.ts`](https://github.com/anugrah-singh/coordra/blob/main/src/db/index.ts) (PostgreSQL via Drizzle), [`src/app.ts`](https://github.com/anugrah-singh/coordra/blob/main/src/app.ts) (Express API app), [`src/domains/assistant/service.ts`](https://github.com/anugrah-singh/coordra/blob/main/src/domains/assistant/service.ts) (Assistant orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Node API"]
  node_server["Server bootstrap<br/>Node entry point<br/>[server.ts]"]
  node_express_app["Express API app<br/>HTTP composition<br/>[app.ts]"]
  node_api_routes["Domain API routes<br/>versioned HTTP routes<br/>[api.ts]"]
  node_security["Auth and RBAC gates<br/>middleware<br/>[auth.middleware.ts]"]
  node_auth_service["Identity service<br/>auth service<br/>[service.ts]"]
  node_socket_server["Workspace Socket.IO<br/>realtime server<br/>[socket.ts]"]
  node_openapi["OpenAPI docs<br/>API documentation<br/>[openapi.ts]"]
end

subgraph group_frontend["Next.js client"]
  node_next_app["Next.js app shell<br/>frontend entry<br/>[layout.tsx]"]
  node_project_board["Project board<br/>delivery UI"]
  node_workspace_socket["Workspace socket client<br/>realtime hook"]
  node_pulse_drawer["Pulse drawer<br/>assistant UI<br/>[PulseDrawer.tsx]"]
  node_invite_page["Invitation deep link<br/>invite UI<br/>[page.tsx]"]
end

subgraph group_delivery["Delivery domain"]
  node_workspace_service["Workspace membership<br/>workspace service<br/>[service.ts]"]
  node_project_service["Projects service<br/>project service<br/>[service.ts]"]
  node_task_service["Tasks service<br/>task service<br/>[service.ts]"]
  node_comment_service["Comments service<br/>comment service<br/>[service.ts]"]
end

subgraph group_ai["Pulse AI"]
  node_assistant_service["Assistant orchestration<br/>assistant service<br/>[service.ts]"]
  node_pulse_tools["Verified AI tools<br/>AI tool layer<br/>[tools.ts]"]
end

subgraph group_data["Persistence"]
  node_postgres[("PostgreSQL via Drizzle<br/>database access<br/>[index.ts]")]
  node_migrations["SQL migrations<br/>database migrations"]
end

node_server -->|"starts"| node_express_app
node_server -->|"hosts"| node_socket_server
node_express_app -->|"mounts"| node_api_routes
node_express_app -->|"applies"| node_security
node_api_routes -->|"identity requests"| node_auth_service
node_api_routes -->|"workspace requests"| node_workspace_service
node_api_routes -->|"project requests"| node_project_service
node_api_routes -->|"task requests"| node_task_service
node_api_routes -->|"comment requests"| node_comment_service
node_api_routes -->|"Pulse requests"| node_assistant_service
node_express_app -->|"mounts"| node_openapi
node_security -.->|"authorizes by membership"| node_workspace_service
node_workspace_service -->|"persists tenancy"| node_postgres
node_project_service -->|"persists"| node_postgres
node_task_service -->|"persists and audits"| node_postgres
node_comment_service -->|"persists"| node_postgres
node_task_service -->|"emits mutations"| node_socket_server
node_assistant_service -->|"uses verified reads"| node_pulse_tools
node_assistant_service -->|"stores proposals"| node_postgres
node_assistant_service -->|"executes approved actions"| node_task_service
node_migrations -->|"evolves schema"| node_postgres
node_next_app -->|"renders"| node_project_board
node_next_app -->|"routes to"| node_invite_page
node_project_board -->|"reads and mutates"| node_api_routes
node_workspace_socket -->|"subscribes to rooms"| node_socket_server
node_workspace_socket -.->|"refetches state"| node_api_routes
node_pulse_drawer -->|"submits and approves proposals"| node_api_routes

click node_server "https://github.com/anugrah-singh/coordra/blob/main/src/server.ts"
click node_express_app "https://github.com/anugrah-singh/coordra/blob/main/src/app.ts"
click node_api_routes "https://github.com/anugrah-singh/coordra/blob/main/src/domains/api.ts"
click node_security "https://github.com/anugrah-singh/coordra/blob/main/src/middlewares/auth.middleware.ts"
click node_auth_service "https://github.com/anugrah-singh/coordra/blob/main/src/domains/auth/service.ts"
click node_socket_server "https://github.com/anugrah-singh/coordra/blob/main/src/socket.ts"
click node_openapi "https://github.com/anugrah-singh/coordra/blob/main/src/docs/openapi.ts"
click node_workspace_service "https://github.com/anugrah-singh/coordra/blob/main/src/domains/workspaces/service.ts"
click node_project_service "https://github.com/anugrah-singh/coordra/blob/main/src/domains/projects/service.ts"
click node_task_service "https://github.com/anugrah-singh/coordra/blob/main/src/domains/tasks/service.ts"
click node_comment_service "https://github.com/anugrah-singh/coordra/blob/main/src/domains/comments/service.ts"
click node_assistant_service "https://github.com/anugrah-singh/coordra/blob/main/src/domains/assistant/service.ts"
click node_pulse_tools "https://github.com/anugrah-singh/coordra/blob/main/src/ai/tools.ts"
click node_postgres "https://github.com/anugrah-singh/coordra/blob/main/src/db/index.ts"
click node_next_app "https://github.com/anugrah-singh/coordra/blob/main/frontend/src/app/layout.tsx"
click node_project_board "https://github.com/anugrah-singh/coordra/blob/main/frontend/src/features/projects/ProjectBoardPage.tsx"
click node_workspace_socket "https://github.com/anugrah-singh/coordra/blob/main/frontend/src/features/collaboration/useWorkspaceSocket.ts"
click node_pulse_drawer "https://github.com/anugrah-singh/coordra/blob/main/frontend/src/features/assistant/PulseDrawer.tsx"
click node_invite_page "https://github.com/anugrah-singh/coordra/blob/main/frontend/src/app/invite/%5Btoken%5D/page.tsx"

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_express_app,node_api_routes,node_security,node_auth_service,node_socket_server,node_openapi toneBlue
class node_next_app,node_project_board,node_workspace_socket,node_pulse_drawer,node_invite_page toneAmber
class node_workspace_service,node_project_service,node_task_service,node_comment_service toneMint
class node_assistant_service,node_pulse_tools toneRose
class node_postgres,node_migrations toneIndigo
```

## Components

### Node API

Express and Socket.IO runtime.

- [Server bootstrap](https://github.com/anugrah-singh/coordra/blob/main/src/server.ts): Node entry point · `src/server.ts`
- [Express API app](https://github.com/anugrah-singh/coordra/blob/main/src/app.ts): HTTP composition · `src/app.ts`
- [Domain API routes](https://github.com/anugrah-singh/coordra/blob/main/src/domains/api.ts): versioned HTTP routes · `src/domains/api.ts`
- [Auth and RBAC gates](https://github.com/anugrah-singh/coordra/blob/main/src/middlewares/auth.middleware.ts): middleware · Authentication, CSRF, validation, roles, and API protections. · `src/middlewares/auth.middleware.ts`
- [Identity service](https://github.com/anugrah-singh/coordra/blob/main/src/domains/auth/service.ts): auth service · `src/domains/auth/service.ts`
- [Workspace Socket.IO](https://github.com/anugrah-singh/coordra/blob/main/src/socket.ts): realtime server · Broadcasts workspace-scoped mutation events. · `src/socket.ts`
- [OpenAPI docs](https://github.com/anugrah-singh/coordra/blob/main/src/docs/openapi.ts): API documentation · `src/docs/openapi.ts`

### Next.js client

Browser workspace application.

- [Next.js app shell](https://github.com/anugrah-singh/coordra/blob/main/frontend/src/app/layout.tsx): frontend entry · `frontend/src/app/layout.tsx`
- [Project board](https://github.com/anugrah-singh/coordra/blob/main/frontend/src/features/projects/ProjectBoardPage.tsx): delivery UI · Workspace project and Kanban experience. · `frontend/src/features/projects/ProjectBoardPage.tsx`
- [Workspace socket client](https://github.com/anugrah-singh/coordra/blob/main/frontend/src/features/collaboration/useWorkspaceSocket.ts): realtime hook · Invalidates and refetches API state after events. · `frontend/src/features/collaboration/useWorkspaceSocket.ts`
- [Pulse drawer](https://github.com/anugrah-singh/coordra/blob/main/frontend/src/features/assistant/PulseDrawer.tsx): assistant UI · `frontend/src/features/assistant/PulseDrawer.tsx`
- [Invitation deep link](https://github.com/anugrah-singh/coordra/blob/main/frontend/src/app/invite/%5Btoken%5D/page.tsx): invite UI · `frontend/src/app/invite/[token]/page.tsx`

### Delivery domain

Projects, tasks, and comments.

- [Workspace membership](https://github.com/anugrah-singh/coordra/blob/main/src/domains/workspaces/service.ts): workspace service · Owns memberships, roles, and invitations. · `src/domains/workspaces/service.ts`
- [Projects service](https://github.com/anugrah-singh/coordra/blob/main/src/domains/projects/service.ts): project service · `src/domains/projects/service.ts`
- [Tasks service](https://github.com/anugrah-singh/coordra/blob/main/src/domains/tasks/service.ts): task service · Transactional task mutations create audit history and live events. · `src/domains/tasks/service.ts`
- [Comments service](https://github.com/anugrah-singh/coordra/blob/main/src/domains/comments/service.ts): comment service · `src/domains/comments/service.ts`

### Pulse AI

Verified reads and approval-gated writes.

- [Assistant orchestration](https://github.com/anugrah-singh/coordra/blob/main/src/domains/assistant/service.ts): assistant service · Creates proposals and executes only approved actions. · `src/domains/assistant/service.ts`
- [Verified AI tools](https://github.com/anugrah-singh/coordra/blob/main/src/ai/tools.ts): AI tool layer · Resolves tenant-scoped data without raw model database access. · `src/ai/tools.ts`

### Persistence

Tenant-scoped PostgreSQL storage.

- [PostgreSQL via Drizzle](https://github.com/anugrah-singh/coordra/blob/main/src/db/index.ts): database access · Schemas cover workspaces, invites, audit logs, and AI proposals. · `src/db/index.ts`
- **SQL migrations**: database migrations

## Connections

- Server bootstrap → Express API app: starts
- Server bootstrap → Workspace Socket.IO: hosts
- Express API app → Domain API routes: mounts
- Express API app → Auth and RBAC gates: applies
- Domain API routes → Identity service: identity requests
- Domain API routes → Workspace membership: workspace requests
- Domain API routes → Projects service: project requests
- Domain API routes → Tasks service: task requests
- Domain API routes → Comments service: comment requests
- Domain API routes → Assistant orchestration: Pulse requests
- Express API app → OpenAPI docs: mounts
- Auth and RBAC gates → Workspace membership: authorizes by membership
- Workspace membership → PostgreSQL via Drizzle: persists tenancy
- Projects service → PostgreSQL via Drizzle: persists
- Tasks service → PostgreSQL via Drizzle: persists and audits
- Comments service → PostgreSQL via Drizzle: persists
- Tasks service → Workspace Socket.IO: emits mutations
- Assistant orchestration → Verified AI tools: uses verified reads
- Assistant orchestration → PostgreSQL via Drizzle: stores proposals
- Assistant orchestration → Tasks service: executes approved actions
- SQL migrations → PostgreSQL via Drizzle: evolves schema
- Next.js app shell → Project board: renders
- Next.js app shell → Invitation deep link: routes to
- Project board → Domain API routes: reads and mutates
- Workspace socket client → Workspace Socket.IO: subscribes to rooms
- Workspace socket client → Domain API routes: refetches state
- Pulse drawer → Domain API routes: submits and approves proposals
