# tylergeorges/echochat architecture

> Architecture diagram of the GitHub repository tylergeorges/echochat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tylergeorges/echochat
- Repository: https://github.com/tylergeorges/echochat

## Overview

#### 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: [`src/providers/react-query-client-provider.tsx`](https://github.com/tylergeorges/echochat/blob/master/src/providers/react-query-client-provider.tsx) (React Query boundary), [`src/app/(protected)/channels/[guildId]/[channelId]/page.tsx`](https://github.com/tylergeorges/echochat/blob/master/src/app/(protected)/channels/%5BguildId%5D/%5BchannelId%5D/page.tsx) (Channel route), [`src/components/guild/guilds.tsx`](https://github.com/tylergeorges/echochat/blob/master/src/components/guild/guilds.tsx) (Guild navigation), [`src/components/chat/index.tsx`](https://github.com/tylergeorges/echochat/blob/master/src/components/chat/index.tsx) (Chat interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js application"]
  node_landing["Landing page<br/>route<br/>[page.tsx]"]
  node_app_shell["App shell<br/>layout<br/>[layout.tsx]"]
  node_login["Login<br/>public route<br/>[page.tsx]"]
  node_oauth_callback{{"OAuth callback<br/>route handler<br/>[route.ts]"}}
  node_auth_middleware{{"Auth middleware<br/>request middleware<br/>[_middleware.ts]"}}
  node_chat_route["Channel route<br/>protected route<br/>[page.tsx]"]
end

subgraph group_client["Protected client"]
  node_guild_navigation["Guild navigation<br/>client UI<br/>[guilds.tsx]"]
  node_modal_system["Modal workflows<br/>client UI<br/>[system.ts]"]
  node_chat_ui["Chat interface<br/>client UI<br/>[index.tsx]"]
  node_react_query["React Query boundary<br/>client state"]
  node_message_query["Paginated messages<br/>query hook"]
  node_send_message["Send message<br/>mutation hook"]
  node_realtime_subscriptions["Realtime subscriptions<br/>subscription hooks"]
end

subgraph group_data["Data and Supabase"]
  node_supabase_clients["Supabase clients<br/>browser/server boundary<br/>[client.ts]"]
  node_drizzle_domain["Drizzle domain schema<br/>typed data model<br/>[guilds.ts]"]
  node_message_queries["Message queries<br/>data access<br/>[message.ts]"]
  node_supabase[("Supabase<br/>external platform")]
  node_database_lifecycle["Database lifecycle<br/>migrations and seed"]
  node_drizzle_config["Drizzle configuration<br/>migration configuration<br/>[drizzle.config.ts]"]
end

node_app_shell -->|"provides"| node_react_query
node_auth_middleware -->|"guards"| node_chat_route
node_login -->|"sign-in returns to"| node_oauth_callback
node_oauth_callback -->|"exchanges session through"| node_supabase_clients
node_chat_route -->|"renders"| node_guild_navigation
node_chat_route -->|"renders"| node_chat_ui
node_guild_navigation -->|"opens actions in"| node_modal_system
node_guild_navigation -->|"loads guilds and channels"| node_react_query
node_chat_ui -->|"displays"| node_message_query
node_chat_ui -->|"submits through"| node_send_message
node_message_query -->|"uses cache"| node_react_query
node_send_message -->|"optimistically updates"| node_react_query
node_realtime_subscriptions -->|"reconciles remote changes"| node_react_query
node_react_query -->|"accesses data through"| node_supabase_clients
node_supabase_clients -->|"connects to"| node_supabase
node_message_queries -->|"queries"| node_drizzle_domain
node_drizzle_domain -->|"maps to Postgres"| node_supabase
node_drizzle_config -->|"drives"| node_database_lifecycle
node_database_lifecycle -->|"provisions"| node_supabase
node_supabase -.->|"publishes changes to"| node_realtime_subscriptions

