# hemantnikumbh/hemantportfolio architecture

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

- Interactive diagram: https://gitdiagram.com/hemantnikumbh/hemantportfolio
- Repository: https://github.com/hemantnikumbh/hemantportfolio

## Overview

##### Project Type and Purpose
- The project is a MERN stack portfolio website.
- Its main goal is to display portfolio information dynamically, support user authentication, and allow secure administrative updates.
- The frontend is built with React.js (client folder) and the backend is built with Node.js and Express (server, controller, router folders), with MongoDB as the database.

##### Main Components
a. Frontend (Client):
- Client: React application containing the user interface.
- Components: Reusable UI elements such as Navbar, Footer, Layout (Admin-Layout specifically noted for admin pages).
- Pages: Different pages (Home, About, Contact, Login, Register, etc.).
- Assets & Store: Styles, images, and state management (auth state using React Hooks).
- Build/Entry Points: Main.jsx, App.jsx, index.html, and configuration scripts (vite.config.js and eslint.config.js).

b. Backend:
- Controllers: Business logic for admin, auth, contacts, and service functionality.
- Routers: API endpoint definitions for admin, auth, contact, and service routes.
- Server: The backend entry point (index.js) and additional supporting modules.
- Validators & Middleware: Input validation, authentication middleware, error handling (found in server/validator and its middleware).
- Models: Schema definitions using Mongoose for contacts, services, and users (located under server/validator/model).

c. Database & Utils:
- Database Configuration: Although a config folder isn’t explicitly present, the utils/db.js file indicates an abstraction layer for database connectivity, most likely to MongoDB.
- Environment & Configuration: .env file holds environment variables crucial for database credentials, API keys, and system-level configurations.

##### Relationships and Interactions
- The Client’s React app makes HTTP requests (RESTful API calls) to the backend.
- The Server routes these requests through defined routers which then call the relevant controllers.
- Controllers interact with the database via models and the utils (db connection).
- Middleware in the validator folder processes requests for authentication, admin checks, and error handling.
- All parts operate under the defined environment configurations (managed through .env).

##### Architectural Patterns & Design Principles
- Separation of Concerns: Frontend and backend code are clearly separated. Within the backend, controllers, routers, and validators form distinct layers.
- RESTful Architecture: The API endpoints are designed following REST principles.
- Modular Architecture: Each feature (authentication, services, contacts) is organized into its own module.
- State Management in React: Uses React Hooks (and possibly Context API) for managing application state.

##### Technologies, Frameworks, and Libraries
- Frontend: React.js, Vite (as indicated by vite.config.js), and possibly ESLint for code styling.
- Backend: Node.js, Express.js, and Mongoose (implied via models) for communication with MongoDB.
- Utilities: Environment configuration via .env, and a centralized DB module.
- Admin Panel: Special components (Admin-Layout, Admin-Cotacts, Admin-Users, Admin_Update pages) to highlight secure administrative functionality.

