# duytoannn/admin-web-nextjs architecture

> Architecture diagram of the GitHub repository duytoannn/admin-web-nextjs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/duytoannn/admin-web-nextjs
- Repository: https://github.com/duytoannn/admin-web-nextjs

## Overview

##### Project type and purpose
- This is a full-stack video management system’s frontend, built with Next.js and TypeScript, which provides an admin section (to manage categories, products, users, videos, and integrate with Dropbox/Cloudinary) and a guest section (authentication, video playback).
- The frontend communicates with a NestJS/MongoDB backend (linked in the README) via RESTful APIs, handles authentication via NextAuth, and streams video content stored on Dropbox.

##### File structure
- Top-level config and tooling:
– .eslintrc.json, jest.config.js, next.config.mjs, tsconfig.json, GitHub Actions workflow in .github/workflows.
- Public assets: public/
- Core application: src/app/
– Two parallel route groups: (admin) and (guest) under src/app/**
– API routes for NextAuth: src/app/api/auth/[...nextauth]/route.ts
– Global layout and entry: src/app/layout.tsx, src/app/page.tsx, src/app/globals.css
- UI components: src/components/ (segmented by admin, auth, layout, videojs)
- Shared context/hooks: src/library/ (e.g., admin.context, next.auth.wrapper)
- Utilities: src/utils/ for API wrappers, custom hooks, error handlers
- Types: src/types/ for backend and NextAuth types
- Middleware: src/middleware.ts for route-level guards or rewrites

##### Key insights from README
- Frontend uses Next.js, Ant Design, NextAuth for authentication, and video playback via VideoJS.
- Integrates with Dropbox API for storage, Cloudinary API for media transforms, JWT for auth tokens.
- Backend (NestJS/MongoDB) is a separate service; frontend simply calls its public endpoints defined by NEXT_PUBLIC_BACKEND_URL.

##### Main components
a. Presentation Layer (Frontend)
– Next.js Server/SSR & Static pages
– Admin UI (dashboard, CRUD pages) and Guest UI (auth, video player)
– NextAuth middleware and session store
– VideoJS integration for playback
b. API Layer
– REST calls from frontend to NestJS backend (/auth, /categories, /videos, etc.)
– API wrapper utility in src/utils/api.ts
c. Backend Service (external)
– NestJS application exposing REST endpoints
– NextAuth callbacks (if any)
– JWT authentication
d. Data Layer
– MongoDB database for user, category, video metadata
e. External Services
– Dropbox API (storing/fetching raw video files)
– Cloudinary API (optional media transformations)
f. CI/CD
– GitHub Actions (node.js.yml) for linting, testing, and deployments
– Docker (as noted in README) for containerizing frontend

##### Relationships and interactions
- User → Frontend UI (SSR or CSR in Next.js)
- Frontend → NextAuth (to authenticate and maintain session)
- Authenticated Frontend → NestJS Backend (REST)
- Backend → MongoDB (read/write metadata)
- Frontend → Cloudinary API for on-the-fly transforms (thumbnails or adaptive streaming)
- CI/CD pipeline triggered on push → runs tests, builds Docker image, deploys to hosting

##### Architectural patterns and design principles
- Separation of concerns: UI components vs. data-fetching hooks vs. API wrapper vs. context providers
- “App Router” structure in Next.js 13+ with nested layouts for admin and guest
- Modular components (Ant Design) organized by feature
- Context-based state management for admin – user sessions, roles
- Utility-first approach for API calls and custom hooks
- Middleware for route guarding (e.g., admin routes vs. guest routes)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "CI/CD Pipeline"
        GH["GitHub Actions (node.js.yml)"]:::cicd
        Docker["Docker"]:::cicd
        Deploy["Deploy"]:::cicd
        GH -->|"build & test"| Docker
        Docker -->|"push image"| Deploy
    end

    subgraph "Presentation Layer"
        NextApp["Next.js App (TS, AntD, NextAuth)"]:::frontend
        subgraph "Admin UI"
            AdminPagesCat["Categories Page"]:::frontend
            AdminPagesProd["Products Page"]:::frontend
            AdminPagesUser["Users Page"]:::frontend
            AdminPagesVideos["Videos List"]:::frontend
            AdminPagesAddVideo["Add Video Page"]:::frontend
            AdminPagesDropbox["Dropbox Page"]:::frontend
        end
        subgraph "Guest UI"
            Login["Login Page"]:::frontend
            Register["Register Page"]:::frontend
            Verify["Email Verify Page"]:::frontend
            Watch["Video Watch Page"]:::frontend
        end
        NextAuthMid["NextAuth Middleware & API"]:::frontend
        VideoJSComp["VideoJS Component"]:::frontend

        NextApp --> AdminPagesCat
        NextApp --> AdminPagesProd
        NextApp --> AdminPagesUser
        NextApp --> AdminPagesVideos
        NextApp --> AdminPagesAddVideo
        NextApp --> AdminPagesDropbox
        NextApp --> Login
        NextApp --> Register
        NextApp --> Verify
        NextApp --> Watch
        NextApp --> NextAuthMid
        NextApp --> VideoJSComp
    end

    subgraph "API/Business Layer"
        APIWrapper["REST API Wrapper"]:::frontend
        BackendService["NestJS Backend"]:::backend
        NextAuthMid --> BackendService
        APIWrapper --> BackendService
        NextApp --> APIWrapper
    end

    subgraph "Data & External Services"
        DB["MongoDB"]:::backend
        DropBox["Dropbox API"]:::external
        Cloudinary["Cloudinary API"]:::external
        BackendService --> DB
        BackendService --> DropBox
        NextApp --> Cloudinary
    end

    User["User"]:::external
    User -->|"HTTP/HTTPS"| NextApp

    click NextApp "https://github.com/duytoannn/admin-web-nextjs/tree/master/src/app/"
    click AdminPagesCat "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(admin)/dashboard/categories/page.tsx"
    click AdminPagesProd "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(admin)/dashboard/product/page.tsx"
    click AdminPagesUser "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(admin)/dashboard/user/page.tsx"
    click AdminPagesVideos "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(admin)/dashboard/videos/page.tsx"
    click AdminPagesAddVideo "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(admin)/dashboard/videos/add/page.tsx"
    click AdminPagesDropbox "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(admin)/dashboard/dropbox/page.tsx"
    click Login "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(guest)/auth/login/page.tsx"
    click Register "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(guest)/auth/register/page.tsx"
    click Verify "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(guest)/verify/[id]/page.tsx"
    click Watch "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/(guest)/watch/[uuid]/page.tsx"
    click NextAuthMid "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/app/api/auth/[...nextauth]/route.ts"
    click VideoJSComp "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/components/videojs/VideoJS.tsx"
    click APIWrapper "https://github.com/duytoannn/admin-web-nextjs/blob/master/src/utils/api.ts"

    classDef frontend fill:#D0E8FF,stroke:#0366d6,stroke-width:1px
    classDef backend fill:#D0FFD6,stroke:#188038,stroke-width:1px
    classDef external fill:#FFE2B3,stroke:#d15704,stroke-width:1px
    classDef cicd fill:#E0D1FF,stroke:#6f42c1,stroke-width:1px
```
