How daithien2004/socialbook works
Project type and purpose
• SocialBook is a full-stack social reading platform combining traditional book management with social features, gamification, and AI-driven services (summaries, TTS, vector search).
File structure
• Top-level: frontend/ (Next.js 15 + TypeScript + TailwindCSS + Radix UI + Redux Toolkit + Socket.IO Client), backend/ (NestJS 11 + TypeScript + Mongoose + Redis + ChromaDB + Passport + Socket.IO Gateway), and docker-compose.yml for Redis & ChromaDB.
• Backend follows a modular, feature-based directory under src/modules/ (auth, users, books, chapters, chat, notifications, gamification, content-moderation, recommendations, search, etc.). Shared code lives in src/shared/ (database seeds, Redis cache, Cloudinary config, logger).
• Frontend uses the App Router (src/app/) with two major layouts—(auth) and (user), plus an admin/ subtree. UI components under src/components, global state under src/store, feature slices under src/features, and API client wrappers under src/lib.
README for additional insights
• Tech stacks and feature list confirm: real-time chat & notifications (Socket.IO), AI integrations (Google Gemini, OpenAI/LangChain, HuggingFace, Google Cloud TTS), caching/queues (Redis), vector search (ChromaDB), file hosting (Cloudinary), and secure onboarding/auth (JWT, Passport, NextAuth).
a. Main components
• Frontend (Next.js server + browser-run React components, Redux + RTK Query)
• Backend (NestJS REST & WebSocket API)
• Data stores (MongoDB, Redis, ChromaDB)
• External AI services (Google Gemini, OpenAI, HuggingFace, Google Cloud TTS)
• File storage/CDN (Cloudinary)
• Authentication provider (JWT, Passport strategies, NextAuth middleware)
• Real-time channels (Socket.IO)
• Container orchestration (Docker Compose)
b. Relationships & interactions
• Browser ↔ Next.js (SSR + client navigation)
• Next.js ↔ NestJS (HTTP REST & WebSocket for chat/notifications)
• NestJS ↔ MongoDB (Mongoose schemas in each module)
• NestJS ↔ Redis (caching, session management, rate-limiting, queueing tasks)
• NestJS ↔ ChromaDB (vector search for embeddings)
• NestJS ↔ External AI APIs (Gemini for summaries, OpenAI/LangChain, HuggingFace, Google TTS)
• NestJS ↔ Cloudinary (image uploads)
• NestJS ↔ Redis/Socket.IO (publish real-time events to frontend)
c. Architectural patterns & principles
• Feature modularity (each domain under modules/)
• Layered service pattern: Controllers → Services → Repositories (via Mongoose schemas)
• Cross-cutting concerns: Guards (authentication/authorization), filters, interceptors, decorators for roles & validation
• State management on frontend: Redux Toolkit slices + RTK Query for API calls
• Separation of concerns: Frontend vs. backend vs. data stores vs. external services
d. Key technologies
• Next.js 15, TypeScript, Turbopack, TailwindCSS, Radix UI, Framer Motion
• Redux Toolkit, RTK Query, Socket.IO Client
• NestJS 11, TypeScript, Mongoose, Passport + JWT, Socket.IO Gateway
• Redis, ChromaDB, MongoDB, Cloudinary, Google Gemini, OpenAI, HuggingFace, Google Cloud TTS
Essential architectural elements
• Authentication flow: NextAuth in Frontend ↔ NestJS Auth Controller ↔ JWT Guard → Redis session/cache
• How Chat & Notifications modules use Socket.IO Gateway for real-time push
• AI integration path: Book Chapter → Gemini summarization → return to Frontend