Shaygan Venus Portal — technical architecture
The portal is a TypeScript monorepo with a React progressive web app and a modular Bun/Express backend. One backend process serves the built dashboard, exposes the HTTP API, accepts WebSocket connections, and runs scheduled jobs. PostgreSQL is the system of record. Redis is optional, and uploaded files are stored on local disk or in S3-compatible storage.
The diagrams describe the architecture implemented in this checkout. The production proxy, host layout, and replica count aren’t established by the application code.
1. Runtime architecture
| Workspace | What it owns |
|---|---|
app/dashboard |
React 18, Vite, React Router, and Tailwind. Public pages, employee features, and admin screens share one Persian RTL SPA. Routes use hash routing; many screens load on demand. |
app/backend |
Express 4, ws, PostgreSQL via pg, optional Redis via ioredis, and S3 via the AWS SDK. app/container.ts wires routes, policies, services, and repositories together. |
lib/contracts |
Shared TypeScript models and selected values/helpers imported by both applications as @portal/contracts. It has no separate runtime service. |
Development: Vite runs on 127.0.0.1:5173 and proxies /api, /ws, and /uploads to the backend on 127.0.0.1:3001. Built mode: Express serves app/dashboard/dist alongside the API and WebSocket endpoint. See vite.config.ts and responses.ts.
2. API, authorization, and persistence
The API has two shapes: collection endpoints (GET and PUT /api/store/:key) for much of the portal content, and dedicated endpoints for workflows such as sign-in, file uploads, push subscriptions, chat search, and system health.
For collection reads, the backend resolves the session, checks whether the collection is available to the caller, reads from the eligible cache or PostgreSQL, and filters the result. For example, document folders can be scoped by employee, department, or organizational role; reminders are filtered to their owner; chat history is filtered to the caller’s visible conversations. Effective employee permissions combine organizational-role grants and direct grants. Session expiry and inactivity are enforced server-side. See store-router.ts, policy.ts, and sessions.ts.
| Data | Storage and access pattern |
|---|---|
| Portal content, employees, sessions, and chat history | portal_store: one PostgreSQL row per collection key, with a JSONB value. Many operations read or replace a collection as a whole. |
| Chat search | chat_search_messages: a derived PostgreSQL full-text index with generated tsvector columns and GIN indexes. Chat writes update the stored collection and search index in one transaction. |
| File metadata and contents | uploaded_files stores identifiers, object keys, URLs, sizes, types, and uploaders. File bytes live on disk or in S3-compatible storage. |
| Audit records | audit_logs, partitioned by time, with indexes for time, action, and user. |
| Application events | event_queue records published events. When Redis is available, the publisher also writes to a Redis list and publishes to a channel, then emits to sockets attached to the current process. |
There are two distinct search paths: the portal search box matches news, documents, and videos already available to the browser; chat search queries PostgreSQL through /api/chat/search. The service worker caches the app shell and same-origin resources while excluding /api/ requests. The dashboard separately keeps session-scoped collection snapshots in memory and can persist guest snapshots in browser storage.
Sources: schema.sql, collections.ts, GlobalSearch.tsx, and cache.ts.
3. Real-time chat flow
On reconnect, the dashboard retries pending sends. If the backend already saved the same message for the same sender and conversation, it acknowledges that copy. Incoming WebSocket events also patch or invalidate browser caches for chat, presence, and changed content. See RealtimeBridge.tsx and chat/service.ts.
4. Resumable upload flow
A repeated completion request can return the previously saved result. Temporary upload state lives on local disk even when final files go to S3. See files/routes.ts and upload-sessions.ts.
5. Operations and deployment implications
- Startup and jobs:
main.tsapplies the schema and data migrations before listening. The process also runs session cleanup, WebSocket pings, upload and chat-attachment cleanup, health checks, scheduled push, HR and sales reminders, audit maintenance, and backup scheduling. - Health and backups: The backend exposes
/api/healthand admin endpoints for system status and service logs. PostgreSQL backups usepg_dump; restore verification can use a temporary database. Uploaded file bytes are stored separately from the database dump. - Scaling boundary: The WebSocket registry, chat write queue, and job timers are process-local. The repository shows Redis event publication but no subscriber wiring events back into other backend instances. Running multiple replicas therefore requires explicit coordination for cross-instance realtime delivery, chat writes, scheduled jobs, and resumable upload state.