Next.js 16 with App Router (Web)
Overviewβ
The QMS frontend uses Next.js 16 with the App Router, built on React 19. The App Router provides file-system routing, layouts, server components, and improved data fetching patterns.
Project layout (apps/web/src/app)β
src/app/
βββ layout.tsx # Root layout
βββ page.tsx # Root page
βββ (auth)/ # Grouped routes
β βββ login/page.tsx
βββ employees/
β βββ layout.tsx
β βββ page.tsx
βββ components/ # Shared UI components
Key App Router conceptsβ
app/layout.tsxprovides persistent UI and common providersapp/page.tsxis the route entry pointapp/route.tssupports server-only request handlers (for edge/server actions)loading.tsxanderror.tsxsupport per-route UX- Server Components by default; use
'use client'for client components
Data fetching patternsβ
- Use server components to fetch data on the server when possible (fast TTFB and SEO)
- Use TanStack Query (see State & Data doc) for client caching and background revalidation
- Prefer route-level loading with Suspense and streaming for large pages
Routing and nested layoutsβ
- Use nested
layout.tsxfiles for subtrees (e.g., employees) to share UI and data - Use
useRouter()in client components for navigation
API integrationβ
- QMS exposes API under
/api/v1via the backend - Use environment variable
NEXT_PUBLIC_API_BASE_URLto point to API
Environment variablesβ
NEXT_PUBLIC_API_BASE_URLβ API base URL available in browserNEXT_PUBLIC_API_VERSIONβ API version path
Rendering strategyβ
- Prefer server rendering for initial load and SEO
- Use client components for interactive widgets (tables, modals)
- Use edge/server functions for lightweight server handlers when needed
Testingβ
- Unit test components with React Testing Library and Jest
- Integration/e2e tests via Playwright/Selenium Grid (see testing docs)
Best Practicesβ
- Keep components small and focused
- Move data fetching to higher-level components when possible
- Use shared UI primitives in
src/componentsandpackages/schemasfor types - Keep accessibility (a11y) in mind β keyboard navigation, labels, and ARIA
Related docsβ
Resourcesβ
- Next.js App Router docs: https://nextjs.org/docs/app
- React 19 release notes: https://reactjs.org