How mohamedhabibfrigui/slack-clone works
Project Type and Purpose
• This is a full-stack, serverless web application built on Next.js (App Router) with Convex providing backend logic and data storage.
• It implements a real-time chat/workspace system: user authentication, workspaces, channels, direct conversations, messages, reactions, file uploads.
File Structure Analysis
• Top-level:
– next.config.mjs, postcss.config.mjs, tailwind.config.ts, tsconfig.json, package.json: build & toolchain config for Next.js, Tailwind CSS, TypeScript.
– convex/ directory: contains generated API types, data model, server functions (channels.ts, messages.ts, etc.), authentication config, HTTP endpoints, upload handlers.
– public/: static assets.
– sampleData.jsonl: seed data for development.
• src/ directory follows a “feature-sliced” pattern:
– src/app/: Next.js App Router pages, layouts, global styles, workspace and join flows.
– src/components/: generic UI components and providers (ConvexClientProvider, JotaiProvider).
– src/features/: feature modules by domain (auth, channels, conversations, members, messages, reaction, upload, workspaces). Each has api hooks, UI components, and local store.
– src/hooks/: custom React hooks for URL params and UI state.
– src/lib/: utility functions.
– middleware.ts: Next.js middleware for auth redirects, etc.
Key Insights from README
• Standard Next.js “create-next-app” bootstrap.
Components
• Frontend (Browser):
– Next.js App Router (pages under src/app) with server-side rendering and client components.
– UI Component Library (src/components/ui).
– ConvexClientProvider + JotaiProvider: global context for data fetching and state.
– Feature modules: auth, workspaces, channels, conversations, members, messages, reactions, upload.
• API Layer:
– Convex client SDK in browser talking to Convex HTTP endpoints.
• Backend (Serverless):
– Convex server functions (convex/*.ts): business logic and data access (CRUD for users, messages, workspaces, etc.).
– Convex HTTP endpoints (convex/http.ts) for file uploads or custom REST usage.
• Data Storage:
– Convex’s managed database (documents/collections defined in convex/schema.ts).
• External Services:
– Vercel (hosting) or any CDN.
– Cloud storage or S3 for uploads (if configured).
– Authentication provider (if external OAuth is used, configured in auth.config.ts).
Relationships and Data Flows
• User Browser → Next.js (SSR + SPA hydration).
• Next.js Client Components → ConvexClientProvider → Convex HTTP endpoints.
• Convex Functions → Data Model → Convex Database.
• Upload Flow: Client requests upload URL from convex/upload.ts → Uploads file to storage → Convex records metadata.
• Authentication Flow: Next.js Middleware → Convex auth.ts flows → Session tokens.
Architectural Patterns and Design Principles
• Feature-centric module organization for scale and clarity.
• Separation of concerns:
– Presentation (components, pages).
– State & data fetching (Convex hooks, Jotai stores).
– Business logic & data access (Convex server functions).
• Serverless functions eliminate custom backend server maintenance.
• Next.js App Router enables SSR/SSG and API routes.