click node_landing "https://github.com/tylergeorges/echochat/blob/master/src/app/page.tsx"
click node_app_shell "https://github.com/tylergeorges/echochat/blob/master/src/app/layout.tsx"
click node_login "https://github.com/tylergeorges/echochat/blob/master/src/app/login/page.tsx"
click node_oauth_callback "https://github.com/tylergeorges/echochat/blob/master/src/app/auth/callback/route.ts"
click node_auth_middleware "https://github.com/tylergeorges/echochat/blob/master/_middleware.ts"
click node_chat_route "https://github.com/tylergeorges/echochat/blob/master/src/app/(protected)/channels/%5BguildId%5D/%5BchannelId%5D/page.tsx"
click node_guild_navigation "https://github.com/tylergeorges/echochat/blob/master/src/components/guild/guilds.tsx"
click node_modal_system "https://github.com/tylergeorges/echochat/blob/master/src/lib/modal/system.ts"
click node_chat_ui "https://github.com/tylergeorges/echochat/blob/master/src/components/chat/index.tsx"
click node_react_query "https://github.com/tylergeorges/echochat/blob/master/src/providers/react-query-client-provider.tsx"
click node_message_query "https://github.com/tylergeorges/echochat/blob/master/src/hooks/use-messages-query.ts"
click node_send_message "https://github.com/tylergeorges/echochat/blob/master/src/hooks/use-send-message-mutation.ts"
click node_realtime_subscriptions "https://github.com/tylergeorges/echochat/blob/master/src/hooks/use-message-subscription.ts"
click node_supabase_clients "https://github.com/tylergeorges/echochat/blob/master/src/lib/supabase/client.ts"
click node_drizzle_domain "https://github.com/tylergeorges/echochat/blob/master/src/lib/db/schema/guilds.ts"
click node_message_queries "https://github.com/tylergeorges/echochat/blob/master/src/lib/db/queries/message.ts"
click node_database_lifecycle "https://github.com/tylergeorges/echochat/blob/master/supabase/migrations/0000_wild_kitty_pryde.sql"
click node_drizzle_config "https://github.com/tylergeorges/echochat/blob/master/drizzle.config.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_landing,node_app_shell,node_login,node_oauth_callback,node_auth_middleware,node_chat_route toneBlue
class node_guild_navigation,node_modal_system,node_chat_ui,node_react_query,node_message_query,node_send_message,node_realtime_subscriptions toneAmber
class node_supabase_clients,node_drizzle_domain,node_message_queries,node_supabase,node_database_lifecycle,node_drizzle_config toneMint
```

## Components

### Next.js application

- [Landing page](https://github.com/tylergeorges/echochat/blob/master/src/app/page.tsx): route · `src/app/page.tsx`
- [App shell](https://github.com/tylergeorges/echochat/blob/master/src/app/layout.tsx): layout · Hosts shared application providers and UI. · `src/app/layout.tsx`
- [Login](https://github.com/tylergeorges/echochat/blob/master/src/app/login/page.tsx): public route · `src/app/login/page.tsx`
- [OAuth callback](https://github.com/tylergeorges/echochat/blob/master/src/app/auth/callback/route.ts): route handler · `src/app/auth/callback/route.ts`
- [Auth middleware](https://github.com/tylergeorges/echochat/blob/master/_middleware.ts): request middleware · Refreshes Supabase session and guards protected routes. · `_middleware.ts`
- [Channel route](https://github.com/tylergeorges/echochat/blob/master/src/app/(protected)/channels/%5BguildId%5D/%5BchannelId%5D/page.tsx): protected route · Selects guild and channel chat context. · `src/app/(protected)/channels/[guildId]/[channelId]/page.tsx`

### Protected client

- [Guild navigation](https://github.com/tylergeorges/echochat/blob/master/src/components/guild/guilds.tsx): client UI · Guild sidebar and action dropdowns. · `src/components/guild/guilds.tsx`
- [Modal workflows](https://github.com/tylergeorges/echochat/blob/master/src/lib/modal/system.ts): client UI · Centralizes guild creation, invitations, and membership actions. · `src/lib/modal/system.ts`
- [Chat interface](https://github.com/tylergeorges/echochat/blob/master/src/components/chat/index.tsx): client UI · Composes chat header, messages, composer, and responsive behavior. · `src/components/chat/index.tsx`
- [React Query boundary](https://github.com/tylergeorges/echochat/blob/master/src/providers/react-query-client-provider.tsx): client state · Loads domain data and reconciles optimistic mutations. · `src/providers/react-query-client-provider.tsx`
- [Paginated messages](https://github.com/tylergeorges/echochat/blob/master/src/hooks/use-messages-query.ts): query hook · Provides cursor-based infinite message retrieval. · `src/hooks/use-messages-query.ts`
- [Send message](https://github.com/tylergeorges/echochat/blob/master/src/hooks/use-send-message-mutation.ts): mutation hook · Optimistically sends and reconciles chat messages. · `src/hooks/use-send-message-mutation.ts`
- [Realtime subscriptions](https://github.com/tylergeorges/echochat/blob/master/src/hooks/use-message-subscription.ts): subscription hooks · Receives message and guild-membership changes. · `src/hooks/use-message-subscription.ts`

### Data and Supabase

- [Supabase clients](https://github.com/tylergeorges/echochat/blob/master/src/lib/supabase/client.ts): browser/server boundary · Separate browser and server access to Supabase. · `src/lib/supabase/client.ts`
- [Drizzle domain schema](https://github.com/tylergeorges/echochat/blob/master/src/lib/db/schema/guilds.ts): typed data model · Defines users, guilds, channels, messages, memberships, and invites. · `src/lib/db/schema/guilds.ts`
- [Message queries](https://github.com/tylergeorges/echochat/blob/master/src/lib/db/queries/message.ts): data access · Implements message retrieval and cursor pagination. · `src/lib/db/queries/message.ts`
- **Supabase**: external platform · Provides Auth, Postgres, Realtime, and storage.
- [Database lifecycle](https://github.com/tylergeorges/echochat/blob/master/supabase/migrations/0000_wild_kitty_pryde.sql): migrations and seed · Deployable SQL schema and seed state. · `supabase/migrations/0000_wild_kitty_pryde.sql`
- [Drizzle configuration](https://github.com/tylergeorges/echochat/blob/master/drizzle.config.ts): migration configuration · `drizzle.config.ts`

## Connections

- 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
