How aditya18mew/echoora works
1. Overall shape
- This repository contains two deployable pieces: a Next.js application in Echoora/ and a separate SocketServer/ Node service for realtime messaging.
- The Next.js app is the primary UI and API boundary; the socket service is a dedicated realtime backend, likely used by the chat experience.
2. Next.js app as a full-stack monolith
- Echoora/src/app uses the App Router and mixes presentation routes with server-side route handlers.
- The app is organized into route groups for major user states: auth, dashboard, and profile, plus a public landing page.
3. Route-level UI boundaries
- src/app/(auth) contains sign-in, sign-up, and password recovery pages with separate layouts, isolating the unauthenticated experience.
- src/app/dashboard contains the authenticated social/feed/chat area with its own layout and shared dashboard components.
- src/app/profile contains profile viewing and settings flows, including a dynamic [username] profile route.
4. Backend API surface inside the same app
- src/app/api exposes the server endpoints that power the UI.
- Auth-related endpoints cover sign-in, sign-up, logout, refresh, cookie setting, delete account, and email verification/reset flows.
- Dashboard endpoints cover chat, individual chat messages, follows, posts, search, profile bio updates, link updates, and user settings.
5. Authentication and session management
- Authentication is split across multiple layers: API routes, middleware.ts, and shared auth helpers in src/libs.
- jwttokens.ts, bcrypt.ts, and the auth API routes indicate JWT-based sessions, password hashing, and server-side token lifecycle handling.
- refresh, set-cookie, and logout routes suggest cookies are used as the browser session boundary.
6. Password recovery and email verification
- The auth flow includes email-based verification for sign-up and forgot-password reset.
- nodemailer.ts, utils/generaterandomstring.ts, and utils/regex.ts support OTP generation, validation, and email delivery.
- This creates a separate recovery sub-flow from the normal login flow: user submits email → receives OTP/link → verifies → resets password.
7. Realtime chat as a separate service boundary
- SocketServer/src/Server.ts and SocketServer/src/mongoosedb.ts indicate a standalone server that connects to MongoDB and handles realtime communication.
- The Next.js app’s chat UI (dashboard/chat) likely consumes both HTTP APIs and socket connections.
- src/utils/socket.ts is the client-side integration point between the web app and the socket server.
8. Data and persistence layer
- src/db.ts is the main database access helper for the Next.js app.
- The presence of mongoosedb.ts in the socket server strongly suggests MongoDB is the shared persistence layer across both services.
- The app likely reads/writes user, post, follow, and chat data through these server-side database helpers rather than directly from the client.
9. Dashboard data flow
- The dashboard UI is built from smaller components in src/app/dashboard/_components such as feed, navbar, right rail, and mini profile.
- User actions in these components flow to /api/dashboard/* routes, which then hit the database and return updated state.
- This area is the core “authenticated social feed” subsystem: posts, follows, search, and profile personalization.
10. Profile management
- src/app/profile/settings and src/app/api/dashboard/updateprofile* show that profile editing is handled as a dedicated subsystem.
- Bio and links are updated via API endpoints rather than inline client state, keeping profile persistence server-owned.
- Dynamic profile pages (profile/[username]) separate public profile rendering from authenticated settings editing.
11. Shared client/server component boundaries
- src/components holds reusable forms, buttons, and client wrappers used across auth and dashboard flows.
- ClientWrapper.tsx suggests the app isolates browser-only behavior from server-rendered pages where needed.
- This separation matters because the app mixes server components, client components, and server route handlers.
12. Cross-cutting infrastructure
- middleware.ts likely guards protected routes and/or redirects unauthenticated users.
- next.config.ts, eslint.config.mjs, postcss.config.mjs, and tsconfig.json reflect a standard TypeScript/Next.js build pipeline.
- Environment configuration is externalized via .env.example, implying runtime secrets such as DB and auth credentials.
13. How to draw the architecture
- A good diagram would show three main zones: browser/UI, Next.js app server, and SocketServer realtime service, with MongoDB underneath both backend services.
- Inside the Next.js app, separate the auth, dashboard, and profile domains, and connect them to their matching API routes.
- Highlight email delivery as an external dependency used only by recovery/verification flows, and treat auth cookies/JWTs as the boundary between browser and server.
Main entry points: db.ts DB Helper · auth Auth API · forgetpassword Recovery API · dashboard Dashboard API
Components 19
Browser UI
User-facing interface and session boundary.
- Browser · Loads the app, signs in, and uses dashboard and chat flows.
Next.js App
Primary full-stack application with routes, UI, and HTTP APIs.
- Landing · Public entry page for the site.
Echoora/src/app/page.tsx - Auth UI · Sign-in, sign-up, and password recovery screens.
Echoora/src/app/(auth) - Dashboard UI · Authenticated feed, navigation, and chat experience.
Echoora/src/app/dashboard - Profile UI · Public profile pages and profile settings screens.
Echoora/src/app/profile - Auth API · Sign-in, sign-up, refresh, cookie, logout, and delete endpoints.
Echoora/src/app/api/auth - Recovery API · Forgot-password and email verification flows.
Echoora/src/app/api/forgetpassword - Dashboard API · Chat, posts, follows, search, and profile update endpoints.
Echoora/src/app/api/dashboard - Middleware · Protects routes and mediates access to authenticated areas.
Echoora/src/middleware.ts - DB Helper · Main database access layer for the Next.js app.
Echoora/src/db.ts - Auth Libs · JWT, password hashing, and email delivery helpers.
Echoora/src/libs - Shared Forms · Reusable auth forms, buttons, and client wrapper utilities.
Echoora/src/components - Feed Widgets · Navbar, feed, right rail, mini profile, and chat panes.
Echoora/src/app/dashboard/_components - Profile Widgets · Profile sidebar and profile-specific rendering pieces.
Echoora/src/app/profile - Socket Client · Browser-side connection helper for realtime chat.
Echoora/src/utils/socket.ts
Realtime Service
Standalone SocketServer for chat and live messaging.
- Socket Server · Standalone Node service handling realtime messaging.
SocketServer/src/Server.ts - Socket DB · MongoDB connection used by the realtime service.
SocketServer/src/mongoosedb.ts
External Services
Shared persistence and email delivery dependencies.
- MongoDB · Shared persistence for users, posts, follows, chat, and session data.
- Email Service · Outbound email delivery for signup verification and password recovery.
Connections 24
- Browser → Landing: visit · Loads the public entry page.
- Browser → Auth UI: auth UI · Uses sign-in, sign-up, and recovery screens.
- Browser → Dashboard UI: use app · Interacts with the authenticated dashboard.
- Browser → Profile UI: view profile · Views public profiles and settings.
- Browser → Auth API: credentials · Submits sign-in and sign-up requests.
- Browser → Recovery API: recovery · Starts verification and password reset flows.
- Browser → Dashboard API: actions · Sends chat, follow, post, search, and profile updates.
- Browser → Socket Client: realtime · Connects chat UI to the realtime backend.
- Middleware → Dashboard UI: protect · Restricts authenticated routes.
- Middleware → Profile UI: protect · Helps gate profile settings and authenticated views.
- Auth UI → Shared Forms: render · Reuses shared sign-in and sign-up forms.
- Dashboard UI → Feed Widgets: compose · Assembles the feed and chat experience from widgets.
- Profile UI → Profile Widgets: compose · Uses profile-specific UI pieces.
- Auth API → Auth Libs: verify · Uses JWT and password helpers.
- Recovery API → Auth Libs: verify · Uses OTP and mail helpers for recovery.
- Dashboard API → DB Helper: read/write · Persists and queries social and profile data.
- Auth API → DB Helper: read/write · Handles auth-related persistence.
- Recovery API → DB Helper: read/write · Stores verification and reset state.
- DB Helper → MongoDB: connect · Reads and writes application data.
- Socket Server → Socket DB: connect · Uses MongoDB from the realtime service.
- Socket DB → MongoDB: persist · Shares the database backend with the Next.js app.
- Socket Client → Socket Server: ws · Opens realtime chat connections.
- Auth Libs → Email Service: send mail · Delivers verification and reset emails.
- Dashboard API → Socket Server: chat bridge · Chat API and sockets coordinate around realtime messaging.