# aayushmaan-54/authn-mern-app architecture

> Architecture diagram of the GitHub repository aayushmaan-54/authn-mern-app, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aayushmaan-54/authn-mern-app
- Repository: https://github.com/aayushmaan-54/authn-mern-app

## Overview

##### Component Details

A. Frontend Section (Top):
- React Components (group by features: Auth, Profile, Users)
- Redux Store (show slices: auth, email, search)
- Router Configuration

B. Backend Section (Middle):
- Express Server
- Middleware (authMiddleware)
- Controllers (userController)
- Route Handlers

C. Database & Services Section (Bottom):
- MongoDB (with User and Token collections)
- External Services:
- Google OAuth 2.0
- Cloudinary
- Gmail/Nodemailer

##### Connection Flows

- Authentication flows:
- Regular login flow
- OAuth flow
- Device verification flow
- API requests between frontend and backend
- Data flow between backend and database
- External service interactions

##### Specific Implementation Details

Frontend Architecture:
**React App**
- Components (Auth, Layout, UI)
- Pages (Auth, Profile, Users)
- Redux Store
- Auth Slice
- Email Slice
- Search Slice
- Router

Backend Architecture:
**Express Server**
- Middleware (Auth, Validation)
- Controllers
- Models (User, Token)
- Routes
- Utils (JWT, Email)

##### Important Flows to Highlight

Authentication Flows:
- Registration with email verification
- Login with device recognition
- Password reset flow
- OAuth authentication

Data Flows:
- User profile updates
- Role management
- Session handling

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef frontend fill:#e1f5fe,stroke:#01579b
    classDef backend fill:#e8f5e9,stroke:#1b5e20
    classDef database fill:#fff3e0,stroke:#e65100
    classDef external fill:#f3e5f5,stroke:#4a148c
    classDef security fill:#ffebee,stroke:#b71c1c

    %% Frontend Layer
    subgraph Frontend
        ReactApp["React Application"]
        Components["React Components"]:::frontend
        AuthPages["Authentication Pages"]:::frontend
        ProfilePage["Profile Management"]:::frontend
        UsersPage["User Management"]:::frontend
        
        subgraph ReduxStore["Redux Store"]
            AuthSlice["Auth Slice"]:::frontend
            EmailSlice["Email Slice"]:::frontend
            SearchSlice["Search Slice"]:::frontend
        end
        
        Router["Frontend Router"]:::frontend
        AuthService["Authentication Services"]:::frontend
        EmailService["Email Services"]:::frontend
    end

    %% Backend Layer
    subgraph Backend
        Express["Express Server"]:::backend
        AuthMiddleware["Auth Middleware"]:::backend
        UserController["User Controller"]:::backend
        Routes["API Routes"]:::backend
        
        subgraph Utils
            JWTUtil["JWT Utilities"]:::backend
            EmailUtil["Email Service"]:::backend
            Templates["Email Templates"]:::backend
        end
    end

    %% Data Layer
    subgraph DataLayer
        DBConfig["Database Config"]:::database
        
        subgraph MongoDB["MongoDB"]
            UserModel["User Model"]:::database
            TokenModel["Token Model"]:::database
        end
        
        subgraph ExternalServices["External Services"]
            GoogleOAuth["Google OAuth 2.0"]:::external
            Cloudinary["Cloudinary"]:::external
            Gmail["Gmail/Nodemailer"]:::external
        end
    end

    %% Relationships
    ReactApp --> Components
    Components --> AuthPages
    Components --> ProfilePage
    Components --> UsersPage
    Components --> Router
    ReactApp --> ReduxStore
    AuthService --> AuthSlice
    EmailService --> EmailSlice
    
    Router --> Express
    Express --> AuthMiddleware
    AuthMiddleware --> UserController
    UserController --> Routes
    Routes --> JWTUtil
    Routes --> EmailUtil
    EmailUtil --> Templates
    EmailUtil --> Gmail
    
    UserController --> MongoDB
    Express --> GoogleOAuth
    UserController --> Cloudinary
    
    DBConfig --> MongoDB

    %% Click Events
    click Components "https://github.com/aayushmaan-54/AuthN-MERN-App/tree/main/frontend/src/components/"
    click AuthPages "https://github.com/aayushmaan-54/AuthN-MERN-App/tree/main/frontend/src/pages/auth/"
    click ReduxStore "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/frontend/src/redux/store.js"
    click AuthSlice "https://github.com/aayushmaan-54/AuthN-MERN-App/tree/main/frontend/src/redux/features/auth/"
    click EmailSlice "https://github.com/aayushmaan-54/AuthN-MERN-App/tree/main/frontend/src/redux/features/email/"
    click SearchSlice "https://github.com/aayushmaan-54/AuthN-MERN-App/tree/main/frontend/src/redux/features/search/"
    click Router "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/frontend/src/router/route.jsx"
    click Express "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/index.js"
    click AuthMiddleware "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/middleware/authMiddleware.js"
    click UserController "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/controllers/userController.js"
    click UserModel "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/model/userSchema.js"
    click TokenModel "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/model/tokenSchema.js"
    click Routes "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/router/route.js"
    click JWTUtil "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/utils/jwt.js"
    click EmailUtil "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/utils/sendEmail.js"
    click Templates "https://github.com/aayushmaan-54/AuthN-MERN-App/tree/main/backend/views/"
    click DBConfig "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/backend/config/db.js"
    click ProfilePage "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/frontend/src/pages/profile/Profile.jsx"
    click UsersPage "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/frontend/src/pages/usersList/UsersList.jsx"
    click AuthService "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/frontend/src/redux/features/auth/authService.js"
    click EmailService "https://github.com/aayushmaan-54/AuthN-MERN-App/blob/main/frontend/src/redux/features/email/emailService.js"
```
