Public
Real-time support chat with SSE and SQLite persistence
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
A real-time chat application built on Val Town with persistent message storage and live updates.
- Username-based login — pick a name to join the chat
- Real-time messaging — messages appear instantly via Server-Sent Events (SSE)
- Persistent storage — messages are stored in SQLite and survive across sessions
- Multi-user sync — open in two tabs to see messages sync in real-time
- Input validation — prevents empty messages, enforces length limits
- Auto-reconnect — SSE connection auto-recovers on disconnect
Rendering mermaid diagram...
- User enters a username to join
- Frontend loads recent messages from
GET /api/messages - Frontend opens an SSE connection to
GET /api/messages/stream?lastId=N - Server polls SQLite every 1s for new messages and pushes them via SSE
- When a user sends a message,
POST /api/messagesinserts it into SQLite - All connected SSE streams pick up the new message within ~1 second
main.ts— Hono HTTP server with API routes and SSE endpointdb.ts— SQLite database helpers (init, get, add messages)frontend/— React UI componentsindex.html— Entry HTML pageindex.tsx— React mount pointcomponents/App.tsx— Root component with username statecomponents/UsernameForm.tsx— Login formcomponents/ChatRoom.tsx— Chat UI with SSE connectioncomponents/MessageBubble.tsx— Individual message display