How duytoannn/admin-web-nextjs works
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)