# sahilmor/zenith architecture

> Architecture diagram of the GitHub repository sahilmor/zenith, 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/sahilmor/zenith
- Repository: https://github.com/sahilmor/zenith

## Overview

#### Purpose and topology
This Turborepo monorepo delivers a multi-tenant project-management SaaS: a Next.js browser app, an Express/MongoDB API, and Socket.io collaboration. Shared TypeScript contracts, configuration, UI utilities, and generic utilities live in `packages/`. Primary entry points are `apps/web/src/app/layout.tsx`, `apps/server/src/index.ts`, and server composition in `apps/server/src/app.ts`.

#### Runtime and deployment boundary
The web app uses Next.js 15 App Router/React 19 and is deployable to Vercel; the API runs Node.js 22/Express and can run on Railway, Render, or Docker. MongoDB Atlas is the system of record via `apps/server/src/db/connection.ts`. Container topology is defined in `docker-compose.yml`, `docker/server.Dockerfile`, and `docker/web.Dockerfile`. External integrations include Cloudinary uploads, SMTP/Resend email, Stripe billing, and selectable OpenAI/Anthropic/Gemini AI providers.

#### HTTP API pipeline and security
Express initializes environment, database, routing, middleware, and Socket.io. Requests pass centralized security, request context/logging, authentication, API-key, workspace-RBAC, upload, validation, and error boundaries in `apps/server/src/middleware/`. Routes are composed from `apps/server/src/routes/index.ts`; health is isolated in `apps/server/src/routes/health.routes.ts`. Feature APIs consistently follow route → controller → service → repository/model, with validation at the HTTP edge. JWT access tokens and HTTP-only refresh cookies are handled by auth services and middleware.

#### Workspace ownership and core work management
Workspaces establish tenant membership and role authorization; projects, boards/columns, and tasks inherit workspace scope. Core domains are implemented in `apps/server/src/features/workspaces/services/workspace.service.ts`, `apps/server/src/features/projects/services/project.service.ts`, and `apps/server/src/features/boards/services/board.service.ts`. Task lifecycle, ordering, bulk updates, and collaboration are centered in `apps/server/src/features/tasks/services/task.service.ts` and `apps/server/src/features/tasks/services/task-collaboration.service.ts`. Mongo models preserve ownership and archival state; REST is authoritative for mutations.

#### Product extensions and derived views
Analytics derive reports and dashboard metrics from existing operational records rather than duplicate task data: `apps/server/src/features/analytics/services/analytics.service.ts`. Strategic planning links goals, key results, initiatives, portfolios, projects, and tasks: `apps/server/src/features/strategic/services/strategic.service.ts`. Customization contributes workspace-scoped fields, workflows, forms, and templates: `apps/server/src/features/customization/services/customization.service.ts`. Documents, CRM, resource management, search, and notifications are independent feature modules under `apps/server/src/features/`.

#### AI, billing, and operations adapters
AI business logic depends on a provider interface/registry rather than a vendor SDK: `apps/server/src/features/ai/providers/ai-provider.ts`, `apps/server/src/features/ai/providers/provider-registry.ts`, and `apps/server/src/features/ai/services/automation.service.ts`. Billing similarly uses local or Stripe adapters, webhook processing, subscriptions, usage, and entitlement enforcement: `apps/server/src/features/billing/providers/stripe-billing.provider.ts`, `apps/server/src/features/billing/services/billing-webhook.service.ts`, and `apps/server/src/features/billing/services/entitlement.service.ts`. Operations manages audit logs, feature flags, jobs, outbound signed webhooks, and scoped API keys in `apps/server/src/features/ops/services/`.

#### Frontend data, state, and realtime flow
App-wide providers establish query caching, auth, selected workspace, theme, and toasts in `apps/web/src/providers/app-providers.tsx`. Feature hooks call the centralized API client, which attaches tokens, refreshes on expiry, and normalizes errors: `apps/web/src/lib/api/client.ts`; dashboard routes compose feature consoles and views under `apps/web/src/app/dashboard/`. Socket.io is notification/reconciliation transport, not the source of truth: server authorization, rooms, and emitters reside in `apps/server/src/sockets/`, while `apps/web/src/features/realtime/realtime-provider.tsx` reconnects authenticated clients and drives query refetch/reconciliation. Task drag-and-drop optimistically updates client caches before REST reorder persistence.

