YACS

Architecture

YACS is a TypeScript monorepo managed with Yarn 4 workspaces and Turborepo.

yacs/
├─ app/                 React PWA (Vite)
├─ api/                 Koa API, Socket.IO, PeerJS server
├─ packages/
│  ├─ dto/              Protobuf schemas + shared types, events, limits
│  ├─ utils/            Shared helpers (time, formatting, random, MongoDB)
│  └─ webshare/         Resumable P2P file transfer
├─ public/              Icons and uploaded media (default MEDIA_URL)
└─ Dockerfile           Multi-stage production image

Runtime overview

 Browser (PWA)                                    Server (one Node process, :3000)
┌───────────────────────────┐   HTTP /api     ┌──────────────────────────────┐
│ React · Redux · Query     │ ──────────────▶ │ Koa router (+ rate limiting) │──▶ MongoDB
│ IndexedDB message cache   │   Socket.IO     │ Socket.IO handlers           │──▶ Redis
│ Service worker · outbox   │ ◀────────────▶  │ PeerJS signalling  (/app)    │──▶ media on disk
│ PeerJS peer               │                 │ Static client + SPA fallback │
└────────────┬──────────────┘                 └──────────────────────────────┘
             │  WebRTC (messages, calls, files)
             ▼
      other user's devices

app — the client

  • React 19 with MUI and Tailwind, Redux Toolkit for conversation/message state, TanStack Query for request caching.
  • Socket.IO client for realtime events; a single PeerJS peer per device carries envelopes, calls and file transfers.
  • IndexedDB (via idb) stores messages and media; an outbox syncs messages written offline.
  • Workbox service worker with precaching, push notifications, share target and app badge.
  • Separate desktop and phone layouts.

api — the server

  • Koa HTTP API under /api, organised by feature folders (auth, conversation, message, envelope, call, discover, profile, user, label…).
  • Mongoose models on MongoDB, including geospatial queries for Nearby.
  • Redis for cache, presence and rate limiting.
  • Socket.IO for realtime; each socket joins a room for its user and its device.
  • PeerJS server mounted at /app on the same HTTP server.
  • Sharp for image processing, web-push for notifications, node-schedule for cleanup jobs (e.g. expiring guests).
  • Static hosting of app/dist with an SPA fallback; /api, /socket.io, /app and /_media are reserved paths.

packages/dto — the contract

All wire types live here so client and server can't drift:

  • proto/v1/*.proto — yacs.v1 Protocol Buffers schemas (users, profiles, conversations, messages, envelopes, calls, peers, transfers). Code is generated with Buf and protoc-gen-es.
  • events.ts — Socket.IO event names.
  • requests.ts, call.ts, http.ts — request/ack shapes.
  • limits.ts — shared validation limits.

Wire format

HTTP endpoints that return protobuf messages negotiate the format by Accept header:

  • Accept: application/x-protobuf → binary protobuf (what the app uses).
  • Anything else → protobuf JSON (enums as integers), handy with curl.

Build and release

  • yarn build builds the packages first (Turborepo ^build), then the API (bundled with ebx) and the client (Vite).
  • CI runs build, typecheck and tests on every pull request.
  • Publishing a GitHub release builds and pushes the Docker image to ghcr.io/yacs-app/yacs.