# audit-tools-deca-lab-cornell/audit-tools-playspace-frontend architecture

> Architecture diagram of the GitHub repository audit-tools-deca-lab-cornell/audit-tools-playspace-frontend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend
- Repository: https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend

## Overview

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: [`src/app/(protected)/layout.tsx`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(protected)/layout.tsx) (App shell), [`src/app/(public)`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(public)) (Public pages), [`src/components/dashboard/data-table.tsx`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/components/dashboard/data-table.tsx) (Dashboard kit), [`src/lib/api/playspace.ts`](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/api/playspace.ts) (Playspace API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public entry"]
  node_public_routes["Public pages<br/>route group"]
  node_login_page["Login<br/>auth page<br/>[page.tsx]"]
  node_signup_page["Signup<br/>auth page<br/>[page.tsx]"]
end

subgraph group_protected["Protected app"]
  node_protected_layout["App shell<br/>protected layout<br/>[layout.tsx]"]
  node_manager_area["Manager area<br/>role area"]
  node_auditor_area["Auditor area<br/>role area"]
  node_admin_area["Admin area<br/>role area"]
  node_settings_page["Settings<br/>preferences page<br/>[page.tsx]"]
  node_audit_form["Audit form<br/>multi-step form<br/>[audit-form.tsx]"]
end

subgraph group_shared["Shared UI"]
  node_dashboard_kit["Dashboard kit<br/>shared widgets<br/>[data-table.tsx]"]
  node_audit_ui["Audit UI<br/>workflow components<br/>[question-card.tsx]"]
  node_design_system["Design system<br/>ui primitives<br/>[button.tsx]"]
end

subgraph group_infra["Infra & data"]
  node_app_root["App root<br/>Next.js app<br/>[layout.tsx]"]
  node_middleware{{"Middleware<br/>route gate<br/>[middleware.ts]"}}
  node_auth_session["Session state<br/>auth cookies<br/>[session.ts]"]
  node_api_client["API client<br/>axios client<br/>[api-client.ts]"]
  node_playspace_api["Playspace API<br/>domain API<br/>[playspace.ts]"]
  node_server_dashboard_api["Dashboard server API<br/>server data"]
  node_i18n_layer["i18n layer<br/>localization<br/>[config.ts]"]
end

subgraph group_tooling["Tooling"]
  node_translations["Translations<br/>message bundles<br/>[en.json]"]
  node_tests["Verification<br/>playwright/scripts"]
end

node_app_root -->|"renders"| node_public_routes
node_app_root -->|"renders"| node_protected_layout
node_public_routes -->|"contains"| node_login_page
node_public_routes -->|"contains"| node_signup_page
node_middleware -->|"guards"| node_protected_layout
node_protected_layout -->|"reads role"| node_auth_session
node_protected_layout -->|"hosts"| node_manager_area
node_protected_layout -->|"hosts"| node_auditor_area
node_protected_layout -->|"hosts"| node_admin_area
node_protected_layout -->|"hosts"| node_settings_page
node_auth_session -->|"tokens"| node_api_client
node_api_client -->|"backs"| node_playspace_api
node_api_client -->|"backs"| node_server_dashboard_api
node_server_dashboard_api -->|"feeds"| node_dashboard_kit
node_dashboard_kit -->|"builds on"| node_design_system
node_audit_form -->|"autosaves"| node_playspace_api
node_auditor_area -->|"uses"| node_audit_form
node_admin_area -->|"uses"| node_dashboard_kit
node_manager_area -->|"uses"| node_dashboard_kit
node_manager_area -->|"fetches"| node_playspace_api
node_auditor_area -->|"fetches"| node_playspace_api
node_i18n_layer -->|"loads"| node_translations
node_design_system -.->|"labels"| node_i18n_layer
node_tests -.->|"covers"| node_public_routes
node_tests -.->|"covers"| node_audit_form
node_tests -.->|"checks"| node_translations

click node_app_root "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/layout.tsx"
click node_public_routes "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(public)"
click node_login_page "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(public)/login/page.tsx"
click node_signup_page "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(public)/signup/page.tsx"
click node_middleware "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/middleware.ts"
click node_protected_layout "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(protected)/layout.tsx"
click node_auth_session "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/auth/session.ts"
click node_api_client "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/api/api-client.ts"
click node_playspace_api "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/api/playspace.ts"
click node_server_dashboard_api "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/api/server-playspace-dashboard.ts"
click node_i18n_layer "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/i18n/config.ts"
click node_dashboard_kit "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/components/dashboard/data-table.tsx"
click node_audit_ui "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/components/audit/question-card.tsx"
click node_design_system "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/components/ui/button.tsx"
click node_manager_area "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(protected)/manager"
click node_auditor_area "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(protected)/auditor"
click node_admin_area "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(protected)/admin"
click node_settings_page "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(protected)/settings/page.tsx"
click node_audit_form "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(protected)/auditor/execute/[placeId]/audit-form.tsx"
click node_translations "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/messages/en.json"
click node_tests "https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/tests/spreadsheet.spec.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_routes,node_login_page,node_signup_page toneBlue
class node_protected_layout,node_manager_area,node_auditor_area,node_admin_area,node_settings_page,node_audit_form toneAmber
class node_dashboard_kit,node_audit_ui,node_design_system toneMint
class node_app_root,node_middleware,node_auth_session,node_api_client,node_playspace_api,node_server_dashboard_api,node_i18n_layer toneRose
class node_translations,node_tests toneIndigo
```

## Components

### Public entry

Unauthenticated login and signup routes.

- [Public pages](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(public)): route group · Login and signup entry points. · `src/app/(public)`
- [Login](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(public)/login/page.tsx): auth page · Public sign-in screen and form. · `src/app/(public)/login/page.tsx`
- [Signup](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(public)/signup/page.tsx): auth page · 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](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(protected)/layout.tsx): protected layout · Shared shell for protected pages with responsive navigation. · `src/app/(protected)/layout.tsx`
- [Manager area](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(protected)/manager): role area · Projects, places, auditors, assignments, and audits for managers. · `src/app/(protected)/manager`
- [Auditor area](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(protected)/auditor): role area · Assigned places, audit execution, and reports for auditors. · `src/app/(protected)/auditor`
- [Admin area](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/tree/master/src/app/(protected)/admin): role area · Accounts, auditors, audits, instruments, places, projects, and system settings. · `src/app/(protected)/admin`
- [Settings](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(protected)/settings/page.tsx): preferences page · Shared protected settings page. · `src/app/(protected)/settings/page.tsx`
- [Audit form](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/(protected)/auditor/execute/[placeId]/audit-form.tsx): multi-step 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](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/components/dashboard/data-table.tsx): shared widgets · Reusable tables, dialogs, stat cards, and CRUD utilities. · `src/components/dashboard/data-table.tsx`
- [Audit UI](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/components/audit/question-card.tsx): workflow components · Components for audit execution and question rendering. · `src/components/audit/question-card.tsx`
- [Design system](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/components/ui/button.tsx): ui primitives · Local shadcn/Tailwind component library. · `src/components/ui/button.tsx`

### Infra & data

Authentication, API, i18n, privacy, and design-system support layers.

- [App root](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/app/layout.tsx): Next.js app · Top-level app entry and global routing/layout. · `src/app/layout.tsx`
- [Middleware](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/middleware.ts): route gate · Enforces role access before protected routes load. · `middleware.ts`
- [Session state](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/auth/session.ts): auth cookies · Browser/server session helpers and demo identity state. · `src/lib/auth/session.ts`
- [API client](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/api/api-client.ts): axios client · Bearer-token transport and 401 session handling. · `src/lib/api/api-client.ts`
- [Playspace API](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/api/playspace.ts): domain API · Frontend helpers for backend domain requests. · `src/lib/api/playspace.ts`
- [Dashboard server API](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/lib/api/server-playspace-dashboard.ts): server data · Server-side data helpers for dashboard pages. · `src/lib/api/server-playspace-dashboard.ts`
- [i18n layer](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/src/i18n/config.ts): localization · Request/config layer for locale-aware rendering. · `src/i18n/config.ts`

### Tooling

Verification, translation, and test support scripts.

- [Translations](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/messages/en.json): message bundles · English and German message catalogs. · `messages/en.json`
- [Verification](https://github.com/audit-tools-deca-lab-cornell/audit-tools-playspace-frontend/blob/master/tests/spreadsheet.spec.ts): playwright/scripts · Playwright tests and audit/translation verification scripts. · `tests/spreadsheet.spec.ts`

## Connections

- 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.
