TalentSync

AI resume builder and ATS optimizer for job seekers. Tailored resumes, outreach, and interview prep from one profile.

Next.js application architecture

The Next.js application architecture.

Repository layout#

The frontend application follows Next.js App Router conventions with a strict file-system-based routing structure under the app directory. Pages are organized by feature and route segments, with nested layouts and providers at the root level. Utility libraries and services are modularized under dedicated folders, while UI components are structured by feature and shared patterns.

Key structural highlights:

  • App Router pages under app with nested layouts and providers
  • Feature-specific pages grouped under functional namespaces (e.g., dashboard, auth, api)
  • Shared UI components under components with feature-specific subfolders
  • Services and hooks under services and hooks
  • Utilities and types under lib and types
  • Global styles and fonts configured at the root layout
  • Build-time configuration under next.config.js, tsconfig.json, and related tooling files

Building blocks#

This section outlines the foundational components that define the application’s layout, providers, and global configuration.

  • Root layout and metadata: Defines application metadata, fonts, and the root HTML wrapper with theme and manifest integration.
  • Layout content: Provides the main content area with navigation, sidebar provider, and toast notifications.
  • Providers: Wraps the application with session and query providers, configuring caching and retries for data fetching.
  • Global error boundaries: Implements error and not-found handlers for graceful degradation and user feedback.
  • Tooling configuration: Next.js configuration for PWA, images, webpack, and PostHog proxying; TypeScript strictness and module resolution; Tailwind and PostCSS setup.

Code to read:

  • Root layout and metadata: app/layout.tsx
  • Layout content and sidebar provider: app/layout-content.tsx
  • Providers and React Query configuration: app/providers.tsx
  • Global error and not-found handlers: app/error.tsx, app/not-found.tsx, app/global-error.tsx
  • Next.js configuration: next.config.js
  • TypeScript configuration: tsconfig.json
  • Tailwind and PostCSS: tailwind.config.ts, postcss.config.js
  • PWA manifest: public/manifest.json

How it fits together#

The application architecture centers around the Next.js App Router with a layered approach:

  • Presentation layer: Root layout, layout content, and feature pages
  • State management: Session and query providers for authentication and data fetching
  • Routing and middleware: proxy.ts cookie presence check, then getSession() on server routes
  • Analytics and observability: PostHog client-side initialization
  • Build and deployment: PWA, image optimization, webpack customization, and external packages

Layout system and providers#

The layout system establishes a consistent shell across pages:

  • Root layout sets metadata, fonts, theme variables, and mounts the Providers and LayoutContent wrappers.
  • LayoutContent manages the main content area, navigation bar, sidebar provider, and toast notifications.
  • Providers configure session management and React Query with caching and retry policies.

Routing patterns and middleware integration#

Routing uses Next.js App Router conventions with dynamic routes and catch-all patterns. proxy.ts redirects unsigned-in users to /auth. It does not verify the JWT.

  • Dynamic routes: e.g., dashboard pages with slug-based routing
  • Catch-all routes: e.g., API namespaces with dynamic segments
  • Middleware enforces role selection for authenticated users without roles and redirects accordingly

Build configuration and PWA setup#

The build configuration integrates PWA capabilities, image optimization, and webpack customization:

  • PWA: Enabled via next-pwa with service worker registration and skipWaiting
  • Images: Unoptimized mode with remote patterns for avatar providers
  • Webpack: Browser-side fixes for Node.js modules and PostHog instrumentation compatibility
  • Rewrites: Proxy for PostHog static assets and API requests
  • External packages: serverExternalPackages includes @prisma/client and bcrypt

TypeScript configuration and type safety#

TypeScript is configured for strict type checking and modern module resolution:

  • Strict mode enabled with noEmit
  • Bundler module resolution and isolated modules
  • JSX runtime set to react-jsx
  • Path aliases (@/*) mapped to root
  • Included types for Next.js and generated types

UI theme and styling#

Tailwind CSS and PostCSS provide a consistent design system:

  • Dark mode support with class strategy
  • Extended color palette and typography tokens
  • Animations and responsive utilities
  • Auto-prefixing and Tailwind integration

Navigation items and action cards guide users through features:

  • Navigation items for desktop and mobile
  • Action items for quick feature access
  • Shared UI components for forms, dialogs, and interactive elements

Error boundaries and user feedback#

Error boundaries provide graceful handling of errors and not-found scenarios:

  • Page-level error boundary with reset functionality
  • Global error boundary for top-level failures
  • Not-found page with themed visuals and navigation

Analytics integration#

PostHog client-side initialization supports analytics and event tracking:

  • Client-side initialization with environment keys
  • Proxy configuration for API and static assets
  • Trailing slash handling for API compatibility

Dependencies#

The application’s dependencies span UI libraries, state management, authentication, analytics, and build tools. The dependency graph highlights core integrations and potential coupling points.

Performance#

Performance is addressed through several mechanisms:

  • Image optimization: Unoptimized images with controlled remote patterns to reduce unnecessary processing
  • PWA: Service worker registration and skipWaiting improve offline readiness and load performance
  • Webpack customization: Node.js module fallbacks prevent runtime errors and reduce bundle bloat
  • React Query caching: Stale-time and retry configurations minimize redundant network requests
  • Tailwind purging: Content paths ensure unused styles are removed during build

Recommendations:

  • Enable image optimization selectively for performance-sensitive assets
  • Monitor bundle sizes and split large components
  • Use React Suspense boundaries for data-intensive pages
  • Use Next.js static generation where feasible

Troubleshooting#

Common issues:

  • Authentication loops: Verify middleware redirection logic and token presence
  • Role selection redirects: Ensure proper handling of authenticated users without roles
  • PostHog proxy errors: Confirm rewrite rules and trailing slash configuration
  • Image loading issues: Validate remote patterns and asset URLs
  • Build errors for Node.js modules: Confirm webpack fallbacks and replacements

Diagnostics:

  • Review getSession() and /api/v1/auth/me if the navbar role is stale
  • Inspect React Query cache behavior and stale times
  • Check PWA registration and service worker lifecycle
  • Validate Tailwind content paths and purge behavior

Appendix#

Deployment considerations#

  • Environment variables for authentication and analytics
  • PWA manifest and service worker registration
  • Build scripts invoking Prisma generation and migrations
  • Docker and compose configurations for containerized deployment