Backend for Real-Time Chat

This directory contains the backend code for the real-time chat application.

Components

  • index.ts: Main entry point with Hono setup, WebSocket handling, and HTTP routes
  • database/: Database setup and queries
    • migrations.ts: Schema definitions
    • queries.ts: Database query functions

WebSocket Protocol

The WebSocket connection handles the following message types:

From Client to Server:

  • join: User joining the chat with a username
  • message: User sending a message

From Server to Client:

  • message: New message from a user
  • user_joined: Notification when a user joins
  • user_left: Notification when a user leaves
  • history: Message history when a user first connects