How muhammedanaskhan/communet works
Project Type & Purpose
• Full-stack social media web application (“Communet”)
• Built on Next.js 13 with Server‐Side Rendering and Server Actions (no separate Node API server)
• Authentication via Clerk, file uploads via UploadThing, persistence in MongoDB (Mongoose)
• Styled with Tailwind CSS and shadcn/ui components
Top‐Level Architecture Components
a. Client Browser (React)
b. Next.js Server (hosted on Vercel or similar)
• Route Groups in app/
• (auth) – onboarding, sign-in, sign-up flows
• (root) – activity feed, create/edit/search threads, profiles, thread pages
• Server Actions (lib/actions) invoked directly from components
• API Routes (app/api/)
• uploadthing – file upload handler
• clerk webhook – user/event webhooks via Svix
• Middleware (middleware.ts) – e.g., auth guards, redirects
c. External Services
• Clerk (authentication provider)
• UploadThing (file storage/CDN)
• Svix (secure webhook delivery)
d. Database
• MongoDB Atlas accessed via Mongoose (lib/mongoose.ts)
• Schemas in lib/models (User, Thread, Community)
Data Flows & Relationships
• User navigates to a page → Next.js SSR/SSG → calls Server Action (e.g., fetchThreadById) → Mongoose → MongoDB
• Posting threads/comments → Server Action or API route → validate with Zod → Mongoose write → MongoDB
• File upload (profile image or thread image) → Client calls UploadThing route → UploadThing service stores asset → returns URL → stored in MongoDB
• Authentication flows through Clerk SDK (client & server) → requests to Clerk APIs → Clerk issues JWT/session → middleware verifies user
• Webhooks: Clerk events → Svix forwards to /app/api/webhook/clerk/route.ts → serverless function processes event
Architectural Patterns & Design Principles
• Serverless Monolith: Next.js handles UI, SSR, API routes, and Server Actions in a single deployment
• Route‐Group Organization: app/(auth) vs. app/(root) segments for clear separation of pre-auth vs. protected routes
• Component-Driven UI: atoms, cards, forms, shared layout components, and generated shadcn/ui primitives
• Schema-Driven Validation: Zod + react-hook-form for request-level validation
• Modular Data Layer: actions, models, validations under lib/
Detail Without Overthinking
• Every distinct component/directory: route groups, middleware, API routes, server actions, models, validation, UI component groups
• Both the UI routing layer and data‐access layer to give a holistic view