How sahilmor/zenith works
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: index.ts Route composition · app.ts Express composition · task.service.ts Task lifecycle · app-providers.tsx App providers
Components 19
Next.js web app
- App Router shell
apps/web/src/app/layout.tsx - App providers · Auth, workspace, query cache, theme, and toasts.
apps/web/src/providers/app-providers.tsx - Dashboard consoles
apps/web/src/app/dashboard/page.tsx - API client · Attaches tokens, refreshes sessions, and normalizes errors.
apps/web/src/lib/api/client.ts - Realtime provider · Reconciles cached views after authenticated reconnects.
apps/web/src/features/realtime/realtime-provider.tsx
Express API
- Server bootstrap
apps/server/src/index.ts - Express composition · Initializes environment, database, middleware, routes, and Socket.io.
apps/server/src/app.ts - Security & HTTP boundary · Context, auth, API keys, RBAC, uploads, validation, and errors.
apps/server/src/middleware/security.middleware.ts - Route composition
apps/server/src/routes/index.ts - Health endpoint
apps/server/src/routes/health.routes.ts - Realtime server · Authorizes rooms and emits collaboration notifications.
apps/server/src/sockets/index.ts
Core domains
- Workspace & project services · Membership, roles, workspace scope, and projects.
apps/server/src/features/workspaces/services/workspace.service.ts - Board service · Workspace-scoped boards and columns.
apps/server/src/features/boards/services/board.service.ts - Task lifecycle · Authoritative task mutations, ordering, and bulk updates.
apps/server/src/features/tasks/services/task.service.ts - Task collaboration
apps/server/src/features/tasks/services/task-collaboration.service.ts - Derived & extension features · Analytics, strategy, customization, documents, CRM, resources, search, and notifications.
apps/server/src/features/analytics/services/analytics.service.ts
Adapters & operations
- AI, billing & operations · Provider registry, billing webhooks and entitlements, audit, jobs, flags, and webhooks.
apps/server/src/features/ai/providers/provider-registry.ts - MongoDB Atlas · Operational records, ownership, and archival state.
apps/server/src/db/connection.ts - External providers · Cloudinary, SMTP/Resend, Stripe, and AI vendors.
Connections 23
- 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