# priyan-b/paletteforge architecture

> Architecture diagram of the GitHub repository priyan-b/paletteforge, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/priyan-b/paletteforge
- Repository: https://github.com/priyan-b/paletteforge

## Overview

#### Purpose and Entry Points
PaletteForge is an authenticated full-stack design workflow: create/edit simple wireframes, derive or manage palettes, and evaluate/apply WCAG accessibility guidance. The Express process starts at `backend.js`; the React SPA mounts at `frontend/src/main.jsx` and coordinates its two top-level modes in `frontend/src/App.jsx`.

#### Application Shell and Authentication
Authentication is session-based Passport Local with bcrypt-backed users. `auth.js` configures identity behavior, `routes/auth.js` exposes registration/login/logout/session endpoints, and `middleware/requireAuth.js` protects application API routes. On the client, `frontend/src/components/AuthGate/AuthGate.jsx` gates the entire SPA on the authenticated session.

#### HTTP and Persistence Boundary
Express mounts feature REST routes from `routes/wireframes.js`, `routes/extractedPalettes.js`, `routes/contrastPalettes.js`, and `routes/contrastReports.js`. These persist user-scoped documents through the native MongoDB driver in `db/connection.js`; no ORM layer exists. Frontend feature API wrappers—`frontend/src/api/wireframes.js`, `frontend/src/api/palettes.js`, and `frontend/src/api/contrastApi.js`—form the client/server boundary.

#### Wireframe Studio
`frontend/src/components/WireframeStudio/WireframeStudio.jsx` owns wireframe and extracted-palette editing state. `WireframeBoard.jsx` and `Shape.jsx` implement the interactive layout surface: selectable rectangle/circle shapes with drag, resize, fill, and labels. Saved layouts flow through `WireframeLibrary.jsx` to the wireframe API; saved image-derived palettes flow through `PaletteExtractor.jsx` and `PaletteLibrary.jsx` to extracted-palette storage.

#### Palette Extraction and Application
Image palette extraction is entirely browser-side in `frontend/src/utils/extractPalette.js`, using canvas-based quantization rather than an external service. `PaletteApplyPanel.jsx` applies palette colors to board shapes, supports direct swatch matching, and shuffles assignments using `frontend/src/utils/shuffleArray.js`, preserving a no-immediate-repeat constraint. The selected/applied palette is also the integration payload for accessibility review.

#### Accessibility Toolkit
`frontend/src/components/AccessibilityToolkit/AccessibilityToolkit.jsx` selects toolkit subviews. `ContrastChecker/ContrastChecker.jsx` provides live pairwise checks; `PaletteBuilder/PaletteBuilder.jsx` assigns fixed UI roles and saves role-based palettes; `PaletteAudit/PaletteAudit.jsx` evaluates defined role pairings and persists reports; `AutoFix/AutoFix.jsx` adjusts a failing foreground color toward its contrast target. Shared client math and role-pair definitions live in `frontend/src/utils/wcag.js` and `frontend/src/utils/roles.js`; matching server-side authority/support exists in `utils/wcag.js` and `utils/roles.js`.

#### Cross-Feature Flow and Runtime
The SPA uses `useState` tab switching rather than client-side routing. Wireframe Studio hands its applied colors directly into the Palette Builder, avoiding re-entry before audit or auto-fix. Development runs React 19/Vite, with `frontend/vite.config.js` proxying `/api` to Node/Express 5. Production Express serves the built frontend. Required infrastructure is MongoDB plus environment-provided `MONGODB_URI`, `SESSION_SECRET`, and port; deployment is documented on Render.

