# aditya18mew/echoora architecture

> Architecture diagram of the GitHub repository aditya18mew/echoora, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aditya18mew/echoora
- Repository: https://github.com/aditya18mew/echoora

## Overview

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: [`Echoora/src/db.ts`](https://github.com/aditya18mew/echoora/blob/main/Echoora/src/db.ts) (DB Helper), [`Echoora/src/app/api/auth`](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/auth) (Auth API), [`Echoora/src/app/api/forgetpassword`](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/forgetpassword) (Recovery API), [`Echoora/src/app/api/dashboard`](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/dashboard) (Dashboard API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser UI"]
  node_browser(("Browser<br/>client"))
end

subgraph group_nextjs["Next.js App"]
  node_landing["Landing<br/>page<br/>[page.tsx]"]
  node_auth_pages["Auth UI<br/>route group"]
  node_dashboard_ui["Dashboard UI<br/>route group"]
  node_profile_ui["Profile UI<br/>route group"]
  node_api_auth["Auth API<br/>http routes"]
  node_api_recovery["Recovery API<br/>http routes"]
  node_api_dashboard["Dashboard API<br/>http routes"]
  node_middleware{{"Middleware<br/>route guard<br/>[middleware.ts]"}}
  node_db_helper[("DB Helper<br/>data access<br/>[db.ts]")]
  node_auth_libs["Auth Libs<br/>security helpers"]
  node_shared_forms["Shared Forms<br/>ui components"]
  node_dashboard_components["Feed Widgets<br/>ui components"]
  node_profile_components["Profile Widgets<br/>ui components"]
  node_socket_client["Socket Client<br/>client socket<br/>[socket.ts]"]
end

subgraph group_socket["Realtime Service"]
  node_socket_server{{"Socket Server<br/>realtime server<br/>[Server.ts]"}}
  node_socket_db[("Socket DB<br/>mongo layer<br/>[mongoosedb.ts]")]
end

subgraph group_infra["External Services"]
  node_shared_mongo[("MongoDB<br/>database")]
  node_email_service["Email Service<br/>smtp"]
end

node_browser -->|"visit"| node_landing
node_browser -->|"auth UI"| node_auth_pages
node_browser -->|"use app"| node_dashboard_ui
node_browser -->|"view profile"| node_profile_ui
node_browser -->|"credentials"| node_api_auth
node_browser -->|"recovery"| node_api_recovery
node_browser -->|"actions"| node_api_dashboard
node_browser -->|"realtime"| node_socket_client
node_middleware -.->|"protect"| node_dashboard_ui
node_middleware -.->|"protect"| node_profile_ui
node_auth_pages -->|"render"| node_shared_forms
node_dashboard_ui -->|"compose"| node_dashboard_components
node_profile_ui -->|"compose"| node_profile_components
node_api_auth -->|"verify"| node_auth_libs
node_api_recovery -->|"verify"| node_auth_libs
node_api_dashboard -->|"read/write"| node_db_helper
node_api_auth -->|"read/write"| node_db_helper
node_api_recovery -->|"read/write"| node_db_helper
node_db_helper -->|"connect"| node_shared_mongo
node_socket_server -->|"connect"| node_socket_db
node_socket_db -->|"persist"| node_shared_mongo
node_socket_client -->|"ws"| node_socket_server
node_auth_libs -->|"send mail"| node_email_service
node_api_dashboard -.->|"chat bridge"| node_socket_server

click node_landing "https://github.com/aditya18mew/echoora/blob/main/Echoora/src/app/page.tsx"
click node_auth_pages "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/(auth)"
click node_dashboard_ui "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/dashboard"
click node_profile_ui "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/profile"
click node_api_auth "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/auth"
click node_api_recovery "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/forgetpassword"
click node_api_dashboard "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/dashboard"
click node_middleware "https://github.com/aditya18mew/echoora/blob/main/Echoora/src/middleware.ts"
click node_db_helper "https://github.com/aditya18mew/echoora/blob/main/Echoora/src/db.ts"
click node_auth_libs "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/libs"
click node_shared_forms "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/components"
click node_dashboard_components "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/dashboard/_components"
click node_profile_components "https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/profile"
click node_socket_client "https://github.com/aditya18mew/echoora/blob/main/Echoora/src/utils/socket.ts"
click node_socket_server "https://github.com/aditya18mew/echoora/blob/main/SocketServer/src/Server.ts"
click node_socket_db "https://github.com/aditya18mew/echoora/blob/main/SocketServer/src/mongoosedb.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_browser toneBlue
class node_landing,node_auth_pages,node_dashboard_ui,node_profile_ui,node_api_auth,node_api_recovery,node_api_dashboard,node_middleware,node_db_helper,node_auth_libs,node_shared_forms,node_dashboard_components,node_profile_components,node_socket_client toneAmber
class node_socket_server,node_socket_db toneMint
class node_shared_mongo,node_email_service toneRose
```

## Components

### Browser UI

User-facing interface and session boundary.

- **Browser**: client · 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](https://github.com/aditya18mew/echoora/blob/main/Echoora/src/app/page.tsx): page · Public entry page for the site. · `Echoora/src/app/page.tsx`
- [Auth UI](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/(auth)): route group · Sign-in, sign-up, and password recovery screens. · `Echoora/src/app/(auth)`
- [Dashboard UI](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/dashboard): route group · Authenticated feed, navigation, and chat experience. · `Echoora/src/app/dashboard`
- [Profile UI](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/profile): route group · Public profile pages and profile settings screens. · `Echoora/src/app/profile`
- [Auth API](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/auth): http routes · Sign-in, sign-up, refresh, cookie, logout, and delete endpoints. · `Echoora/src/app/api/auth`
- [Recovery API](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/forgetpassword): http routes · Forgot-password and email verification flows. · `Echoora/src/app/api/forgetpassword`
- [Dashboard API](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/api/dashboard): http routes · Chat, posts, follows, search, and profile update endpoints. · `Echoora/src/app/api/dashboard`
- [Middleware](https://github.com/aditya18mew/echoora/blob/main/Echoora/src/middleware.ts): route guard · Protects routes and mediates access to authenticated areas. · `Echoora/src/middleware.ts`
- [DB Helper](https://github.com/aditya18mew/echoora/blob/main/Echoora/src/db.ts): data access · Main database access layer for the Next.js app. · `Echoora/src/db.ts`
- [Auth Libs](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/libs): security helpers · JWT, password hashing, and email delivery helpers. · `Echoora/src/libs`
- [Shared Forms](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/components): ui components · Reusable auth forms, buttons, and client wrapper utilities. · `Echoora/src/components`
- [Feed Widgets](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/dashboard/_components): ui components · Navbar, feed, right rail, mini profile, and chat panes. · `Echoora/src/app/dashboard/_components`
- [Profile Widgets](https://github.com/aditya18mew/echoora/tree/main/Echoora/src/app/profile): ui components · Profile sidebar and profile-specific rendering pieces. · `Echoora/src/app/profile`
- [Socket Client](https://github.com/aditya18mew/echoora/blob/main/Echoora/src/utils/socket.ts): client socket · Browser-side connection helper for realtime chat. · `Echoora/src/utils/socket.ts`

### Realtime Service

Standalone SocketServer for chat and live messaging.

- [Socket Server](https://github.com/aditya18mew/echoora/blob/main/SocketServer/src/Server.ts): realtime server · Standalone Node service handling realtime messaging. · `SocketServer/src/Server.ts`
- [Socket DB](https://github.com/aditya18mew/echoora/blob/main/SocketServer/src/mongoosedb.ts): mongo layer · MongoDB connection used by the realtime service. · `SocketServer/src/mongoosedb.ts`

### External Services

Shared persistence and email delivery dependencies.

- **MongoDB**: database · Shared persistence for users, posts, follows, chat, and session data.
- **Email Service**: smtp · Outbound email delivery for signup verification and password recovery.

## Connections

- 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.
