Skip to main content

Backend Architecture

Repository: equa-server | Stack: Express, TypeORM, PostgreSQL, Node 18, vineyard-lawn

Server Entry Point

Source: equa-server/modules/api/src/server.ts (function startApi(), lines 180-198) The server starts with this sequence:
  1. Create Express app
  2. Enable CORS via enableCors(app) (vineyard-lawn)
  3. Initialize sessions via initializeSessions() (TypeORM session store)
  4. Register Google OAuth redirect endpoint
  5. Register all API endpoints via createEndpoints(app, endpoints) (vineyard-lawn)
  6. Initialize dynamic file serving
  7. Register /health and / ping endpoints
  8. Register 404 handler
  9. Start Express on configured port (default: 3000)

SSL Support

Source: equa-server/modules/api/src/server.ts (function startExpress(), lines 53-98) SSL is optional, activated when API_SSL env var is set. Reads certs from SSL_PRIVATE_KEY_PATH and SSL_PUBLIC_KEY_PATH.

Module Inventory

The backend is organized into 20 modules under equa-server/modules/:
ModuleDirectoryPurpose
apimodules/api/Main Express server, endpoint registration, route definitions
api-helpermodules/api-helper/HTTP handler utilities, response formatting
authmodules/auth/Authentication (password, Google OAuth, magic links), sessions, RBAC
persistencemodules/persistence/TypeORM entities (92), database connection, schema management
organizationsmodules/organizations/Organization CRUD, details, settings
captablemodules/captable/Cap table management, shareholdings, securities
billingmodules/billing/Chargify billing integration, subscriptions
notificationsmodules/notifications/Email via AWS SES / SMTP, Handlebars templates
file-storagemodules/file-storage/AWS S3 file upload/download, Microsoft file storage
doc-genmodules/doc-gen/Document generation (certificates, agreements)
data-roommodules/data-room/Data room access control and file management
google-drivemodules/google-drive/Google Drive OAuth, sync, file operations
microsoftmodules/microsoft/Microsoft Graph integration
adminmodules/admin/Admin-only endpoints
activitymodules/activity/Activity/action logging
agentmodules/agent/AI assistant (Equanaut) — chat, tools, onboarding
referralmodules/referral/Referral system, EquaCash rewards
walletmodules/wallet/Wallet and payment method management
commonmodules/common/Shared types and utilities
ravenmodules/raven/Raven blockchain address management

Endpoint Framework: vineyard-lawn

Endpoints are defined using vineyard-lawn’s type-safe endpoint system. Source: equa-server/modules/api/src/lib/utility.ts (lines 60-94)
// Standard endpoint
defineEndpoint<T>(config)

// Endpoint with permission check
defineRestrictedEndpoint<T>(config)
Each endpoint specifies:
  • HTTP method and path
  • Request/response types
  • Optional requires?: PermissionCheck for authorization
  • Versioning (v1 prefix)

Endpoint Files

Source: equa-server/modules/api/src/endpoints/
FileEndpoint Group
auth-endpoints.tsAuthentication (login, register, verify, OAuth)
organization-endpoints.tsOrganization CRUD, details, settings
captable-endpoints.tsCap table operations, shareholdings
user-endpoints.tsUser management, profile, current user
billing-endpoints.tsBilling, subscriptions, Chargify webhooks
admin-endpoints.tsAdmin-only operations
activity-endpoints.tsActivity logging and retrieval
data-room-endpoints.tsData room access and files
google-drive-endpoints.tsGoogle Drive sync and connection
microsoft-endpoints.tsMicrosoft integration
referral-endpoints.tsReferral system
wallet-endpoint.tsWallet and blockchain operations
color-endpoints.tsUser color preferences
Agent-specific endpoints in equa-server/modules/agent/src/endpoints/:
  • agent-endpoints.ts — Chat, confirmations, context, tools, onboarding

Database Layer

Source: equa-server/modules/persistence/src/site/connecting.ts
PropertyValue
ORMTypeORM
DatabasePostgreSQL (configurable via DATABASE_TYPE)
Entities92 (defined in schema.ts)
Schema syncEnabled in development (NODE_ENV=development && DATABASE_SYNC !== 'false')
Connection configVia environment variables (DATABASE_HOST, DATABASE_USERNAME, etc.)

Entity Registration

Source: equa-server/modules/persistence/src/schema.ts (lines 2008-2101) All 92 entities are registered in the allEntities array and loaded during connection initialization.

Middleware Stack

MiddlewarePurposeSource
CORSCross-origin requestsvineyard-lawn enableCors()
express-sessionSession managementmodules/auth/src/sessions.ts
TypeORM session storeSession persistence in PostgreSQLCustom TypeORMSessionStore
URL-encoded parserGoogle OAuth redirectserver.ts line 143
Error loggingRequest error captureconfigureErrorLogging()
No explicit rate limiting middleware was found in the codebase. This is a gap for production readiness.

Process Architecture

Development

equa-server $ yarn start:dev
→ ts-node modules/api/scripts/api.ts
→ Express on port 3000

Production

Docker (node:18-alpine)
→ PM2 (pm2-runtime)
  → api process (./modules/api/scripts/api.js, port 3000)
  → raven-addresses process (./modules/raven/scripts/user-raven-addresses.js)

Build Pipeline

Source: equa-server/package.json
ScriptCommand
buildyarn tsc && yarn tsa
tscBuild API module TypeScript
tsaBuild file-storage module TypeScript
start:apiyarn build && cd modules/api && node scripts/api.js
start:devDevelopment mode with ts-node
init:dbDatabase initialization