Main entry points: [`routes/wireframes.js`](https://github.com/priyan-b/paletteforge/blob/main/routes/wireframes.js) (Feature REST routes), [`frontend/src/components/AccessibilityToolkit/AccessibilityToolkit.jsx`](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/components/AccessibilityToolkit/AccessibilityToolkit.jsx) (Toolkit selector), [`frontend/src/App.jsx`](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/App.jsx) (App modes), [`frontend/src/components/WireframeStudio/WireframeStudio.jsx`](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/components/WireframeStudio/WireframeStudio.jsx) (Studio state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React SPA"]
  node_spa_entry["SPA entry<br/>React entry<br/>[main.jsx]"]
  node_app_shell["App modes<br/>React shell<br/>[App.jsx]"]
  node_auth_gate["Auth gate<br/>session gate<br/>[AuthGate.jsx]"]
end

subgraph group_studio["Wireframe Studio"]
  node_studio_shell["Studio state<br/>React feature"]
  node_board["Interactive board<br/>canvas UI"]
  node_wireframe_library["Wireframe library<br/>saved layouts"]
  node_palette_extractor["Palette extraction<br/>image palette UI"]
  node_palette_apply["Palette apply<br/>shape color UI"]
  node_browser_extraction{{"Canvas quantization<br/>browser utility<br/>[extractPalette.js]"}}
end

subgraph group_accessibility["Accessibility Toolkit"]
  node_toolkit["Toolkit selector<br/>React feature"]
  node_contrast_checker["Live contrast check<br/>WCAG UI"]
  node_palette_builder["Role palette builder<br/>WCAG UI"]
  node_palette_audit["Palette audit<br/>WCAG UI"]
  node_auto_fix["Auto-fix contrast<br/>WCAG UI"]
  node_client_wcag{{"WCAG math and roles<br/>shared client utility<br/>[wcag.js]"}}
end

subgraph group_server["Express API"]
  node_express["Express runtime<br/>Node server<br/>[backend.js]"]
  node_auth["Passport auth<br/>session authentication<br/>[auth.js]"]
  node_api_routes["Feature REST routes<br/>Express routes<br/>[wireframes.js]"]
  node_auth_routes["Auth endpoints<br/>Express routes<br/>[auth.js]"]
  node_auth_middleware["Route protection<br/>Express middleware<br/>[requireAuth.js]"]
  node_mongo_connection[("MongoDB driver<br/>persistence adapter<br/>[connection.js]")]
end

node_mongodb[("MongoDB<br/>database")]

node_spa_entry -->|"mounts"| node_app_shell
node_app_shell -->|"gated by"| node_auth_gate
node_auth_gate -->|"session API"| node_auth_routes
node_app_shell -->|"Studio mode"| node_studio_shell
node_app_shell -->|"Accessibility mode"| node_toolkit
node_studio_shell -->|"edits"| node_board
node_studio_shell -->|"saved layouts"| node_wireframe_library
node_studio_shell -->|"image palettes"| node_palette_extractor
node_palette_extractor -->|"quantizes image"| node_browser_extraction
node_palette_apply -->|"colors shapes"| node_board
node_palette_apply -->|"applied colors"| node_palette_builder
node_toolkit -->|"selects"| node_contrast_checker
node_toolkit -->|"selects"| node_palette_builder
node_toolkit -->|"selects"| node_palette_audit
node_toolkit -->|"selects"| node_auto_fix
node_contrast_checker -->|"calculates"| node_client_wcag
node_palette_audit -->|"evaluates"| node_client_wcag
node_express -->|"configures"| node_auth
node_express -->|"mounts"| node_auth_routes
node_express -->|"uses"| node_auth_middleware
node_auth_middleware -->|"protects"| node_api_routes
node_wireframe_library -->|"wireframe API"| node_api_routes
node_palette_extractor -->|"extracted-palette API"| node_api_routes
node_palette_audit -->|"report API"| node_api_routes
node_palette_builder -->|"role-palette API"| node_api_routes
node_auth_routes -->|"users"| node_mongo_connection
node_api_routes -->|"user documents"| node_mongo_connection
node_mongo_connection -->|"native driver"| node_mongodb

click node_spa_entry "https://github.com/priyan-b/paletteforge/blob/main/frontend/src/main.jsx"
click node_app_shell "https://github.com/priyan-b/paletteforge/blob/main/frontend/src/App.jsx"
click node_auth_gate "https://github.com/priyan-b/paletteforge/blob/main/frontend/src/components/AuthGate/AuthGate.jsx"
click node_studio_shell "https://github.com/priyan-b/paletteforge/blob/main/frontend/src/components/WireframeStudio/WireframeStudio.jsx"
click node_browser_extraction "https://github.com/priyan-b/paletteforge/blob/main/frontend/src/utils/extractPalette.js"
click node_toolkit "https://github.com/priyan-b/paletteforge/blob/main/frontend/src/components/AccessibilityToolkit/AccessibilityToolkit.jsx"
click node_client_wcag "https://github.com/priyan-b/paletteforge/blob/main/frontend/src/utils/wcag.js"
click node_express "https://github.com/priyan-b/paletteforge/blob/main/backend.js"
click node_auth "https://github.com/priyan-b/paletteforge/blob/main/auth.js"
click node_api_routes "https://github.com/priyan-b/paletteforge/blob/main/routes/wireframes.js"
click node_auth_routes "https://github.com/priyan-b/paletteforge/blob/main/routes/auth.js"
click node_auth_middleware "https://github.com/priyan-b/paletteforge/blob/main/middleware/requireAuth.js"
click node_mongo_connection "https://github.com/priyan-b/paletteforge/blob/main/db/connection.js"

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_spa_entry,node_app_shell,node_auth_gate toneBlue
class node_studio_shell,node_board,node_wireframe_library,node_palette_extractor,node_palette_apply,node_browser_extraction toneAmber
class node_toolkit,node_contrast_checker,node_palette_builder,node_palette_audit,node_auto_fix,node_client_wcag toneMint
class node_express,node_auth,node_api_routes,node_auth_routes,node_auth_middleware,node_mongo_connection toneRose
class node_mongodb toneNeutral
```

## Components

### React SPA

Vite-built browser application.

- [SPA entry](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/main.jsx): React entry · `frontend/src/main.jsx`
- [App modes](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/App.jsx): React shell · Switches between Studio and Accessibility views with useState. · `frontend/src/App.jsx`
- [Auth gate](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/components/AuthGate/AuthGate.jsx): session gate · Blocks the SPA until a session is authenticated. · `frontend/src/components/AuthGate/AuthGate.jsx`

### Wireframe Studio

- [Studio state](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/components/WireframeStudio/WireframeStudio.jsx): React feature · Owns wireframe and extracted-palette editing state. · `frontend/src/components/WireframeStudio/WireframeStudio.jsx`
- **Interactive board**: canvas UI · Selectable, draggable, resizable shapes.
- **Wireframe library**: saved layouts
- **Palette extraction**: image palette UI
- **Palette apply**: shape color UI · Applies and shuffles palette assignments without immediate repeats.
- [Canvas quantization](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/utils/extractPalette.js): browser utility · Extracts image colors entirely in the browser. · `frontend/src/utils/extractPalette.js`

### Accessibility Toolkit

- [Toolkit selector](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/components/AccessibilityToolkit/AccessibilityToolkit.jsx): React feature · Selects accessibility subviews. · `frontend/src/components/AccessibilityToolkit/AccessibilityToolkit.jsx`
- **Live contrast check**: WCAG UI
- **Role palette builder**: WCAG UI · Receives applied Studio colors for role assignment.
- **Palette audit**: WCAG UI · Evaluates role pairings and saves reports.
- **Auto-fix contrast**: WCAG UI · Adjusts failing foreground colors toward their target.
- [WCAG math and roles](https://github.com/priyan-b/paletteforge/blob/main/frontend/src/utils/wcag.js): shared client utility · `frontend/src/utils/wcag.js`

### Express API

- [Express runtime](https://github.com/priyan-b/paletteforge/blob/main/backend.js): Node server · Serves APIs and the production frontend build. · `backend.js`
- [Passport auth](https://github.com/priyan-b/paletteforge/blob/main/auth.js): session authentication · Local strategy with bcrypt-backed users. · `auth.js`
- [Feature REST routes](https://github.com/priyan-b/paletteforge/blob/main/routes/wireframes.js): Express routes · Wireframes, extracted palettes, contrast palettes, and reports. · `routes/wireframes.js`
- [Auth endpoints](https://github.com/priyan-b/paletteforge/blob/main/routes/auth.js): Express routes · Registration, login, logout, and session endpoints. · `routes/auth.js`
- [Route protection](https://github.com/priyan-b/paletteforge/blob/main/middleware/requireAuth.js): Express middleware · `middleware/requireAuth.js`
- [MongoDB driver](https://github.com/priyan-b/paletteforge/blob/main/db/connection.js): persistence adapter · Persists user-scoped documents through the native driver. · `db/connection.js`

### Other components

- **MongoDB**: database · Required external persistence infrastructure.

## Connections

- SPA entry → App modes: mounts
- App modes → Auth gate: gated by
- Auth gate → Auth endpoints: session API
- App modes → Studio state: Studio mode
- App modes → Toolkit selector: Accessibility mode
- Studio state → Interactive board: edits
- Studio state → Wireframe library: saved layouts
- Studio state → Palette extraction: image palettes
- Palette extraction → Canvas quantization: quantizes image
- Palette apply → Interactive board: colors shapes
- Palette apply → Role palette builder: applied colors · Direct cross-feature payload.
- Toolkit selector → Live contrast check: selects
- Toolkit selector → Role palette builder: selects
- Toolkit selector → Palette audit: selects
- Toolkit selector → Auto-fix contrast: selects
- Live contrast check → WCAG math and roles: calculates
- Palette audit → WCAG math and roles: evaluates
- Express runtime → Passport auth: configures
- Express runtime → Auth endpoints: mounts
- Express runtime → Route protection: uses
- Route protection → Feature REST routes: protects
- Wireframe library → Feature REST routes: wireframe API
- Palette extraction → Feature REST routes: extracted-palette API
- Palette audit → Feature REST routes: report API
- Role palette builder → Feature REST routes: role-palette API
- Auth endpoints → MongoDB driver: users
- Feature REST routes → MongoDB driver: user documents
- MongoDB driver → MongoDB: native driver
