# nirmalravidas/advanced-mern-authentication architecture

> Architecture diagram of the GitHub repository nirmalravidas/advanced-mern-authentication, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nirmalravidas/advanced-mern-authentication
- Repository: https://github.com/nirmalravidas/advanced-mern-authentication

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) authentication system.
- Purpose: provide secure user registration, login, email verification, password reset, and JWT-based sessions.

##### File structure
- Top-level: two directories, “backend” (Express API) and “frontend” (React + Tailwind UI).
- Backend modules:
- controller (business logic)
- routes (Express endpoints)
- models (Mongoose schemas)
- middlewares (auth guard)
- db (MongoDB connection)
- mail (Nodemailer setup and templates)
- utils (JWT & verification code generators)
- Frontend modules:
- auth pages & forms (Signup, Login, Forgot/Reset, Verify)
- UI components (buttons, cards, inputs)
- layout & theming
- store (Zustand or similar for user state)
- schema validation (Zod or Yup)
- Config files: tsconfig, package.json, Vite config, ESLint.

##### README for additional insights
- Tech stack: React + Tailwind, Node.js + Express, MongoDB, bcrypt, JWT, email verification.
- Features listed match folder contents.

##### Detailed breakdown to capture all essential elements
- Routes layer (user.route.ts) → Controller layer (user.controller.ts) → Service/Utils (generateToken, connectDB) → Models (user.model.ts) → middlewares (isAuthenticated) → mail submodule
- Pages (Login.tsx, Signup.tsx, Forgot/Reset/Verify)
- Components (forms under components/auth)
- Layout & Theme (MainLayout, theme-provider)
- Store (useUserStore)
- Schema validation (userSchema)
- Data flows:
- Signup → POST /api/users/register → DB create user → send verification email → client verifies via GET /api/users/verify?code=…
- Login → POST /api/users/login → DB check & bcrypt compare → JWT issued → client stores token
- Forgot password → POST /api/users/forgot → send reset email → client uses token to POST /api/users/reset

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend Cluster
    subgraph "Frontend (React + Tailwind)" 
        direction TB
        F_MAIN["main.tsx"]:::frontend
        F_APP["App.tsx"]:::frontend
        subgraph "Auth Pages" 
            direction TB
            SIGNUP_PAGE["Signup.tsx"]:::frontend
            LOGIN_PAGE["Login.tsx"]:::frontend
            FORGOT_PAGE["ForgotPassword.tsx"]:::frontend
            RESET_PAGE["ResetPassword.tsx"]:::frontend
            VERIFY_PAGE["VerifyEmail.tsx"]:::frontend
        end
        subgraph "Auth Forms" 
            direction TB
            SIGNUP_FORM["SignupForm.tsx"]:::frontend
            LOGIN_FORM["LoginForm.tsx"]:::frontend
            FORGOT_FORM["ForgotPasswordForm.tsx"]:::frontend
            RESET_FORM["ResetPasswordForm.tsx"]:::frontend
            VERIFY_FORM["VerifyEmailForm.tsx"]:::frontend
        end
        subgraph "UI Component Library"
            direction TB
            UI_COMP["ui/*"]:::frontend
        end
        subgraph "Landing Components"
            direction TB
            HERO["hero.tsx"]:::frontend
            LOGO["logo.tsx"]:::frontend
            NAV_MENU["nav-menu.tsx"]:::frontend
            NAVBAR["navbar.tsx"]:::frontend
            NAV_SHEET["navigation-sheet.tsx"]:::frontend
        end
        subgraph "Layout & Theming"
            direction TB
            MAIN_LAYOUT["MainLayout.tsx"]:::frontend
            THEME_PROVIDER["theme-provider.tsx"]:::frontend
            MODE_TOGGLE["mode-toggle.tsx"]:::frontend
        end
        STORE["useUserStore.ts"]:::frontend
        SCHEMA["userSchema.ts"]:::frontend
    end

    %% Backend Cluster
    subgraph "Backend (Node.js + Express)" 
        direction TB
        BE_INDEX["index.ts"]:::backend
        BE_ROUTES["user.route.ts"]:::backend
        BE_CONTROLLER["user.controller.ts"]:::backend
        BE_MIDDLEWARE["isAuthenticated.ts"]:::backend
        subgraph "Utilities"
            direction TB
            BE_UTIL_TOKEN["generateToken.ts"]:::backend
            BE_UTIL_CODE["generateVerificationCode.ts"]:::backend
        end
        BE_MODELS["user.model.ts"]:::backend
        BE_DB["connectDB.ts"]:::backend
        subgraph "Email Service"
            direction TB
            BE_MAIL_NOD["nodemailer.ts"]:::backend
            BE_MAIL_TEMP["emailTemplate.ts"]:::backend
            BE_MAIL_ES["emails.ts"]:::backend
        end
    end

    %% External Services
    DB_SERVER["MongoDB"]:::db
    EMAIL_SERVICE["SMTP (Nodemailer)"]:::external

    %% Frontend Flow
    F_MAIN --> F_APP
    F_APP --> SIGNUP_PAGE
    F_APP --> LOGIN_PAGE
    F_APP --> FORGOT_PAGE
    F_APP --> RESET_PAGE
    F_APP --> VERIFY_PAGE

    SIGNUP_PAGE --> SIGNUP_FORM
    LOGIN_PAGE --> LOGIN_FORM
    FORGOT_PAGE --> FORGOT_FORM
    RESET_PAGE --> RESET_FORM
    VERIFY_PAGE --> VERIFY_FORM

    F_APP --> UI_COMP
    F_APP --> HERO
    F_APP --> NAVBAR
    F_APP --> MAIN_LAYOUT
    F_APP --> THEME_PROVIDER
    F_APP --> MODE_TOGGLE
    F_APP --> STORE
    F_APP --> SCHEMA

    %% Client to Backend
    SIGNUP_FORM -->|HTTP/HTTPS POST /api/users/register| BE_ROUTES
    LOGIN_FORM -->|HTTP/HTTPS POST /api/users/login| BE_ROUTES
    FORGOT_FORM -->|HTTP/HTTPS POST /api/users/forgot| BE_ROUTES
    RESET_FORM -->|HTTP/HTTPS POST /api/users/reset| BE_ROUTES
    VERIFY_FORM -->|HTTP/HTTPS GET /api/users/verify| BE_ROUTES

    %% Backend Flow
    BE_INDEX --> BE_ROUTES
    BE_ROUTES -->|uses middleware| BE_MIDDLEWARE
    BE_ROUTES -->|calls| BE_CONTROLLER
    BE_CONTROLLER -->|CRUD & hash| BE_MODELS
    BE_CONTROLLER -->|generate JWT| BE_UTIL_TOKEN
    BE_CONTROLLER -->|generate code| BE_UTIL_CODE
    BE_CONTROLLER -->|send email| BE_MAIL_NOD
    BE_DB --> BE_MODELS
    BE_DB --> DB_SERVER
    BE_MAIL_NOD --> EMAIL_SERVICE
    BE_MAIL_NOD --> BE_MAIL_TEMP
    BE_MAIL_NOD --> BE_MAIL_ES

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#0288d1,stroke-width:1px
    classDef backend fill:#e8f5e9,stroke:#2e7d32,stroke-width:1px
    classDef db fill:#fff3e0,stroke:#ef6c00,stroke-width:1px
    classDef external fill:#eceff1,stroke:#607d8b,stroke-width:1px

    %% Click Events
    click F_MAIN "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/main.tsx"
    click F_APP "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/App.tsx"
    click SIGNUP_PAGE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/auth/Signup.tsx"
    click LOGIN_PAGE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/auth/Login.tsx"
    click FORGOT_PAGE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/auth/ForgotPassword.tsx"
    click RESET_PAGE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/auth/ResetPassword.tsx"
    click VERIFY_PAGE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/auth/VerifyEmail.tsx"
    click SIGNUP_FORM "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/auth/SignupForm.tsx"
    click LOGIN_FORM "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/auth/LoginForm.tsx"
    click FORGOT_FORM "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/auth/ForgotPasswordForm.tsx"
    click RESET_FORM "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/auth/ResetPasswordForm.tsx"
    click VERIFY_FORM "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/auth/VerifyEmailForm.tsx"
    click UI_COMP "https://github.com/nirmalravidas/advanced-mern-authentication/tree/main/frontend/src/components/ui/"
    click HERO "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/landing/Hero/hero.tsx"
    click LOGO "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/landing/Navbar/logo.tsx"
    click NAV_MENU "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/landing/Navbar/nav-menu.tsx"
    click NAVBAR "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/landing/Navbar/navbar.tsx"
    click NAV_SHEET "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/landing/Navbar/navigation-sheet.tsx"
    click MAIN_LAYOUT "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/layout/MainLayout.tsx"
    click THEME_PROVIDER "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/theme/theme-provider.tsx"
    click MODE_TOGGLE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/components/theme/mode-toggle.tsx"
    click STORE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/store/useUserStore.ts"
    click SCHEMA "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/frontend/src/schema/userSchema.ts"
    click BE_INDEX "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/index.ts"
    click BE_ROUTES "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/routes/user.route.ts"
    click BE_CONTROLLER "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/controller/user.controller.ts"
    click BE_MODELS "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/models/user.model.ts"
    click BE_MIDDLEWARE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/middlewares/isAuthenticated.ts"
    click BE_DB "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/db/connectDB.ts"
    click BE_MAIL_NOD "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/mail/nodemailer.ts"
    click BE_MAIL_TEMP "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/mail/emailTemplate.ts"
    click BE_MAIL_ES "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/mail/emails.ts"
    click BE_UTIL_TOKEN "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/utils/generateToken.ts"
    click BE_UTIL_CODE "https://github.com/nirmalravidas/advanced-mern-authentication/blob/main/backend/utils/generateVerificationCode.ts"
```
