How tylergeorges/echochat works
Purpose and runtime
Echo Chat is a Discord-like real-time chat application: authenticated users create guilds/channels, invite or join members, and exchange messages. It runs as a Next.js TypeScript application, styled with Tailwind, deployed plausibly to Vercel, with Supabase providing authentication, Postgres, storage/realtime capabilities, and Drizzle defining database access/migrations.
Key entry points are src/app/page.tsx (landing), src/app/layout.tsx (application shell), and src/app/(protected)/channels/[guildId]/[channelId]/page.tsx (active chat).
Routing, authentication, and protection
The App Router separates public landing/login routes from protected guild, channel, and invite flows. Authentication is Supabase-based, including a callback endpoint for OAuth/Google sign-in. Request-level middleware establishes or refreshes Supabase auth state and protects route access.
• src/app/login/page.tsx
• src/app/auth/callback/route.ts
• _middleware.ts
• src/lib/supabase/middleware.ts
• src/app/(protected)/channels/[guildId]/page.tsx
Workspace and guild navigation
The protected UI models Discord’s hierarchy: users select a guild, inspect its channels, and navigate to a channel-specific route. Guild sidebars/dropdowns host actions such as creation, deletion, leaving, and invitations; modal infrastructure centralizes these workflows.
• src/components/guild/guilds.tsx
• src/components/guild/guild-sidebar.tsx
• src/components/guild/guild-dropdown.tsx
• src/components/modals/create-guild-modal.tsx
• src/lib/modal/system.ts
Chat experience
The channel page composes the chat interface: header/context, scrollable paginated messages, composer, author details, and responsive drawer behavior. Message retrieval supports infinite pagination, while sending mutations give immediate/optimistic client feedback.
• src/components/chat/index.tsx
• src/components/chat/chat-messages.tsx
• src/components/chat/chat-input.tsx
• src/hooks/use-messages-query.ts
• src/hooks/use-send-message-mutation.ts
Client data and realtime flow
React Query is the client data boundary: query hooks load guilds, channels, messages, and memberships; mutation hooks change server state and reconcile caches optimistically. Supabase subscription hooks listen for message and guild-membership changes, propagating remote activity into active client views.
• src/providers/react-query-client-provider.tsx
• src/hooks/use-guilds-query.ts
• src/hooks/use-channels-query.ts
• src/hooks/use-message-subscription.ts
• src/hooks/use-guild-member-subscription.ts
Persistence model and server boundary
Database schema and query modules encode the core domain: users, guilds, channels, messages, memberships/invites, and cursor pagination. Application code reaches Supabase through distinct browser/server clients, while Drizzle supplies typed schema/query construction and migration configuration.
• src/lib/db/schema/users.ts
• src/lib/db/schema/guilds.ts
• src/lib/db/schema/channels.ts
• src/lib/db/schema/messages.ts
• src/lib/db/queries/message.ts
• src/lib/supabase/client.ts
• src/lib/supabase/server.ts
Database lifecycle and external services
Supabase is the material external dependency for Google authentication, Postgres persistence, realtime subscriptions, and likely bucket assets (src/lib/get-bucket-asset.ts). SQL migrations and seed data define the deployable database state; Drizzle configuration connects the TypeScript model to that lifecycle.
• supabase/migrations/0000_wild_kitty_pryde.sql
• supabase/migrations/0008_cuddly_spot.sql
• supabase/seed.sql
• drizzle.config.ts
Main entry points: react-query-client-provider.tsx React Query boundary · page.tsx Channel route · guilds.tsx Guild navigation · index.tsx Chat interface
Components 19
Next.js application
- Landing page
src/app/page.tsx - App shell · Hosts shared application providers and UI.
src/app/layout.tsx - Login
src/app/login/page.tsx - OAuth callback
src/app/auth/callback/route.ts - Auth middleware · Refreshes Supabase session and guards protected routes.
_middleware.ts - Channel route · Selects guild and channel chat context.
src/app/(protected)/channels/[guildId]/[channelId]/page.tsx
Protected client
- Guild navigation · Guild sidebar and action dropdowns.
src/components/guild/guilds.tsx - Modal workflows · Centralizes guild creation, invitations, and membership actions.
src/lib/modal/system.ts - Chat interface · Composes chat header, messages, composer, and responsive behavior.
src/components/chat/index.tsx - React Query boundary · Loads domain data and reconciles optimistic mutations.
src/providers/react-query-client-provider.tsx - Paginated messages · Provides cursor-based infinite message retrieval.
src/hooks/use-messages-query.ts - Send message · Optimistically sends and reconciles chat messages.
src/hooks/use-send-message-mutation.ts - Realtime subscriptions · Receives message and guild-membership changes.
src/hooks/use-message-subscription.ts
Data and Supabase
- Supabase clients · Separate browser and server access to Supabase.
src/lib/supabase/client.ts - Drizzle domain schema · Defines users, guilds, channels, messages, memberships, and invites.
src/lib/db/schema/guilds.ts - Message queries · Implements message retrieval and cursor pagination.
src/lib/db/queries/message.ts - Supabase · Provides Auth, Postgres, Realtime, and storage.
- Database lifecycle · Deployable SQL schema and seed state.
supabase/migrations/0000_wild_kitty_pryde.sql - Drizzle configuration
drizzle.config.ts
Connections 20
- App shell → React Query boundary: provides
- Auth middleware → Channel route: guards
- Login → OAuth callback: sign-in returns to
- OAuth callback → Supabase clients: exchanges session through
- Channel route → Guild navigation: renders
- Channel route → Chat interface: renders
- Guild navigation → Modal workflows: opens actions in
- Guild navigation → React Query boundary: loads guilds and channels
- Chat interface → Paginated messages: displays
- Chat interface → Send message: submits through
- Paginated messages → React Query boundary: uses cache
- Send message → React Query boundary: optimistically updates
- Realtime subscriptions → React Query boundary: reconciles remote changes
- React Query boundary → Supabase clients: accesses data through
- Supabase clients → Supabase: connects to
- Message queries → Drizzle domain schema: queries
- Drizzle domain schema → Supabase: maps to Postgres
- Drizzle configuration → Database lifecycle: drives
- Database lifecycle → Supabase: provisions
- Supabase → Realtime subscriptions: publishes changes to