- Data flow (from frontend UI → API call → router → controller → model/database).
- Dependencies (middleware intercepting API calls).
- Fields in this project are represented – from high-level modules to individual middleware functions and model definitions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Section
    subgraph "Frontend (Client)"
        RC["React Client"]:::frontend
        subgraph "UI Components"
            Navbar["Navbar"]:::frontend
            Footer["Footer"]:::frontend
            AdminLayout["Admin Layout"]:::frontend
        end
        Pages["Frontend Pages"]:::frontend
        Store["Auth Store"]:::frontend
        subgraph "Build & Entry Points"
            Main["Main.jsx"]:::frontend
            App["App.jsx"]:::frontend
            HTML["index.html"]:::frontend
            Vite["Vite Config"]:::frontend
        end
    end

    %% Backend Section
    subgraph "Backend (Server)"
        Server["Server Entry (index.js)"]:::backend
        subgraph "Controllers"
            AdminController["Admin Controller"]:::backend
            AuthController["Auth Controller"]:::backend
            ContactController["Contact Controller"]:::backend
            ServiceController["Service Controller"]:::backend
        end
        subgraph "Routers"
            AdminRouter["Admin Router"]:::backend
            AuthRouter["Auth Router"]:::backend
            ContactRouter["Contact Router"]:::backend
            ServiceRouter["Service Router"]:::backend
        end
        subgraph "Validators & Middleware"
            Validator["Validator"]:::backend
            subgraph "Middleware"
                AdminMiddleware["Admin Middleware"]:::backend
                AuthMiddleware["Auth Middleware"]:::backend
                ErrorMiddleware["Error Middleware"]:::backend
                ValidateMiddleware["Validation Middleware"]:::backend
            end
        end
        subgraph "Models"
            UserModel["User Model"]:::backend
            ContactModel["Contact Model"]:::backend
            ServiceModel["Service Model"]:::backend
        end
        DBUtility["Database Connection Utility (db.js)"]:::backend
        Env["Environment (.env)"]:::config
    end

    %% Database Section
    MongoDB["MongoDB Database"]:::database

    %% Connections between Frontend and Backend
    RC -->|"API_call"| AdminRouter
    RC -->|"API_call"| AuthRouter
    RC -->|"API_call"| ContactRouter
    RC -->|"API_call"| ServiceRouter

    %% Routers to Controllers via Middleware/Validation
    AdminRouter -->|"validate"| Validator
    AuthRouter -->|"validate"| Validator
    ContactRouter -->|"validate"| Validator
    ServiceRouter -->|"validate"| Validator

    Validator -->|"pass"| AdminMiddleware
    Validator -->|"pass"| AuthMiddleware
    Validator -->|"pass"| ErrorMiddleware
    Validator -->|"pass"| ValidateMiddleware

    AdminRouter -->|"forward"| AdminController
    AuthRouter -->|"forward"| AuthController
    ContactRouter -->|"forward"| ContactController
    ServiceRouter -->|"forward"| ServiceController

    %% Controllers interacting with Models and Database
    AdminController -->|"uses"| UserModel
    AuthController -->|"uses"| UserModel
    ContactController -->|"uses"| ContactModel
    ServiceController -->|"uses"| ServiceModel

    AdminController -->|"query"| DBUtility
    AuthController -->|"query"| DBUtility
    ContactController -->|"query"| DBUtility
    ServiceController -->|"query"| DBUtility

    DBUtility -->|"connects"| MongoDB

    %% Environment influence
    Env --- RC
    Env --- Server
    Env --- DBUtility

    %% Click Events for Frontend
    click RC "https://github.com/hemantnikumbh/hemantportfolio/tree/main/client"
    click Navbar "https://github.com/hemantnikumbh/hemantportfolio/blob/main/client/src/Components/Navbar.jsx"
    click Footer "https://github.com/hemantnikumbh/hemantportfolio/blob/main/client/src/Components/Footer.jsx"
    click AdminLayout "https://github.com/hemantnikumbh/hemantportfolio/blob/main/client/src/Components/Layout/Admin-Layout.jsx"
    click Pages "https://github.com/hemantnikumbh/hemantportfolio/tree/main/client/src/pages"
    click Store "https://github.com/hemantnikumbh/hemantportfolio/blob/main/client/src/store/auth.jsx"
    click Main "https://github.com/hemantnikumbh/hemantportfolio/blob/main/client/src/main.jsx"
    click App "https://github.com/hemantnikumbh/hemantportfolio/blob/main/client/src/App.jsx"
    click HTML "https://github.com/hemantnikumbh/hemantportfolio/blob/main/client/index.html"
    click Vite "https://github.com/hemantnikumbh/hemantportfolio/blob/main/client/vite.config.js"

    %% Click Events for Backend Controllers and Routers
    click AdminController "https://github.com/hemantnikumbh/hemantportfolio/blob/main/controller/admin_controller.js"
    click AuthController "https://github.com/hemantnikumbh/hemantportfolio/blob/main/controller/auth_controller.js"
    click ContactController "https://github.com/hemantnikumbh/hemantportfolio/blob/main/controller/contact-controller.js"
    click ServiceController "https://github.com/hemantnikumbh/hemantportfolio/blob/main/controller/service-controller.js"
    click AdminRouter "https://github.com/hemantnikumbh/hemantportfolio/blob/main/router/admin-router.js"
    click AuthRouter "https://github.com/hemantnikumbh/hemantportfolio/blob/main/router/auth_router.js"
    click ContactRouter "https://github.com/hemantnikumbh/hemantportfolio/blob/main/router/contact-router.js"
    click ServiceRouter "https://github.com/hemantnikumbh/hemantportfolio/blob/main/router/service-route.js"
    click Server "https://github.com/hemantnikumbh/hemantportfolio/blob/main/index.js"

    %% Click Events for Validators & Middleware
    click Validator "https://github.com/hemantnikumbh/hemantportfolio/blob/main/server/validator/auth_validatore.js"
    click AdminMiddleware "https://github.com/hemantnikumbh/hemantportfolio/blob/main/server/validator/middleware/admin-middleware.js"
    click AuthMiddleware "https://github.com/hemantnikumbh/hemantportfolio/blob/main/server/validator/middleware/authMiddleware.js"
    click ErrorMiddleware "https://github.com/hemantnikumbh/hemantportfolio/blob/main/server/validator/middleware/errr-middleware.js"
    click ValidateMiddleware "https://github.com/hemantnikumbh/hemantportfolio/blob/main/server/validator/middleware/validate_middleware.js"

    %% Click Events for Models, DB and Environment
    click UserModel "https://github.com/hemantnikumbh/hemantportfolio/blob/main/server/validator/model/user-model.js"
    click ContactModel "https://github.com/hemantnikumbh/hemantportfolio/blob/main/server/validator/model/contact-model.js"
    click ServiceModel "https://github.com/hemantnikumbh/hemantportfolio/blob/main/server/validator/model/service-model.js"
    click DBUtility "https://github.com/hemantnikumbh/hemantportfolio/blob/main/utils/db.js"
    click Env "https://github.com/hemantnikumbh/hemantportfolio/blob/main/.env"

    %% Styles
    classDef frontend fill:#a1c4fd,stroke:#0e2431,stroke-width:2px;
    classDef backend fill:#c3fdb8,stroke:#0e3a0e,stroke-width:2px;
    classDef config fill:#fff3b0,stroke:#7a6700,stroke-width:2px;
    classDef database fill:#ffd3b6,stroke:#ad5600,stroke-width:2px;
```
