# samseralikhan/linkhive architecture

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

- Interactive diagram: https://gitdiagram.com/samseralikhan/linkhive
- Repository: https://github.com/samseralikhan/linkhive

## Overview

##### Project type and purpose
- Link Hive is a full-stack web application whose primary function is to let users sign up/log in via OTP, then create and manage shortened links.
- The frontend is a React single-page app; the backend is an Express.js API connecting to a MongoDB database and using Firebase for OTP services.

##### File structure
- Top-level folders:
- `.github/workflows/CICD.yml` → CI/CD pipeline configuration.
- `backend/` → Node.js/Express API (routes, controllers, models, middleware, config).
- `frontend/` → React app (pages, components, styles, Tailwind config).
- Backend:
- `config/` holds database connection (`db.js`) and Firebase OTP credentials.
- `controllers/` split by domain (auth, OTP, link).
- `routes/` map HTTP endpoints to controllers.
- `models/` define MongoDB schemas for users, OTPs, and links.
- Frontend:
- `public/` with `index.html`.
- `src/` contains `pages/` (Login, OTP, Signup, Dashboard, etc.), `components/`, and a `Config/Firebase.js` for initializing Firebase.

##### README
- Confirms separate run steps for frontend (`npm start`) and backend (`nodemon server.js`).
- No explicit hosting details or external integrations beyond Firebase.

