How thearnabsaha/chat-app works
Project type and purpose
• This is a full-stack real-time chat application organized in a monorepo (pnpm + Turborepo).
• It consists of three main runnable apps—Next.js web client, Express REST API server, and a WebSockets server—plus shared packages for common types, database access (Prisma), UI components, and lint/TypeScript configs.
File structure
• Top-level “apps” directory with:
• express-server (src/controllers, routes, JWT middleware, config)
• websockets-server (entrypoint only)
• web (Next.js 13 app directory, components, hooks, Tailwind, Zustand stores)
• “packages” directory with:
• common (shared types)
• backend-common (shared utilities for servers)
• db (Prisma schema & migrations + client wrapper)
• ui (shared React/Tailwind components)
• eslint-config & typescript-config (shared lint/build configs)
• Root configs (turbo.json, tsconfig.json, pnpm-workspace.yaml) orchestrate workspace builds.
README for additional insights
• REST API routes for Users (/signup, /signin, /me, /health), Chats (/chat CRUD), Rooms (/room CRUD).
• JWT-protected endpoints.
• Controllers implement business logic, Prisma is used under the hood for persistence.
• Web Client (Next.js app)
• REST API Service (Express)
• WebSockets Service
• Database (PostgreSQL via Prisma)
• Shared Package Modules (common, backend-common, db, ui)
• External Auth (JWT token issuance & validation)
b. Relationships and data flows:
1. User ↔ Web Client (browser)
2. Web Client ↔ REST API (HTTP/JSON + Authorization: Bearer JWT)
3. REST API ↔ Database (Prisma Client)
4. Web Client ↔ WebSockets Server (real-time messaging)
5. WebSockets Server ↔ Database (optional writes/reads via Prisma)
6. Both server apps import shared packages (common types, db wrappers, backend utilities) from workspace
c. Architectural patterns & design principles:
• Monorepo with code-sharing via local packages
• Separation of concerns: UI vs. business logic vs. real-time messaging
• Modular controllers/routes/middleware in Express
• Component-driven design in Next.js + shared UI library
• Strong typing & validation (TypeScript + shared types)
d. Key technologies / frameworks / libraries:
• Next.js 13 (app router, React, Tailwind CSS, Zustand stores)
• Express.js + TypeScript + JWT middleware
• ws or socket.io (WebSockets server)
• Prisma ORM + PostgreSQL (migrations in packages/db)
• pnpm / Turborepo (monorepo tooling)
• Shared UI components (packages/ui) and shared configs