How euxzy/lazy-chat works
Project Type & Purpose
• This is a full-stack, SvelteKit-based web application scaffolded via the sv CLI.
• It includes a client-side SPA/SSR layer (Svelte components & routes), a Node-based server for HTTP/SSR and WebSocket handling, a relational database layer (via Drizzle ORM), plus E2E and unit testing.
Top-Level File Structure & Architectural Hints
• /src
• routes/ — SvelteKit page routes with server endpoints (+page.server.ts) and client pages (.svelte).
• lib/ — shared UI components (ui/, layout/, chat/), stores, utilities, and server DB schema (lib/server/db/schema).
• /server — custom server entrypoints (index.ts) and WebSocket logic (socket.ts).
• /plugins/vite/socket.ts — Vite plugin that provisions the WebSocket plugin during dev/build.
• drizzle.config.ts — Drizzle ORM configuration for schema definitions under lib/server/db/schema.
• e2e/ & src/demo.spec.ts — Playwright and Vitest tests.
• vite.config.ts & svelte.config.js — bundler and framework configs.
a. Client (Browser)
• SvelteKit app: SSR entrypoints + client hydration.
• UI Components: chat bubbles, layout, buttons, etc.
• Stores: Socket store for real-time data.
b. Dev/Build Toolchain
• Vite: bundles code & applies socket plugin.
• Husky pre-commit/pre-push hooks.
• Prettier/ESLint.
c. Server
• SvelteKit Node adapter: handles HTTP/SSR & endpoints in routes folder.
• /server/index.ts: custom server bootstrap if present.
• WebSocket server: server/socket.ts + Vite plugin wiring.
• Drizzle ORM layer: configured via drizzle.config.ts, uses schema under lib/server/db/schema.
d. Database
• Postgres (or similar) where Drizzle applies migrations and queries.
e. Tests & CI
• Playwright E2E tests hitting the running server.
• Vitest unit tests for components and utilities.
Data Flows & Relationships
• HTTP/SSR: Browser ↔ SvelteKit server (page loads, API calls in +page.server.ts).
• WebSocket: Browser’s Socket store ↔ WebSocket endpoint on the server.
• ORM: SvelteKit server logic ↔ Drizzle ORM ↔ Database.
• Build: Source files ↔ Vite + socket plugin → production assets.
• CI Hooks: Git operations → Husky → lint/tests → commit/push.
Architectural Patterns & Principles
• Component-based UI (Svelte).
• Server-Side Rendering + client hydration (SvelteKit).
• Real-time communication via WebSockets.
• Single source of truth for data via Drizzle ORM schemas.
• Separation of concerns: UI vs store vs server vs database.
Essential Elements
• Frontend: SvelteKit routes, components, stores.
• Backend: SvelteKit server endpoints, custom server, socket handler.
• Data Layer: Drizzle config & schema modules, external DB.
• Toolchain: Vite + plugin, ESLint/Prettier, Husky, Vitest/Playwright.
• Flows: SSR HTTP, WebSocket, build pipeline.