# yatharth-2906/linknest architecture

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

- Interactive diagram: https://gitdiagram.com/yatharth-2906/linknest
- Repository: https://github.com/yatharth-2906/linknest

## Overview

##### Main Components
- Frontend: A React-based single-page application (SPA) using Vite as its build tool. It includes multiple components (e.g., HomePage, LoginPage, SignupPage, Profile) and context providers (UserProvider) for state management.
- Backend: A Node.js/Express server that is structured using an MVC-like pattern. It includes controllers (for static content and user-related operations), models (trees, urls, user), service modules (e.g., auth service for JWT authentication), and route definitions (handling static and user endpoints).
- Database: MongoDB (as indicated in the README) where user data, nests, and associated links are stored.
- External/Deployment Configurations: Environment variables for secure credentials, Vercel configuration files, and deployment scripts.

##### Component Interactions and Dependencies
- Additional Backend Services: The auth service handles JWT verification and token issuance. This service is used across various routes/controllers.
- Static Assets & Deployment: Highlight configuration files (e.g., vercel.json in both frontend and backend) that indicate deployment and environment management.

##### Architectural Patterns and Design Principles
- MVC Structure: Show a separation of concerns in the backend – controllers (handling HTTP requests), models (defining data structure), and routes (mapping endpoints) interact in a cohesive manner.
- Service Layer/Authentication: Mark the authentication service separately to clarify that JWT authentication is used for secure routes.
- Frontend Component Hierarchy: Demonstrate how high-level pages (like HomePage, Profile, etc.) link to context providers for state management and how these components communicate with the backend API.

##### Technologies and Their Roles
- Frontend: React.js (component-based UI), Vite (development and build bundler), CSS modules for component-level styling.
- Backend: Node.js and Express.js, along with middleware such as the logger, to handle HTTP requests and connect controllers to routes.
- MongoDB: The NoSQL database used for storing structured data.
- JWT: For secure authentication and session management.
- Vercel: Configuration files for deployment (indicated by vercel.json in both frontend and backend directories).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Section
    subgraph "Frontend"
        FHP["HomePage"] 
        FLP["LoginPage"]
        FSP["SignupPage"]
        FP["Profile"]
        FUP["UserProvider"]
        FVite["Vite Config"]
        FVer["Deployment Config"]
    end

    %% Backend Section
    subgraph "Backend"
        BS["Express Server (index.js)"]
        BDC["Database Connection"]
        BR_STATIC["Static Routes"]
        BR_USER["User Routes"]
        BC_STATIC["Static Controller"]
        BC_USER["User Controller"]
        BAUTH["Auth Service (JWT)"]
        BM_Trees["Trees Model"]
        BM_URLs["URLs Model"]
        BM_User["User Model"]
        BVer["Deployment Config"]
    end

    %% Database Section
    subgraph "Database"
        MDB["MongoDB"]
    end

    %% Frontend -> Backend API calls
    FLP -->|"calls"| BR_USER
    FSP -->|"calls"| BR_USER
    FHP -->|"calls"| BR_STATIC
    FP  -->|"calls"| BR_STATIC

    %% Backend internal flow
    BS --> BR_STATIC
    BS --> BR_USER
    BS -->|"init DB"| BDC

    BR_STATIC --> BC_STATIC
    BR_USER   --> BC_USER

    %% Controllers invoking services and models
    BC_USER   -->|"validates"| BAUTH
    BC_STATIC -->|"manages data"| BM_Trees
    BC_USER   -->|"manages data"| BM_User
    BC_USER   -->|"manages links"| BM_URLs

    %% Database interactions
    BDC --> BM_Trees
    BDC --> BM_User
    BDC --> BM_URLs
    BM_Trees --> MDB
    BM_User  --> MDB
    BM_URLs  --> MDB

    %% Styling classes
    classDef frontendClass fill:#cfe2f3,stroke:#6fa8dc,stroke-width:2px;
    classDef backendClass fill:#d9ead3,stroke:#6aa84f,stroke-width:2px;
    classDef database fill:#f4cccc,stroke:#cc0000,stroke-width:2px;

    class FHP,FLP,FSP,FP,FUP,FVite,FVer frontendClass;
    class BS,BDC,BR_STATIC,BR_USER,BC_STATIC,BC_USER,BAUTH,BM_Trees,BM_URLs,BM_User,BVer backendClass;
    class MDB database;

    %% Click Events for Frontend Components
    click FHP "https://github.com/yatharth-2906/linknest/blob/main/frontend/src/HomePage.jsx"
    click FLP "https://github.com/yatharth-2906/linknest/blob/main/frontend/src/LoginPage.jsx"
    click FSP "https://github.com/yatharth-2906/linknest/blob/main/frontend/src/SignupPage.jsx"
    click FP "https://github.com/yatharth-2906/linknest/blob/main/frontend/src/Profile.jsx"
    click FUP "https://github.com/yatharth-2906/linknest/blob/main/frontend/src/CONTEXT_PROVIDERS/UserProvider.jsx"
    click FVite "https://github.com/yatharth-2906/linknest/blob/main/frontend/vite.config.js"
    click FVer "https://github.com/yatharth-2906/linknest/blob/main/frontend/vercel.json"

    %% Click Events for Backend Components
    click BS "https://github.com/yatharth-2906/linknest/blob/main/backend/index.js"
    click BDC "https://github.com/yatharth-2906/linknest/blob/main/backend/connect.js"
    click BR_STATIC "https://github.com/yatharth-2906/linknest/blob/main/backend/routes/static.js"
    click BR_USER "https://github.com/yatharth-2906/linknest/blob/main/backend/routes/user.js"
    click BC_STATIC "https://github.com/yatharth-2906/linknest/blob/main/backend/controllers/static.js"
    click BC_USER "https://github.com/yatharth-2906/linknest/blob/main/backend/controllers/user.js"
    click BAUTH "https://github.com/yatharth-2906/linknest/blob/main/backend/service/auth.js"
    click BM_Trees "https://github.com/yatharth-2906/linknest/blob/main/backend/models/trees.js"
    click BM_URLs "https://github.com/yatharth-2906/linknest/blob/main/backend/models/urls.js"
    click BM_User "https://github.com/yatharth-2906/linknest/blob/main/backend/models/user.js"
    click BVer "https://github.com/yatharth-2906/linknest/blob/main/backend/vercel.json"
```
