How hung123-alt/ktpm_4_2026 works
1. Repository shape
- This is a two-tier monorepo: a React/Vite client in client/ and a NestJS API server in server/.
- The architecture is centered on a REST API consumed by the frontend; there is no separate backend-for-frontend layer.
2. Frontend shell and app composition
- The client bootstraps through main.jsx and App.jsx, with global wiring in AppProviders.jsx.
- Core cross-cutting providers include auth state, theme state, and a query client for server state management.
- Routing is split into public, protected, and admin routes, with dedicated route guards.
3. Frontend feature organization
- The client is organized by domain feature: auth, movies, comments, interactions, notifications, reports, and admin.
- Each feature typically has:
- api/ for HTTP calls,
- hooks/ for reusable data/mutation logic,
- pages/ for route-level screens,
- queries.js or index.js for feature exports.
- This indicates a feature-first frontend architecture with React Query-style server-state boundaries.
4. Frontend presentation boundaries
- Shared UI is separated from feature UI:
- shared/layout/ for Header, Footer, MainLayout, AdminLayout,
- shared/components/ for cross-app controls like ThemeToggle.
- ProtectedRoute and AdminRoute enforce access boundaries in the UI, but they complement server-side authorization rather than replace it.
5. Frontend data flow
- UI components call feature hooks, hooks call feature APIs, and APIs use a shared Axios client in lib/axiosClient.js.
- Central query-client setup suggests cache/invalidation-driven flows for list/detail screens, mutations, and refreshable user state.
- The main user journeys reflected in pages are:
- browsing/searching/filtering movies,
- viewing details and watching,
- commenting, rating, favoriting, watchlisting, and tracking history,
- authentication and profile management,
- admin moderation and catalog management.
6. Backend core structure
- The server is a NestJS modular monolith: each business area lives in its own module with controller/service/entity separation.
- app.module.ts composes modules, while main.ts is the Nest bootstrap entrypoint.
- The backend is strongly domain-driven at the module level rather than layered by technical concern.
7. Backend domain modules
- Major server modules include:
- auth for login/register/password reset/refresh token handling,
- users for profile and account management,
- movies and episodes for catalog and playback metadata,
- genres and countries for catalog taxonomy,
- comments, ratings, favorites, watchlist, and watch-history for user interactions,
- notifications for user-facing alerts,
- error-reports for issue reporting,
- admin for privileged operations.
- This mirrors the frontend feature map, which keeps the client/server contract easy to reason about.
8. Backend security model
- Authentication is JWT-based, with auth.strategy.ts, jwt-auth.guard.ts, and roles.guard.ts enforcing access.
- Authorization is role-aware through roles.decorator.ts and user-role.enum.ts; there is a clear boundary between normal users and admins.
- current-user.decorator.ts indicates controllers can directly access the authenticated principal.
- The presence of refresh-token.entity.ts suggests token lifecycle management beyond simple stateless JWTs.
9. Backend persistence and schema
- server/src/database/ contains the relational schema and seed data, which points to a SQL database-backed architecture.
- The devcontainer includes MSSQL tooling and setup scripts, so local development is designed around Microsoft SQL Server.
- Entities under each module imply the API maps closely to relational tables and joins rather than a document model.
10. Backend cross-cutting services
- mail/ is a separate infrastructure module, likely used for password recovery and notification delivery.
- Shared enums, DTOs, and utilities in common/ keep validation, error typing, role checks, and slug generation consistent across modules.
- This shows a small set of shared primitives supporting otherwise isolated feature modules.
11. Interaction and moderation workflows
- User-generated and user-specific data is split into distinct modules:
- comments, ratings, favorites, watchlist, watch-history, and notifications.
- error-reports and the admin module support moderation/operations workflows, while frontend admin pages expose management screens for users, comments, movies, genres, countries, and reports.
- This is a good example of a user-content + moderation subsystem boundary.
12. Operational and developer tooling
- The repo includes a .devcontainer/ setup with Docker Compose and SQL Server initialization scripts, indicating the project is intended to run consistently in containerized dev environments.
- The client also has a vercel.json, suggesting the frontend is deployable as a static SPA on Vercel.
- End-to-end test scaffolding exists on the server (test/app.e2e-spec.ts), showing the API has integration-test coverage.
13. How to draw the architecture
- The simplest diagram is:
- Browser / React client
→ NestJS REST API
→ SQL Server database
plus a side path from the API to mail delivery.
- Add role-based gates on both sides: UI route guards on the client and JWT/role guards on the server.
- Around the API, show domain modules as separate internal subsystems rather than a single generic backend.
Main entry points: main.ts Nest app · AppRoutes.jsx Routes · schema.sql SQL schema · common Shared core
Components 21
Client
React/Vite frontend
- App shell · Bootstraps the SPA and composes global providers and routes.
client/src/main.jsx - Providers · Auth, theme, and query-client context used across the app.
client/src/providers/AppProviders.jsx - Routes · Public, protected, and admin routing with access checks.
client/src/routes/AppRoutes.jsx - Shared UI · Reusable layouts and controls shared across features.
client/src/shared/layout/MainLayout.jsx - Auth feature · Login, registration, profile, and password recovery flows.
client/src/features/auth - Movies feature · Browse, search, filter, detail, watch, and random movie pages.
client/src/features/movies - Comments feature · Comment listing and mutation hooks around movie discussions.
client/src/features/comments - Interactions · Favorites, watchlist, ratings, comments, and watch history UI.
client/src/features/interactions - Notifications · User notification retrieval and display hooks.
client/src/features/notifications - Reports · Error/report submission and tracking flows.
client/src/features/reports - Admin feature · Management screens for users, movies, comments, genres, countries, and reports.
client/src/features/admin
Server
NestJS REST API
- Nest app · NestJS entrypoint and root module composition.
server/src/main.ts - Security · JWT auth strategy plus guards and role decorators for access control.
server/src/common/guards/jwt-auth.guard.ts - Auth module · Login, registration, password reset, refresh tokens, and JWT issuance.
server/src/modules/auth/auth.module.ts - Catalog modules · Movies, episodes, genres, and countries for catalog and playback metadata.
server/src/modules/movies/movies.module.ts - Interaction modules · Comments, ratings, favorites, watchlist, and watch-history subsystems.
server/src/modules/comments/comments.module.ts - Admin/ops · Admin actions, notifications, and user-facing error reports.
server/src/modules/admin/admin.module.ts - Shared core · DTOs, enums, interfaces, slug utility, and current-user/roles helpers.
server/src/common - SQL schema · Relational schema and seed data backing the API.
server/src/database/schema.sql - Mail service · Email delivery for password recovery and notifications.
server/src/mail/mail.service.ts
Infra
Local dev and deployment support
- Dev container · Containerized local environment with SQL Server setup.
.devcontainer/docker-compose.yml
Connections 33
- App shell → Providers: wraps · App shell installs global state providers.
- App shell → Routes: renders · Top-level routing is mounted from the app shell.
- Providers → Auth feature: auth state · Auth context is consumed by auth and protected flows.
- Providers → Routes: guards · Route decisions depend on provider state.
- Routes → Shared UI: layouts · Routes compose shared application layouts.
- Routes → Auth feature: public · Authentication screens are exposed through public routes.
- Routes → Movies feature: browse · Core content browsing and playback screens.
- Routes → Interactions: protected · User-specific lists and histories require login.
- Routes → Admin feature: admin · Privileged management screens are separately gated.
- Movies feature → Nest app: REST calls · Movie pages fetch data from the API.
- Auth feature → Nest app: REST calls · Authentication flows call backend endpoints.
- Comments feature → Nest app: REST calls · Comment hooks and pages talk to the API.
- Interactions → Nest app: REST calls · Favorites, ratings, watchlist, and history use API endpoints.
- Notifications → Nest app: REST calls · Notification data is loaded from the API.
- Reports → Nest app: REST calls · Report submission and status flows use the API.
- Admin feature → Nest app: REST calls · Management screens operate against admin endpoints.
- Nest app → Security: enforces · Controllers rely on JWT and role guards.
- Nest app → Auth module: composes · Root module wires authentication into the app.
- Nest app → Catalog modules: composes · Catalog-related modules are registered in the app.
- Nest app → Interaction modules: composes · User interaction modules are registered in the app.
- Nest app → Admin/ops: composes · Admin and operational modules are registered in the app.
- Auth module → SQL schema: persists · Users and refresh tokens are stored in the relational database.
- Catalog modules → SQL schema: reads/writes · Catalog data is backed by relational tables.
- Interaction modules → SQL schema: reads/writes · User interactions are persisted in SQL tables.
- Admin/ops → SQL schema: reads/writes · Admin operations and notifications persist to the database.
- Auth module → Mail service: sends mail · Password recovery and related flows trigger email delivery.
- Admin/ops → Mail service: sends mail · Operational notifications can use mail delivery.
- Shared core → Auth module: shared by · Common decorators and enums support auth.
- Shared core → Catalog modules: shared by · Common utilities and enums are reused across catalog modules.
- Shared core → Interaction modules: shared by · Common primitives support interaction modules.
- Shared core → Admin/ops: shared by · Shared helpers support admin and reporting flows.
- Dev container → SQL schema: provisions · Dev container brings up SQL Server and initialization scripts.
- Dev container → App shell: hosts · Containerized development supports the frontend build environment.