# akashyap2013/mern_login_app_with_resetemail architecture

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

- Interactive diagram: https://gitdiagram.com/akashyap2013/mern_login_app_with_resetemail
- Repository: https://github.com/akashyap2013/mern_login_app_with_resetemail

## Overview

##### Project type and purpose
- This is a full-stack MERN (MongoDB, Express, React, Node.js) application that implements user authentication flows: register, login, profile viewing, password recovery and reset.
- The client (“client/”) is a React single-page app; the server (“server/”) is a Node.js/Express REST API. It uses MongoDB Atlas for persistent storage and Nodemailer (via an Ethereal test account) to send reset emails.

##### File structure
- client/
- public/: static HTML + manifest
- src/: React components, hooks, middleware, helper functions, and global state store (Redux-like)
- middleware/auth.js: client-side route protection
- hooks/fetch.hook.js: custom fetch wrapper for API calls
- server/
- controllers/: business logic (appController.js, mailer.js)
- model/User.model.js: Mongoose schema for users
- database/conn.js: MongoDB connection setup
- router/route.js: Express routes for auth flows
- middleware/auth.js: JWT validation for protected routes
- server.js: express app bootstrap
- Config files: .env on client, config.js on server

##### README for additional insights
- Describes environment variables and usage.
- Emphasizes use of JWT_SECRET, MongoDB Atlas, and Ethereal email credentials.

##### Detailed breakdown
- Middleware chains on both sides (client auth middleware, server JWT middleware)
- API endpoints (e.g., POST /register, POST /login, GET /profile, POST /reset)
- Data flows (credentials, JWT tokens, password reset tokens)
- Error flows (e.g., 401 → redirect to login)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Frontend UI Layer
    subgraph "Frontend (UI Layer)"
        direction TB
        App["React App (App.js)"]:::ui
        Components["UI Components (client/src/components)"]:::ui
        AuthMWClient["Client Auth Middleware (middleware/auth.js)"]:::ui
        FetchHook["Custom Fetch Hook (hooks/fetch.hook.js)"]:::ui
        Store["Global State Store (store/store.js)"]:::ui
        PublicAssets["Public Assets (public/)"]:::ui
    end

    %% Backend Server Layer
    subgraph "Backend (Server)"
        direction TB
        ServerEntry["Server Entry (server.js)"]:::server
        Router["API Router (router/route.js)"]:::server
        AuthMWServer["JWT Validation Middleware (middleware/auth.js)"]:::server
        Controllers["Controllers"]:::server
        subgraph "Controllers"
            direction TB
            AuthController["Auth & Profile Controller (controllers/appController.js)"]:::server
            MailerController["Email Controller (controllers/mailer.js)"]:::server
        end
        Model["User Model (model/User.model.js)"]:::server
        DBConn["DB Connection (database/conn.js)"]:::server
    end

    %% External Services
    MongoDB[(MongoDB Atlas)]:::external
    SMTP["SMTP Service (Ethereal)"]:::external

    %% Connections - Frontend
    App -->|renders| Components
    Components -->|dispatch actions| Store
    App -->|uses| AuthMWClient
    App -->|calls API via| FetchHook
    FetchHook -->|HTTP requests| Router

    %% Connections - Backend
    ServerEntry -->|uses| Router
    Router -->|protect routes| AuthMWServer
    Router -->|handles endpoints| AuthController
    Router -->|handles reset| MailerController
    AuthController -->|CRUD users| Model
    MailerController -->|sends emails| SMTP
    Model -->|connects via| DBConn
    DBConn -->|connects to| MongoDB

    %% Password reset flow
    SMTP -->|email link| App

    %% Click Events
    click App "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/client/src/App.js"
    click Components "https://github.com/akashyap2013/mern_login_app_with_resetemail/tree/Main/client/src/components"
    click AuthMWClient "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/client/src/middleware/auth.js"
    click FetchHook "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/client/src/hooks/fetch.hook.js"
    click Store "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/client/src/store/store.js"
    click PublicAssets "https://github.com/akashyap2013/mern_login_app_with_resetemail/tree/Main/client/public"
    click ServerEntry "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/server/server.js"
    click Router "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/server/router/route.js"
    click AuthController "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/server/controllers/appController.js"
    click MailerController "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/server/controllers/mailer.js"
    click AuthMWServer "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/server/middleware/auth.js"
    click Model "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/server/model/User.model.js"
    click DBConn "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/server/database/conn.js"
    click SMTP "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/.env"
    click Store "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/client/package.json"
    click ServerEntry "https://github.com/akashyap2013/mern_login_app_with_resetemail/blob/Main/server/package.json"

    %% Styles
    classDef ui fill:#e0f7da,stroke:#2d7f5e,color:#2d7f5e
    classDef server fill:#d0e7ff,stroke:#1f5fa0,color:#1f5fa0
    classDef external fill:#ffe3b3,stroke:#b36f00,color:#b36f00
```
