Route structure
The application is organized into four main route groups:Nested layouts
The dashboard uses nested layouts to provide consistent navigation and sidebar across all dashboard pages.Layout hierarchy
Dashboard layout implementation
The employee dashboard layout (app/dashboard/employee/layout.tsx) wraps all child pages with:
Sidebar navigation
Sidebar navigation
Shared header
Shared header
Content area
Content area
- Renders child pages via
{children} - Consistent padding and responsive layout
app/dashboard/employee/layout.tsx
Route patterns
Public routes
Public routes are accessible without authentication:LandingLayout component from components/layouts/ for consistent header and footer.
Authentication routes
Auth routes handle sign in and registration:type field.
Protected routes (employee)
Employee dashboard routes require authentication and havetype: 'employee':
Protected routes (admin)
Admin routes require authentication and havetype: 'organization':
API routes
Better Auth endpoint
The authentication API is handled by a catch-all route:app/api/auth/[...all]/route.ts
POST /api/auth/sign-in- Email/password loginPOST /api/auth/sign-up- User registrationPOST /api/auth/sign-out- LogoutGET /api/auth/session- Get current session
Route protection
Routes are protected using middleware and server-side session checks.Middleware protection
Middleware protection
Middleware checks for valid sessions on protected routes and redirects unauthenticated users to
/login.Role-based access
Role-based access
Dashboard layouts check the user’s
type field:type: 'employee'→/dashboard/employee/*type: 'organization'→/dashboard/admin/*
Server component checks
Server component checks
Page components use
auth.api.getSession() to verify authentication server-side before rendering.Navigation patterns
Tab-based navigation
The employee dashboard uses tab-based navigation with separate content components:Sidebar state persistence
The sidebar’s collapsed/expanded state is persisted via cookies:Performance optimizations
Turbopack
Turbopack
Development server uses Turbopack for fast hot module replacement (HMR).
Server components by default
Server components by default
All pages are React Server Components unless marked with
'use client', reducing JavaScript bundle size.Nested layouts
Nested layouts
Only the child page re-renders on navigation; the dashboard layout stays mounted.
Route prefetching
Route prefetching
Next.js automatically prefetches linked routes on hover for instant navigation.
Best practices
- Use nested layouts for consistent UI across related routes
- Protect routes with middleware and server-side session checks
- Implement role-based routing with user
typefield - Persist UI state (like sidebar) via cookies for better UX
- Keep API routes minimal and delegate logic to
lib/modules