Main entry points: [`apps/server/src/routes/index.ts`](https://github.com/sahilmor/zenith/blob/main/apps/server/src/routes/index.ts) (Route composition), [`apps/server/src/app.ts`](https://github.com/sahilmor/zenith/blob/main/apps/server/src/app.ts) (Express composition), [`apps/server/src/features/tasks/services/task.service.ts`](https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/tasks/services/task.service.ts) (Task lifecycle), [`apps/web/src/providers/app-providers.tsx`](https://github.com/sahilmor/zenith/blob/main/apps/web/src/providers/app-providers.tsx) (App providers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js web app"]
  node_web_layout["App Router shell<br/>Next.js entry<br/>[layout.tsx]"]
  node_web_providers["App providers<br/>client state<br/>[app-providers.tsx]"]
  node_dashboard["Dashboard consoles<br/>feature views<br/>[page.tsx]"]
  node_api_client["API client<br/>HTTP client<br/>[client.ts]"]
  node_realtime_client["Realtime provider<br/>Socket.io client"]
end

subgraph group_api["Express API"]
  node_server_entry["Server bootstrap<br/>Node.js entry<br/>[index.ts]"]
  node_server_app["Express composition<br/>[app.ts]"]
  node_http_pipeline["Security &amp; HTTP boundary<br/>middleware"]
  node_routes["Route composition<br/>REST routes<br/>[index.ts]"]
  node_health["Health endpoint<br/>operations route<br/>[health.routes.ts]"]
  node_sockets["Realtime server<br/>Socket.io<br/>[index.ts]"]
end

subgraph group_domains["Core domains"]
  node_workspace_projects["Workspace &amp; project services<br/>tenant domain"]
  node_boards["Board service<br/>work domain<br/>[board.service.ts]"]
  node_tasks["Task lifecycle<br/>work domain<br/>[task.service.ts]"]
  node_task_collaboration["Task collaboration<br/>realtime domain"]
  node_derived_extensions["Derived &amp; extension features<br/>feature modules"]
end

subgraph group_adapters["Adapters &amp; operations"]
  node_ai_billing_ops["AI, billing &amp; operations<br/>adapter-backed modules"]
  node_mongodb[("MongoDB Atlas<br/>system of record<br/>[connection.ts]")]
  node_external_services{{"External providers<br/>integrations"}}
end

node_web_layout -->|"wraps"| node_web_providers
node_web_providers -->|"provides state"| node_dashboard
node_dashboard -->|"REST mutations and queries"| node_api_client
node_web_providers -->|"supplies auth/workspace"| node_realtime_client
node_api_client -->|"HTTPS"| node_server_app
node_realtime_client -->|"Socket.io"| node_sockets
node_server_entry -->|"starts"| node_server_app
node_server_app -->|"applies"| node_http_pipeline
node_http_pipeline -->|"authorized requests"| node_routes
node_server_app -->|"exposes"| node_health
node_routes -->|"tenant and project APIs"| node_workspace_projects
node_routes -->|"board APIs"| node_boards
node_routes -->|"task APIs"| node_tasks
node_tasks -->|"publishes lifecycle changes"| node_task_collaboration
node_task_collaboration -->|"emits reconciliation events"| node_sockets
node_workspace_projects -->|"workspace scope"| node_boards
node_boards -->|"columns and ordering"| node_tasks
node_routes -->|"extension APIs"| node_derived_extensions
node_routes -->|"adapter-backed APIs"| node_ai_billing_ops
node_workspace_projects -->|"persists"| node_mongodb
node_tasks -->|"persists authoritative state"| node_mongodb
node_derived_extensions -.->|"derives from records"| node_mongodb
node_ai_billing_ops -->|"vendor adapters"| node_external_services

click node_web_layout "https://github.com/sahilmor/zenith/blob/main/apps/web/src/app/layout.tsx"
click node_web_providers "https://github.com/sahilmor/zenith/blob/main/apps/web/src/providers/app-providers.tsx"
click node_dashboard "https://github.com/sahilmor/zenith/blob/main/apps/web/src/app/dashboard/page.tsx"
click node_api_client "https://github.com/sahilmor/zenith/blob/main/apps/web/src/lib/api/client.ts"
click node_realtime_client "https://github.com/sahilmor/zenith/blob/main/apps/web/src/features/realtime/realtime-provider.tsx"
click node_server_entry "https://github.com/sahilmor/zenith/blob/main/apps/server/src/index.ts"
click node_server_app "https://github.com/sahilmor/zenith/blob/main/apps/server/src/app.ts"
click node_http_pipeline "https://github.com/sahilmor/zenith/blob/main/apps/server/src/middleware/security.middleware.ts"
click node_routes "https://github.com/sahilmor/zenith/blob/main/apps/server/src/routes/index.ts"
click node_health "https://github.com/sahilmor/zenith/blob/main/apps/server/src/routes/health.routes.ts"
click node_sockets "https://github.com/sahilmor/zenith/blob/main/apps/server/src/sockets/index.ts"
click node_workspace_projects "https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/workspaces/services/workspace.service.ts"
click node_boards "https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/boards/services/board.service.ts"
click node_tasks "https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/tasks/services/task.service.ts"
click node_task_collaboration "https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/tasks/services/task-collaboration.service.ts"
click node_derived_extensions "https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/analytics/services/analytics.service.ts"
click node_ai_billing_ops "https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/ai/providers/provider-registry.ts"
click node_mongodb "https://github.com/sahilmor/zenith/blob/main/apps/server/src/db/connection.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_layout,node_web_providers,node_dashboard,node_api_client,node_realtime_client toneBlue
class node_server_entry,node_server_app,node_http_pipeline,node_routes,node_health,node_sockets toneAmber
class node_workspace_projects,node_boards,node_tasks,node_task_collaboration,node_derived_extensions toneMint
class node_ai_billing_ops,node_mongodb,node_external_services toneRose
```

## Components

### Next.js web app

- [App Router shell](https://github.com/sahilmor/zenith/blob/main/apps/web/src/app/layout.tsx): Next.js entry · `apps/web/src/app/layout.tsx`
- [App providers](https://github.com/sahilmor/zenith/blob/main/apps/web/src/providers/app-providers.tsx): client state · Auth, workspace, query cache, theme, and toasts. · `apps/web/src/providers/app-providers.tsx`
- [Dashboard consoles](https://github.com/sahilmor/zenith/blob/main/apps/web/src/app/dashboard/page.tsx): feature views · `apps/web/src/app/dashboard/page.tsx`
- [API client](https://github.com/sahilmor/zenith/blob/main/apps/web/src/lib/api/client.ts): HTTP client · Attaches tokens, refreshes sessions, and normalizes errors. · `apps/web/src/lib/api/client.ts`
- [Realtime provider](https://github.com/sahilmor/zenith/blob/main/apps/web/src/features/realtime/realtime-provider.tsx): Socket.io client · Reconciles cached views after authenticated reconnects. · `apps/web/src/features/realtime/realtime-provider.tsx`

### Express API

- [Server bootstrap](https://github.com/sahilmor/zenith/blob/main/apps/server/src/index.ts): Node.js entry · `apps/server/src/index.ts`
- [Express composition](https://github.com/sahilmor/zenith/blob/main/apps/server/src/app.ts): application · Initializes environment, database, middleware, routes, and Socket.io. · `apps/server/src/app.ts`
- [Security & HTTP boundary](https://github.com/sahilmor/zenith/blob/main/apps/server/src/middleware/security.middleware.ts): middleware · Context, auth, API keys, RBAC, uploads, validation, and errors. · `apps/server/src/middleware/security.middleware.ts`
- [Route composition](https://github.com/sahilmor/zenith/blob/main/apps/server/src/routes/index.ts): REST routes · `apps/server/src/routes/index.ts`
- [Health endpoint](https://github.com/sahilmor/zenith/blob/main/apps/server/src/routes/health.routes.ts): operations route · `apps/server/src/routes/health.routes.ts`
- [Realtime server](https://github.com/sahilmor/zenith/blob/main/apps/server/src/sockets/index.ts): Socket.io · Authorizes rooms and emits collaboration notifications. · `apps/server/src/sockets/index.ts`

### Core domains

- [Workspace & project services](https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/workspaces/services/workspace.service.ts): tenant domain · Membership, roles, workspace scope, and projects. · `apps/server/src/features/workspaces/services/workspace.service.ts`
- [Board service](https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/boards/services/board.service.ts): work domain · Workspace-scoped boards and columns. · `apps/server/src/features/boards/services/board.service.ts`
- [Task lifecycle](https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/tasks/services/task.service.ts): work domain · Authoritative task mutations, ordering, and bulk updates. · `apps/server/src/features/tasks/services/task.service.ts`
- [Task collaboration](https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/tasks/services/task-collaboration.service.ts): realtime domain · `apps/server/src/features/tasks/services/task-collaboration.service.ts`
- [Derived & extension features](https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/analytics/services/analytics.service.ts): feature modules · Analytics, strategy, customization, documents, CRM, resources, search, and notifications. · `apps/server/src/features/analytics/services/analytics.service.ts`

### Adapters & operations

- [AI, billing & operations](https://github.com/sahilmor/zenith/blob/main/apps/server/src/features/ai/providers/provider-registry.ts): adapter-backed modules · Provider registry, billing webhooks and entitlements, audit, jobs, flags, and webhooks. · `apps/server/src/features/ai/providers/provider-registry.ts`
- [MongoDB Atlas](https://github.com/sahilmor/zenith/blob/main/apps/server/src/db/connection.ts): system of record · Operational records, ownership, and archival state. · `apps/server/src/db/connection.ts`
- **External providers**: integrations · Cloudinary, SMTP/Resend, Stripe, and AI vendors.

## Connections

- App Router shell → App providers: wraps
- App providers → Dashboard consoles: provides state
- Dashboard consoles → API client: REST mutations and queries
- App providers → Realtime provider: supplies auth/workspace
- API client → Express composition: HTTPS
- Realtime provider → Realtime server: Socket.io
- Server bootstrap → Express composition: starts
- Express composition → Security & HTTP boundary: applies
- Security & HTTP boundary → Route composition: authorized requests
- Express composition → Health endpoint: exposes
- Route composition → Workspace & project services: tenant and project APIs
- Route composition → Board service: board APIs
- Route composition → Task lifecycle: task APIs
- Task lifecycle → Task collaboration: publishes lifecycle changes
- Task collaboration → Realtime server: emits reconciliation events
- Workspace & project services → Board service: workspace scope
- Board service → Task lifecycle: columns and ordering
- Route composition → Derived & extension features: extension APIs
- Route composition → AI, billing & operations: adapter-backed APIs
- Workspace & project services → MongoDB Atlas: persists
- Task lifecycle → MongoDB Atlas: persists authoritative state
- Derived & extension features → MongoDB Atlas: derives from records
- AI, billing & operations → External providers: vendor adapters
