UI Console
Overview
The UI console is a Next.js 16 App Router application rooted under ui/app. The authenticated application lives in the (prowler) route group, with the global shell in ui/…/layout.tsx: it imports ui/…/globals.css, renders the runtime config JSON island in <head>, wraps the tree with SessionProvider and next-themes via ui/…/providers.tsx, seeds client UI state with StoreInitializer, and mounts the sidebar/main layout, global side panel, task polling watcher, survey, navigation progress, and toaster. Public auth pages live in ui/app/(auth), and ui/…/layout.tsx redirects already-authenticated users back to /.
Route protection is split between ui/proxy.ts and NextAuth callbacks in ui/auth.config.ts. The proxy excludes API/static assets, attaches CSP from ui/lib/csp, redirects unauthenticated users to /sign-in?callbackUrl=..., preserves UTM parameters for login redirects, and applies route gates for billing, Registry, and integrations. NextAuth uses JWT sessions in ui/auth.config.ts, supports credentials plus a social-oauth credentials provider, decodes tenant/user claims from API access tokens, refreshes expired access tokens through ${apiBaseUrl}/tokens/refresh, and refreshes the user/permission payload from /users/me?include=roles through ui/…/current-user.ts. The NextAuth route itself is ui/…/route.ts; Google, GitHub, and SAML callbacks under ui/…/route.ts exchange provider callback data with the backend token endpoints and then sign into the social-oauth provider.
Most page data is loaded in Server Components and server actions. Shared legacy actions live in ui/actions/** and newer feature-local actions live under route _actions folders such as ui/app/(prowler)/realtime/_actions. Actions call the backend API at apiBaseUrl from ui/…/helper.ts, using getAuthHeaders() to read the NextAuth session token server-side. ui/…/server-actions-helper.ts centralizes response parsing, path revalidation, sanitization of server errors, and Sentry capture for unexpected 4xx/5xx failures. Feature pages pass searchParams into actions and helper parsers so URL filters, pagination, tabs, and sort remain the source of truth.
Core authenticated pages are in ui/app/(prowler). ui/…/page.tsx is the overview dashboard: it loads providers, provider groups, sample-preview state, and Lighthouse banner state, then streams dashboard cards through Suspense. ui/…/page.tsx selects between sample preview, early/running scan findings, and latest/historical finding-group APIs, resolving scan-date filters before rendering filters and the findings table. ui/…/page.tsx combines scans, schedules, providers, provider groups, session permissions, report-download gates, active scan count, and synthetic pending-schedule rows. ui/…/page.tsx renders provider/provider-group tabs without re-suspending on tab-only changes. Other top-level domains include resources, services, compliance, attack paths, issues, mutelist, manage groups, users, roles, invitations, alerts, integrations, Lighthouse, Registry, and Realtime; nested routes include scan configuration, integration detail pages, Lighthouse settings/config, compliance detail pages, and Realtime configuration. Cloud-only behavior is normally gated through isCloud() from ui/…/env.ts; for example ui/…/page.tsx returns notFound() outside Cloud.
API routes under ui/app/api/** are same-origin adapters for browser-sensitive flows. ui/…/route.ts checks the report-download gate, forwards authenticated report requests, preflights report readiness, preserves upstream redirects to S3 presigned URLs, and streams direct API ZIP bytes for self-hosted deployments. ui/…/route.ts is a Cloud-only multipart proxy that preserves Content-Type and Content-Length while translating ingestion rejection statuses into user-facing messages. ui/…/route.ts proxies Lighthouse SSE streams with the session token server-side so the browser can use same-origin EventSource without exposing tokens. Health, service, ingestion detail, and Lighthouse analyst routes follow the same route-handler pattern.
The main client shell is in ui/…/main-layout.tsx and ui/components/layout/app-sidebar/*. The <main> element is the responsive container (data-responsive-container) and is pushed right by the persisted global side-panel width from ui/…/side-panel.ts; the side panel owns its open state, selected tab, context-tab registration, modal-host inert state, and resizable width. ui/…/store.ts persists sidebar open/provider state while keeping per-request server decisions such as Registry eligibility out of persistence; ui/…/store-initializer.tsx seeds those values from the server layout. Background task state is centralized in ui/…/store.ts, which persists non-sensitive task metadata, resumes polling after reload through TaskPollingWatcher, and lets feature-specific handlers react to ready/error states.
Runtime/build configuration is deliberately runtime-readable. ui/next.config.js loads ../.env, disables server-function argument logging, enables React Compiler, emits standalone output only for production non-CI builds, configures security headers, and wraps Sentry only when build upload credentials exist. Public runtime configuration is produced per request in ui/…/runtime-config.ts using connection(), serialized by ui/…/runtime-public-config.tsx into a safe JSON script tag, read in the browser by ui/…/get-runtime-config.client.ts, and exposed to React through ui/…/use-runtime-config.ts. ui/…/runtime-env.ts avoids literal process.env.NEXT_PUBLIC_* reads so legacy public names can remain runtime fallbacks instead of build-time snapshots. Sentry server/edge bootstrapping starts in ui/instrumentation.ts; client Sentry and navigation progress are initialized before hydration in ui/instrumentation-client.ts from the runtime config island.
Testing is organized inside the covered UI tree. ui/vitest.config.ts defines a jsdom unit project for *.test.ts(x) without React Compiler and a browser integration project for *.integration.test.tsx with React Compiler and Playwright/Chromium. Route, action, adapter, hook, store, and component tests sit beside their implementations across ui/app, ui/actions, ui/components, ui/lib, ui/hooks, and ui/store; Playwright E2E config files are at ui/playwright*.ts, and package scripts in ui/package.json expose healthcheck, unit, integration, coverage, and E2E commands.
Coupling
- If the session shape or permission keys change in ui/auth.config.ts, also update ui/nextauth.d.ts, ui/…/use-auth.ts, ui/…/current-user.ts, and ui/…/users.ts; route gates in ui/proxy.ts and server pages such as ui/…/page.tsx read
session.user.permissionsdirectly. - If backend JSON:API endpoints, filters, includes, or pagination fields change, update the corresponding server actions in
ui/actions/**and any page helpers that parse search params. For example, findings routes couple ui/…/page.tsx toui/actions/finding-groups,ui/actions/scans, and filter helpers inui/lib, while providers couple ui/…/providers.ts to provider filters and provider-table components. - If adding a browser-visible runtime flag, add it to ui/…/runtime-config.ts, ui/…/runtime-config.shared.ts, and any client reader/hook. Reading a new
NEXT_PUBLIC_*variable literally in client code bypasses the runtime-island design and can freeze deployment config at build time. - If changing Cloud, Registry, billing, or self-registration gates, verify both server and client paths: ui/proxy.ts handles request-time redirects, ui/…/env.ts handles shared runtime checks, and page components such as ui/…/page.tsx and ui/…/page.tsx make route-local decisions.
- If changing report downloads, keep ui/…/helper.ts client preflight/download behavior aligned with ui/…/route.ts; the client expects
202for reports still being generated, text errors for failed preflight, redirects for S3-backed reports, and streamed ZIP bytes for self-hosted reports. - If adding a same-origin API proxy for uploads or streams, follow the token-handling patterns in ui/…/route.ts and ui/…/route.ts: credentials stay server-side, cache is disabled, and browser-facing errors are sanitized.
- If adding global task-producing UI, register a task kind with ui/…/store.ts and mount/resume through the existing
TaskPollingWatcher; persistedmetamust stay serializable and non-sensitive because it is stored in localStorage. - If moving feature code between legacy shared folders and route-local
_actions/_components/_lib, update import paths and barrel exports together. Existing pages mix legacyui/actions/ui/componentswith route-local folders, so dead or duplicate exports can silently leave pages on the old implementation.
Risks
- ui/auth.config.ts, ui/proxy.ts, and ui/…/route.ts jointly control login, callback redirects, token refresh, and session invalidation. A mismatch in callback URL sanitization, token response parsing, or refresh-error handling can redirect users to the wrong page or clear otherwise valid sessions.
- ui/…/runtime-env.ts, ui/…/runtime-config.ts, ui/…/runtime-config.shared.ts, and ui/instrumentation-client.ts depend on the runtime config island being present before client modules execute. If a new integration reads env directly at module scope instead of through the island, single-image deployments can use stale build-time values or initialize telemetry when it should be disabled.
- ui/…/route.ts deliberately uses
redirect: "manual"so S3 report downloads do not stream through the Next server. Changing this route to follow redirects can proxy large ZIP files through the UI process and break preflight semantics used bydownloadScanZip()in ui/…/helper.ts. - ui/…/side-panel.ts coordinates one global context tab with monotonic owner tokens. If detail views bypass
registerContextTab()/unregisterContextTab()or reuse stale close handlers, the panel can close the wrong detail view or leave the app shell inert throughMainLayout. - ui/…/store.ts treats navigation-aborted server action requests as resumable, not failed. Changes to its
beforeunload/pagehide/pageshowhandling can produce duplicate task polling, lost completion toasts, or dismissed task results after reload.