##### Diagramming conventions
- Browser → React app (internal event flow)
- React app → Express API (HTTP requests/responses)
- Express → MongoDB (read/write)
- Express → Firebase (OTP send/verify)
- GitHub → Build/Deploy → Hosting (if applicable)
- Green rectangles for frontend components
- Blue rectangles for backend components
- Purple cloud for external service (Firebase)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% CI/CD Pipeline
    subgraph "CI/CD Pipeline"
        CI["GitHub Actions CI/CD"]:::ci
    end

    %% Frontend Layer
    subgraph "Frontend"
        Browser["User’s Browser"]:::browser
        ReactApp["React SPA"]:::frontend
        subgraph "Pages"
            LandingPage["LandingPage"]:::frontend
            LoginPage["LoginPage"]:::frontend
            OTPPage["OTPPage"]:::frontend
            SignupPage["SignupPage"]:::frontend
            Dashboard["Dashboard"]:::frontend
            AddLink["AddLink"]:::frontend
        end
        subgraph "Components"
            ReusableComponents["Navbar, Sidebar, LinkShortener, etc."]:::frontend
        end
        FirebaseClient["Firebase OTP (Client)"]:::externalService
    end

    %% Backend Layer
    subgraph "Backend"
        ExpressAPI["Express.js API"]:::backend
        subgraph "Config"
            DBConfig["db.js"]:::backend
            FirebaseConfig["firebase-config.js"]:::backend
        end
        subgraph "Middleware"
            AuthMiddleware["authMiddleware.js"]:::backend
        end
        subgraph "Routes"
            AuthRoutes["authRoutes.js"]:::backend
            OtpRoutes["otpRoutes.js"]:::backend
            LinkRoutes["linkRoutes.js"]:::backend
        end
        subgraph "Controllers"
            LoginController["loginController.js"]:::backend
            SignupController["signupController.js"]:::backend
            AuthOtpController["otpController.js"]:::backend
            SendOtp["send.js"]:::backend
            VerifyOtp["verify.js"]:::backend
            AddLinkController["addLinkController.js"]:::backend
        end
        subgraph "Models"
            UserModel["userModel.js"]:::backend
            OtpModel["otp.js"]:::backend
            LinkModel["linkModel.js"]:::backend
        end
        Utils["otpServices.js"]:::backend
        MongoDB["MongoDB"]:::database
        FirebaseServer["Firebase OTP Service"]:::externalService
    end

    %% CI/CD Relationships
    CI -->|"build & deploy"| ReactApp
    CI -->|"build & deploy"| ExpressAPI

    %% Frontend Flow
    Browser -->|"loads"| ReactApp
    ReactApp -->|"renders"| LandingPage
    ReactApp -->|"renders"| LoginPage
    ReactApp -->|"renders"| OTPPage
    ReactApp -->|"renders"| SignupPage
    ReactApp -->|"renders"| Dashboard
    ReactApp -->|"renders"| AddLink
    ReactApp -->|"uses"| ReusableComponents
    ReactApp -->|"calls"| AuthRoutes
    ReactApp -->|"calls"| OtpRoutes
    ReactApp -->|"calls"| LinkRoutes
    ReactApp -->|"uses"| FirebaseClient

    %% Backend Flow
    AuthRoutes -->|"handles"| LoginController
    AuthRoutes -->|"handles"| SignupController
    AuthRoutes -->|"handles"| AuthOtpController
    OtpRoutes -->|"handles"| SendOtp
    OtpRoutes -->|"handles"| VerifyOtp
    LinkRoutes -->|"handles"| AddLinkController
    ExpressAPI -->|"uses"| AuthMiddleware
    ExpressAPI -->|"includes"| AuthRoutes
    ExpressAPI -->|"includes"| OtpRoutes
    ExpressAPI -->|"includes"| LinkRoutes
    Controllers -->|"query/write"| MongoDB
    SendOtp -->|"calls"| FirebaseServer
    VerifyOtp -->|"calls"| FirebaseServer
    LoginController -->|"uses"| UserModel
    SignupController -->|"uses"| UserModel
    AuthOtpController -->|"uses"| OtpModel
    AddLinkController -->|"uses"| LinkModel
    SendOtp -->|"uses"| Utils
    VerifyOtp -->|"uses"| Utils
    DBConfig -->|"connects"| MongoDB
    FirebaseConfig -->|"configures"| FirebaseServer

    %% Click Events
    click CI "https://github.com/samseralikhan/linkhive/blob/main/.github/workflows/CICD.yml"
    click ReactApp "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/App.js"
    click Browser "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/index.js"
    click LandingPage "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/pages/LandingPage.js"
    click LoginPage "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/pages/LoginPage.js"
    click OTPPage "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/pages/OTPPage.js"
    click SignupPage "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/pages/SignupPage.js"
    click Dashboard "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/pages/Dashboard.js"
    click AddLink "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/pages/AddLink.js"
    click ReusableComponents "https://github.com/samseralikhan/linkhive/tree/main/frontend/src/components"
    click FirebaseClient "https://github.com/samseralikhan/linkhive/blob/main/frontend/src/Config/Firebase.js"
    click DBConfig "https://github.com/samseralikhan/linkhive/blob/main/backend/config/db.js"
    click FirebaseConfig "https://github.com/samseralikhan/linkhive/blob/main/backend/config/firebase-config.js"
    click AuthMiddleware "https://github.com/samseralikhan/linkhive/blob/main/backend/middleware/authMiddleware.js"
    click UserModel "https://github.com/samseralikhan/linkhive/blob/main/backend/models/userModel.js"
    click OtpModel "https://github.com/samseralikhan/linkhive/blob/main/backend/models/otp.js"
    click LinkModel "https://github.com/samseralikhan/linkhive/blob/main/backend/models/linkModel.js"
    click LoginController "https://github.com/samseralikhan/linkhive/blob/main/backend/controllers/auth/loginController.js"
    click SignupController "https://github.com/samseralikhan/linkhive/blob/main/backend/controllers/auth/signupController.js"
    click AuthOtpController "https://github.com/samseralikhan/linkhive/blob/main/backend/controllers/auth/otpController.js"
    click SendOtp "https://github.com/samseralikhan/linkhive/blob/main/backend/controllers/OTP/send.js"
    click VerifyOtp "https://github.com/samseralikhan/linkhive/blob/main/backend/controllers/OTP/verify.js"
    click AddLinkController "https://github.com/samseralikhan/linkhive/blob/main/backend/controllers/link/addLinkController.js"
    click AuthRoutes "https://github.com/samseralikhan/linkhive/blob/main/backend/routes/authRoutes.js"
    click OtpRoutes "https://github.com/samseralikhan/linkhive/blob/main/backend/routes/otpRoutes.js"
    click LinkRoutes "https://github.com/samseralikhan/linkhive/blob/main/backend/routes/linkRoutes.js"
    click Utils "https://github.com/samseralikhan/linkhive/blob/main/backend/utils/otpServices.js"

    %% Styles
    classDef frontend fill:#d4f1be,stroke:#2d7a2d,stroke-width:1px
    classDef backend fill:#bee3f8,stroke:#2b5797,stroke-width:1px
    classDef database fill:#fddb93,stroke:#c26e00,stroke-width:1px
    classDef externalService fill:#e2b8f4,stroke:#7d1e7a,stroke-width:1px
    classDef ci fill:#e0e0e0,stroke:#8a8a8a,stroke-width:1px
    classDef browser fill:#cfd8dc,stroke:#455a64,stroke-width:1px
```
