How audit-tools-deca-lab-cornell/audit-tools-playspace-frontend works
1. System boundary
This repository is a Next.js 15 frontend for the Playspace Play Value & Usability Audit Tool. It is not the backend; it is built to talk to a separate FastAPI API via a configurable NEXT_PUBLIC_API_BASE_URL and uses browser/server cookies to simulate or carry auth state.
2. Route structure
The app is split into public and protected route groups. Public pages are limited to login/signup. Protected pages are organized by role: manager, auditor, and admin, plus shared settings. This is the main architectural boundary for the UI.
3. Authentication and route gating
Authentication is currently a frontend-only demo session implemented with cookies such as playspace_role, playspace_access_token, and playspace_auditor_code. middleware.ts enforces access rules before routes load, while the axios client adds bearer tokens to API calls and clears the session on 401.
4. Role-based application shell
Protected pages render inside a shared AppShell with responsive navigation: sidebar on desktop, drawer/sheet on mobile. The shell derives navigation from the active role, so the same layout framework supports manager, auditor, and admin experiences without duplicating chrome.
5. Domain hierarchy
The app is centered on the hierarchy Account → Projects → Places → Audits. The different role areas expose different slices of that hierarchy:
- Admin manages accounts, auditors, audits, instruments, places, projects, and system settings.
- Manager works mainly with projects, places, auditors, assignments, and audits.
- Auditor focuses on assigned places, audit execution, and reports.
6. Audit execution flow
The auditor workflow is one of the key interactive subsystems. src/app/(protected)/auditor/execute/[placeId] uses a server page wrapper plus a client form. The form is multi-step, watches values with React Hook Form, and auto-saves partial draft state through debounced PATCH requests to the backend.
7. Dashboard and CRUD subsystem
Most manager/admin screens are built from a reusable dashboard toolkit: data tables, pagination, column headers, row actions, dialogs, sheets, empty states, and stat cards. This shared component layer supports the CRUD-like pages for projects, places, auditors, accounts, and audits.
8. API and data-fetching layer
Backend integration is concentrated under src/lib/api. The axios client centralizes transport concerns, while playspace-specific API helpers and dashboard server helpers encapsulate domain requests. The architecture is designed around server-rendered pages plus client-side interactivity, with TanStack Query handling client data synchronization where needed.
9. Shared UI and design system
The UI is composed from a local component library built on shadcn/ui and Tailwind CSS primitives. This includes forms, tables, dialogs, tabs, sheets, buttons, cards, and accessibility-friendly controls. The app also has small reusable utilities for form handling, table behavior, and masking/privacy logic.
10. Internationalization
The repository includes localized message bundles in English and German plus an i18n request/config layer. Translation scripts indicate that copy is maintained as a first-class asset, not hardcoded in components. This matters for architecture because text content is externalized and likely resolved at render time.
11. Verification and auxiliary tooling
The repo includes Playwright tests plus spreadsheet/audit verification scripts, suggesting the frontend is validated against structured audit artifacts and contract-like expectations. There are also scripts for translation export and audit contract checks, which are supporting subsystems rather than user-facing features.
12. How the main data flows work
Typical flow is: user enters via public auth pages → middleware admits the role-appropriate protected area → server page renders data or shell → client components fetch/update through the axios API client → backend persists audit/project/place state → tables/forms refresh via local state or query caching. The most important cross-cutting concerns are role enforcement, token propagation, and audit draft persistence.
Main entry points: layout.tsx App shell · (public) Public pages · data-table.tsx Dashboard kit · playspace.ts Playspace API
Components 21
Public entry
Unauthenticated login and signup routes.
- Public pages · Login and signup entry points.
src/app/(public) - Login · Public sign-in screen and form.
src/app/(public)/login/page.tsx - Signup · Public account creation screen and form.
src/app/(public)/signup/page.tsx
Protected app
Role-based application areas wrapped by the shared shell.
- App shell · Shared shell for protected pages with responsive navigation.
src/app/(protected)/layout.tsx - Manager area · Projects, places, auditors, assignments, and audits for managers.
src/app/(protected)/manager - Auditor area · Assigned places, audit execution, and reports for auditors.
src/app/(protected)/auditor - Admin area · Accounts, auditors, audits, instruments, places, projects, and system settings.
src/app/(protected)/admin - Settings · Shared protected settings page.
src/app/(protected)/settings/page.tsx - Audit form · Auditor execution form with draft autosave.
src/app/(protected)/auditor/execute/[placeId]/audit-form.tsx
Shared UI
Reusable shell, dashboard widgets, and audit components used across roles.
- Dashboard kit · Reusable tables, dialogs, stat cards, and CRUD utilities.
src/components/dashboard/data-table.tsx - Audit UI · Components for audit execution and question rendering.
src/components/audit/question-card.tsx - Design system · Local shadcn/Tailwind component library.
src/components/ui/button.tsx
Infra & data
Authentication, API, i18n, privacy, and design-system support layers.
- App root · Top-level app entry and global routing/layout.
src/app/layout.tsx - Middleware · Enforces role access before protected routes load.
middleware.ts - Session state · Browser/server session helpers and demo identity state.
src/lib/auth/session.ts - API client · Bearer-token transport and 401 session handling.
src/lib/api/api-client.ts - Playspace API · Frontend helpers for backend domain requests.
src/lib/api/playspace.ts - Dashboard server API · Server-side data helpers for dashboard pages.
src/lib/api/server-playspace-dashboard.ts - i18n layer · Request/config layer for locale-aware rendering.
src/i18n/config.ts
Tooling
Verification, translation, and test support scripts.
- Translations · English and German message catalogs.
messages/en.json - Verification · Playwright tests and audit/translation verification scripts.
tests/spreadsheet.spec.ts
Connections 26
- App root → Public pages: renders · Root app includes public route group.
- App root → App shell: renders · Root app includes protected route group.
- Public pages → Login: contains · Public routes include login.
- Public pages → Signup: contains · Public routes include signup.
- Middleware → App shell: guards · Middleware admits or blocks protected routes.
- App shell → Session state: reads role · Shell derives navigation from session role.
- App shell → Manager area: hosts · Shared shell wraps manager UI.
- App shell → Auditor area: hosts · Shared shell wraps auditor UI.
- App shell → Admin area: hosts · Shared shell wraps admin UI.
- App shell → Settings: hosts · Shared shell wraps settings page.
- Session state → API client: tokens · Session state supplies bearer tokens and role info.
- API client → Playspace API: backs · Domain helpers use the shared axios transport.
- API client → Dashboard server API: backs · Server dashboard helpers rely on the transport layer.
- Dashboard server API → Dashboard kit: feeds · Server-rendered dashboard pages populate shared tables and cards.
- Dashboard kit → Design system: builds on · Dashboard widgets are composed from local UI primitives.
- Audit form → Playspace API: autosaves · Draft audit updates are sent to the backend.
- Auditor area → Audit form: uses · Auditor execution route mounts the form workflow.
- Admin area → Dashboard kit: uses · Admin CRUD screens are built from the shared dashboard toolkit.
- Manager area → Dashboard kit: uses · Manager CRUD screens are built from the shared dashboard toolkit.
- Manager area → Playspace API: fetches · Manager pages read and update domain entities.
- Auditor area → Playspace API: fetches · Auditor pages load assignments, places, and reports.
- i18n layer → Translations: loads · Locale-aware messages are resolved from bundles.
- Design system → i18n layer: labels · UI copy is externalized through the localization layer.
- Verification → Public pages: covers · Tests exercise public entry points and flows.
- Verification → Audit form: covers · Verification includes audit workflow behavior.
- Verification → Translations: checks · Scripts validate translation and audit artifacts.