Skip to content

kalokaradia/privo-chat

Repository files navigation

PrivoChat

Private, temporary, room-based chat app (2 participants max per room) with realtime updates via Upstash.

Features

  • Create a new room and share the link.
  • Join room via /room/:roomId.
  • Realtime “new message” updates (no manual refresh).
  • Destroy room (broadcasts a destroy event and clears stored data).
  • Room TTL (defaults to 10 minutes) and auto-expiration after inactivity.

Tech Stack

  • Framework: Next.js (next@16.2.6) + React (react@19)
  • Styling: Tailwind CSS v4
  • API layer: Elysia (elysia) mounted inside Next.js Route Handlers
  • Client data fetching/cache: TanStack Query (@tanstack/react-query)
  • Realtime transport: Upstash Realtime (@upstash/realtime)
  • Storage: Upstash Redis REST (@upstash/redis)
  • Validation: Zod v4 (zod/v4)
  • Utilities: nanoid, date-fns, lucide-react

System Overview

Pages

  • src/app/page.tsx: Lobby (create/join UI + error states via query params).
  • src/app/room/[roomId]/page.tsx: Room UI (messages list, input, TTL, copy link, destroy).

API Endpoints

All endpoints live under src/app/api/[[...slugs]]/route.ts and are served at /api/*:

  • POST /api/room/create{ roomId }
  • GET /api/room/ttl?roomId=...{ ttl } (seconds)
  • DELETE /api/room?roomId=... → destroys room + broadcasts destroy
  • GET /api/messages?roomId=...&token?=...{ messages }
  • POST /api/messages?roomId=... → send message + broadcast message

Realtime handshake endpoint:

  • GET /api/realtime (Upstash Realtime handler) in src/app/api/realtime/route.ts

Storage (Redis Keys)

  • meta:{roomId} (hash): room metadata, including connected tokens and createdAt
  • messages:{roomId} (list): message history

Auth / Access Control

  • Uses a x-auth-token HttpOnly cookie to identify a participant.
  • Server validates token membership via meta:{roomId}.connected in src/app/api/[[...slugs]]/auth.ts.

Note: src/proxy.ts contains a ready-to-use middleware-style gatekeeper for /room/* (sets cookie, enforces max 2 participants, handles redirects), but it must be wired into Next.js middleware.ts to be active.

Getting Started (Local)

1) Install

bun install

2) Configure environment

Create .env.local:

UPSTASH_REDIS_REST_URL=...
UPSTASH_REDIS_REST_TOKEN=...

These are required by src/lib/redis.ts.

3) Run

bun dev

Open http://localhost:3000.

How to Use

  1. Open the lobby page.
  2. Click “Create room” (generates a roomId).
  3. Share the room link with a friend.
  4. Both participants open the room link and start chatting.
  5. Use “Destroy room” to permanently end the session for both sides.

How It Works (High Level)

  • Room creation stores metadata in Redis with a 10-minute TTL.
  • Messages are appended into a Redis list (messages:{roomId}).
  • On send, the server emits a realtime message event on the room channel.
  • Clients subscribe to the room channel and refetch messages on new events.
  • Destroy emits a destroy event then deletes room data (meta + messages).

Releases

No releases published

Packages

 
 
 

Contributors