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

Runtime architecture The React dashboard connects to the service worker and browser cache. It exchanges requests and events with Express and WebSocket endpoints. Both endpoints and scheduled jobs connect to domain modules. Those modules use PostgreSQL, optional Redis, local disk, optional S3-compatible storage, and optional Web Push, which reaches the service worker. Browser / installed PWA Bun backend process React dashboard Browser cache andIndexedDB chatqueue Service worker Express: SPA assets,/api, /uploads WebSocket: /ws Scheduled jobs Domain modulesand access policy PostgreSQL — required Redis — optional Local disk S3-compatible storage Browser push service Static assets and JSON requests Chat, presence,and update events Collections, indexes, metadata, audit Cache and event publication Upload staging; final files by default Final files when configured VAPID Web Push
WorkspaceWhat 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.

DataStorage 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

Real-time chat flow The sender queues a message with an idempotency key and sends it over an authenticated socket. The backend checks permissions, destination, and rate limit, then persists the chat collection and search index in one transaction. After PostgreSQL commits, the backend sends new_message and room updates to the recipient and message_saved to the sender. The sender acknowledges the queued message. Sender dashboard IndexedDB chat queue Backend /ws PostgreSQL Recipient dashboard Queue message withan idempotency key send_message on an authenticated socket Check permissions, destination,and rate limit Persist chat collectionand search index inone transaction Commit Targeted new_message and room updates message_saved with idempotency key Acknowledge queued message

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

Resumable upload flow Initialize the upload, post chunks to the local upload session, and call the completion endpoint. The backend checks ownership and chunk completeness, assembles and hashes the file, stores it on disk or in S3, writes PostgreSQL metadata, and returns the URL while emitting upload_completed. POST /api/upload/init POST /api/upload/chunk Upload session and chunks on local disk POST /api/upload/complete Check ownership and chunk completeness;assemble and hash Store final bytes on disk or in S3 Write PostgreSQL metadata and record completion Return file URL and emit upload_completed

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