# tanishqbhatia474/devlinks architecture

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

- Interactive diagram: https://gitdiagram.com/tanishqbhatia474/devlinks
- Repository: https://github.com/tanishqbhatia474/devlinks

## Overview

##### Project Type and Purpose
- From the README and file structure, this is a full-stack web application (“DevLinks”) built on Next.js.
- Purpose: allow users to authenticate via Google, then create and manage a personalized “link tree” (drag-and-drop, add/edit links), with server-side rendering, responsive design, and a preview mode.

##### File Structure
- Top-level files: next.config.mjs, package.json, tailwind.config.js, README.md, .eslintrc.json
- /models: Mongoose model(s) (user.js)
- /utils & /src/app/lib: database connection helpers (mongodb.js, database.js)
- src/app: Next.js App Router
- src/app/page.jsx: main landing page
- src/app/login/page.jsx: login UI
- src/app/preview/[userId]/page.jsx: public preview
- src/app/api: API routes under auth, user, getlinks—each exposing route.js handlers
- src/app/components: React components (Header, Linktree, Newlink)
- src/app/globals.css: global Tailwind styles
- NextAuth routes in src/app/api/auth/[...nextauth]/route.js

##### README Insights
- Tech stack: Next.js, Tailwind CSS, NextAuth.js, HTML5 drag-and-drop
- Features: Google Authentication, user profile, link management, responsive design

##### Main Components and Relationships
a. Frontend (Browser & Next.js Server Components)
- Browser: renders pages, executes client-side JS for drag-and-drop
- Next.js App Server: renders React components on server, handles data fetching in server components
- React Components: Header (displays profile, login/logout), Linktree (renders list), Newlink (UI for adding links)
b. API Layer
- Next.js API Routes:
- /api/auth → NextAuth.js (Google OAuth flow + session management)
- /api/user/[userId] → CRUD operations on user metadata
- /api/user/getlinks/[userId] → retrieve/save link ordering
c. Data Layer
- MongoDB Atlas (or on-prem)
- Mongoose models (models/user.js)
- Connection utilities (src/app/lib/mongodb.js, utils/database.js)
d. External Services
- Google OAuth (via NextAuth.js)
- Static assets served from /public

##### Important Patterns and Principles
- Separation of Concerns:
- Presentation Layer (React components, CSS)
- API Layer (Next.js route handlers)
- Data Layer (MongoDB + Mongoose)
- Server-Side Rendering (SSR) via Next.js App Router
- Authentication as a distinct module (NextAuth.js)
- Component Reusability (Header, Linktree, Newlink)
- Drag-and-drop uses browser APIs for UX

## Diagram (Mermaid)

```mermaid
graph TB
  %% Client Tier
  subgraph "Client Tier (Browser)"
    direction TB
    Landing["Landing Page"]:::frontend
    Login["Login Page"]:::frontend
    Preview["Public Preview Page"]:::frontend
    Header["Header Component"]:::frontend
    Linktree["Linktree Component"]:::frontend
    Newlink["Newlink Component"]:::frontend
    CSS["Global Stylesheet"]:::frontend
    Tailwind["Tailwind Config"]:::frontend
    PublicAssets["Public Images & Icons"]:::external
  end

  %% Server Tier
  subgraph "Server Tier (Next.js)"
    direction TB
    SSR["SSR & Static Rendering"]:::backend
    subgraph "API Layer"
      direction TB
      AuthAPI["Auth API Route"]:::backend
      UserAPI["User Metadata API"]:::backend
      LinksAPI["Link Management API"]:::backend
    end
  end

  %% Data & External Tier
  subgraph "Data & External Tier"
    direction TB
    MongoDB["MongoDB"]:::database
    UserModel["User Model (Mongoose)"]:::database
    ConnLib["MongoDB Connection Helper"]:::database
    DBUtil["Database Utility"]:::database
    OAuth["Google OAuth"]:::external
  end

  %% Connections: Page Requests
  Landing -->|"HTTPS GET"| SSR
  Login -->|"HTTPS GET"| SSR
  Preview -->|"HTTPS GET"| SSR

  %% SSR delivers components and styles
  SSR --> Header
  SSR --> Linktree
  SSR --> Newlink
  SSR --> CSS
  SSR --> Tailwind
  SSR --> PublicAssets

  %% Component ↔ API calls
  Header -->|"GET /api/user/:userId"| UserAPI
  Linktree -->|"GET /api/user/getlinks/:userId"| LinksAPI
  Newlink -->|"POST /api/user/getlinks/:userId"| LinksAPI
  Login -->|"POST /api/auth"| AuthAPI

  %% Auth flow to external OAuth
  AuthAPI -->|"OAuth tokens"| OAuth
  AuthAPI -->|"session data"| SSR

  %% API ↔ Data Layer
  AuthAPI --> UserModel
  UserAPI --> UserModel
  LinksAPI --> UserModel
  UserModel --> MongoDB
  ConnLib --> UserModel
  DBUtil --> UserModel

  %% Styling and static assets usage
  CSS --> PublicAssets

  %% Click Events
  click Landing "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/page.jsx"
  click Login "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/login/page.jsx"
  click Preview "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/preview/[userId]/page.jsx"
  click Header "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/components/Header.js"
  click Linktree "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/components/Linktree.js"
  click Newlink "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/components/Newlink.js"
  click CSS "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/globals.css"
  click Tailwind "https://github.com/tanishqbhatia474/devlinks/blob/main/tailwind.config.js"
  click AuthAPI "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/api/auth/[...nextauth]/route.js"
  click UserAPI "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/api/user/[userId]/route.js"
  click LinksAPI "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/api/user/getlinks/[userId]/route.js"
  click UserModel "https://github.com/tanishqbhatia474/devlinks/blob/main/models/user.js"
  click ConnLib "https://github.com/tanishqbhatia474/devlinks/blob/main/src/app/lib/mongodb.js"
  click DBUtil "https://github.com/tanishqbhatia474/devlinks/blob/main/utils/database.js"
  click PublicAssets "https://github.com/tanishqbhatia474/devlinks/tree/main/public/images"

  %% Styles
  classDef frontend fill:#cfe2f3,stroke:#333,stroke-width:1px
  classDef backend fill:#d9ead3,stroke:#333,stroke-width:1px
  classDef database fill:#e6e0ec,stroke:#333,stroke-width:1px
  classDef external fill:#fce5cd,stroke:#333,stroke-width:1px
```
