# riteshtiwari-arista/arista-dhatr architecture

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

- Interactive diagram: https://gitdiagram.com/riteshtiwari-arista/arista-dhatr
- Repository: https://github.com/riteshtiwari-arista/arista-dhatr

## Overview

1. **High-level shape**
   - Dhatr is a **single-node monolith**: one Express backend in `server.mjs` serves both the API and the static frontend.
   - The browser app is a **vanilla JavaScript SPA** under `public/`, not a separate frontend service.

2. **Client boundary**
   - User-facing entry points are the static pages in `public/`: `landing-new.html`, `login.html`, `signup.html`, `app.html`, `settings.html`, `pricing.html`, and `admin.html`.
   - `public/app-main.js` is the main client controller for the analysis workspace; `public/voice-input.js` adds optional voice interaction.
   - The frontend talks to the backend through JSON/API endpoints and relies on server sessions for authenticated access.

3. **Backend responsibilities**
   - `server.mjs` appears to own almost all server-side concerns: routing, auth, analysis orchestration, history, settings, billing, and admin flows.
   - This file is the main architectural center, with `create-admin.js` as a small operational helper for bootstrapping an admin account.

4. **Persona-driven analysis engine**
   - The core product logic is driven by `persona.json` and related persona docs.
   - The platform analyzes designs through **32 expert personas** with distinct boundaries, tone, and rubrics, so the server must translate one user input into many persona-specific evaluations and then aggregate the results.
   - The readme emphasizes anti-duplication and consensus tracking, so the analysis output is not just raw model text; it is post-processed into structured, de-duplicated feedback.

5. **AI provider abstraction**
   - `lib/ai-providers/` is a clear boundary around model vendors.
   - `AIProvider.js` defines the shared contract, while `OpenAIProvider.js` and `AnthropicProvider.js` implement the two supported backends.
   - `providerFactory.js` and `index.js` let the server select a default provider or honor user/provider settings without leaking vendor-specific logic into the rest of the app.

6. **Input and enrichment pipeline**
   - The app supports multiple analysis inputs: uploaded images, Figma URLs, document/PRD review, and A/B comparisons.
   - The backend integrates with the **Figma API** when a Figma token is available, pulling metadata, component structure, prototype flow details, and screenshots.
   - The presence of `Sharp` in the stack indicates image handling/normalization is part of the pipeline before AI analysis.

7. **Data persistence and user state**
   - The app supports **SQLite for local/dev** and **PostgreSQL for production**, with tables auto-created on startup.
   - Persisted data likely includes users, sessions, analysis history, settings, and billing-related state, because the API exposes `/api/history`, `/api/settings`, and key-management endpoints.
   - API keys can be user-managed and are protected with encryption (`ENCRYPTION_KEY` in env), which is an important security boundary.

8. **Auth and account lifecycle**
   - The app has dedicated login/signup/reset/forgot-password screens, so account management is a first-class flow rather than a bolt-on.
   - `Resend` is used for email verification and password reset.
   - Session handling is centralized on the server via `SESSION_SECRET`, and admin access is a separate privileged path (`admin.html`, admin bootstrap script).

9. **Billing and entitlements**
   - Stripe is the payment subsystem, with endpoints for checkout creation and webhook processing.
   - Pricing is tier-based: Free, Own Key, and Pro, which affects analysis limits and whether the server or the user supplies the AI key.
   - This means entitlement checks are part of request handling for analysis and provider selection.

10. **Primary API surface**
   - The main backend endpoints are:
     - `/api/analyze` for design analysis
     - `/api/chat` for follow-up dialogue
     - `/api/export-pdf` for report generation
     - `/api/history` for CRUD over past analyses
     - `/api/personas` for loading persona definitions
     - `/api/settings` and `/api/settings/keys` for user configuration and key management
     - Stripe checkout/webhook endpoints for billing
   - This API shape shows the server is the orchestration layer between UI, AI providers, storage, and external services.

11. **Operational and deployment boundary**
   - `vercel.json` indicates deployment on **Vercel**, while the readme also supports other Node hosts.
   - The repo includes `playwright.config.mjs` and several `tests/*.spec.mjs`, suggesting end-to-end browser coverage around core flows like auth, navigation, history, settings, and DOM contract stability.

12. **What to draw in an architecture diagram**
   - A good diagram would center on:
     - **Browser SPA** on one side
     - **Express backend** in the middle
     - **AI providers / Figma / Stripe / Resend** as external services
     - **SQLite/Postgres** as the persistence layer
   - The key internal flow is: user input in the SPA → authenticated API call to `server.mjs` → input enrichment and persona orchestration → vendor AI calls via `lib/ai-providers` → persistence/export/billing updates → response back to the SPA.

Main entry points: [`server.mjs`](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/server.mjs) (Express server), [`lib/ai-providers/providerFactory.js`](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/providerFactory.js) (Provider factory), [`public/app-main.js`](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/app-main.js) (Workspace UI), [`public/app.html`](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/app.html) (Browser app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client"]
  node_browser_shell["Browser app<br/>static SPA<br/>[app.html]"]
  node_workspace_ui["Workspace UI<br/>client controller<br/>[app-main.js]"]
  node_voice_input["Voice input<br/>client enhancer<br/>[voice-input.js]"]
  node_entry_pages["Auth pages<br/>static screens<br/>[login.html]"]
end

subgraph group_backend["Backend"]
  node_server_app["Express server<br/>monolith backend<br/>[server.mjs]"]
  node_admin_bootstrap["Admin bootstrap<br/>ops helper<br/>[create-admin.js]"]
  node_persona_model["Persona model<br/>analysis spec<br/>[persona.json]"]
  node_analysis_flow["Analysis engine<br/>orchestration<br/>[server.mjs]"]
  node_history_api["History<br/>persistence API<br/>[server.mjs]"]
end

subgraph group_ai["AI layer"]
  node_provider_contract["Provider contract<br/>ai abstraction<br/>[AIProvider.js]"]
  node_provider_factory["Provider factory<br/>selection layer<br/>[providerFactory.js]"]
  node_openai_adapter["OpenAI adapter<br/>vendor client<br/>[OpenAIProvider.js]"]
  node_anthropic_adapter["Anthropic adapter<br/>vendor client"]
end

subgraph group_data["Data"]
  node_db_store[("App data store<br/>sqlite/postgres")]
  node_encrypted_keys[("Key vault<br/>encrypted secrets")]
end

subgraph group_external["External services"]
  node_figma_api["Figma API<br/>design import"]
  node_stripe["Stripe<br/>billing"]
  node_resend["Resend<br/>email service"]
end

node_browser_shell -->|"API calls"| node_server_app
node_workspace_ui -->|"analyze/chat/history"| node_server_app
node_voice_input -.->|"augment"| node_workspace_ui
node_entry_pages -->|"auth/navigation"| node_server_app
node_server_app -->|"orchestrates"| node_analysis_flow
node_analysis_flow -->|"loads rubrics"| node_persona_model
node_analysis_flow -->|"selects model"| node_provider_factory
node_provider_factory -->|"implements"| node_provider_contract
node_provider_factory -->|"default/vendor"| node_openai_adapter
node_provider_factory -->|"default/vendor"| node_anthropic_adapter
node_server_app -->|"reads/writes"| node_db_store
node_server_app -->|"protects keys"| node_encrypted_keys
node_server_app -->|"imports design data"| node_figma_api
node_server_app -->|"billing"| node_stripe
node_server_app -->|"email flows"| node_resend
node_server_app -->|"exposes"| node_history_api
node_admin_bootstrap -.->|"admin setup"| node_server_app

click node_browser_shell "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/app.html"
click node_workspace_ui "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/app-main.js"
click node_voice_input "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/voice-input.js"
click node_entry_pages "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/login.html"
click node_server_app "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/server.mjs"
click node_admin_bootstrap "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/create-admin.js"
click node_persona_model "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/persona.json"
click node_analysis_flow "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/server.mjs"
click node_history_api "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/server.mjs"
click node_provider_contract "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/AIProvider.js"
click node_provider_factory "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/providerFactory.js"
click node_openai_adapter "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/OpenAIProvider.js"
click node_anthropic_adapter "https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/AnthropicProvider.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_browser_shell,node_workspace_ui,node_voice_input,node_entry_pages toneBlue
class node_server_app,node_admin_bootstrap,node_persona_model,node_analysis_flow,node_history_api toneAmber
class node_provider_contract,node_provider_factory,node_openai_adapter,node_anthropic_adapter toneMint
class node_db_store,node_encrypted_keys toneRose
class node_figma_api,node_stripe,node_resend toneIndigo
```

## Components

### Client

Static browser UI and SPA entrypoints

- [Browser app](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/app.html): static SPA · Main frontend shell served from the public directory; the user-facing app lives in the browser and talks to the server over JSON APIs. · `public/app.html`
- [Workspace UI](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/app-main.js): client controller · Main analysis workspace controller for the SPA. · `public/app-main.js`
- [Voice input](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/voice-input.js): client enhancer · Optional voice interaction layer for the workspace. · `public/voice-input.js`
- [Auth pages](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/public/login.html): static screens · Landing, login, signup, reset, pricing, settings, and admin pages that frame the user flows. · `public/login.html`

### Backend

Express monolith and orchestration

- [Express server](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/server.mjs): monolith backend · Single-node backend that serves the frontend, exposes APIs, handles auth, analysis, history, settings, billing, and admin flows. · `server.mjs`
- [Admin bootstrap](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/create-admin.js): ops helper · Small utility for creating or bootstrapping an admin account. · `create-admin.js`
- [Persona model](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/persona.json): analysis spec · Persona definitions and rubrics that drive multi-expert evaluation and de-duplication. · `persona.json`
- [Analysis engine](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/server.mjs): orchestration · Translates one input into many persona-specific evaluations, then aggregates structured feedback and consensus. · `server.mjs`
- [History](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/server.mjs): persistence API · Analysis history and related user state surfaced through the backend API. · `server.mjs`

### AI layer

Model abstraction and vendor adapters

- [Provider contract](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/AIProvider.js): ai abstraction · Shared interface used to keep vendor-specific logic out of the rest of the app. · `lib/ai-providers/AIProvider.js`
- [Provider factory](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/providerFactory.js): selection layer · Chooses the active model provider based on configuration or user settings. · `lib/ai-providers/providerFactory.js`
- [OpenAI adapter](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/OpenAIProvider.js): vendor client · OpenAI implementation of the provider contract. · `lib/ai-providers/OpenAIProvider.js`
- [Anthropic adapter](https://github.com/riteshtiwari-arista/arista-dhatr/blob/main/lib/ai-providers/AnthropicProvider.js): vendor client · Anthropic implementation of the provider contract. · `lib/ai-providers/AnthropicProvider.js`

### Data

Persistence and key protection

- **App data store**: sqlite/postgres · Primary persistence layer for users, sessions, settings, history, and billing-related state.
- **Key vault**: encrypted secrets · User-managed API keys protected by server-side encryption.

### External services

Third-party integrations used by the app

- **Figma API**: design import · Enriches analyses with metadata, component structure, prototype flow details, and screenshots when a Figma token is available.
- **Stripe**: billing · Checkout and webhook integration for subscriptions and entitlements.
- **Resend**: email service · Email verification and password reset delivery.

## Connections

- Browser app → Express server: API calls · Authenticated browser requests flow to the monolithic Express backend.
- Workspace UI → Express server: analyze/chat/history · Workspace actions are handled by backend API endpoints.
- Voice input → Workspace UI: augment · Voice input enhances the main workspace controller.
- Auth pages → Express server: auth/navigation · Static entry pages submit login, signup, reset, settings, and admin flows to the server.
- Express server → Analysis engine: orchestrates · Server routes analysis requests into the persona-driven processing pipeline.
- Analysis engine → Persona model: loads rubrics · Persona definitions shape the evaluation prompts and output structure.
- Analysis engine → Provider factory: selects model · The engine uses the factory to resolve the active AI backend.
- Provider factory → Provider contract: implements · Concrete vendor adapters conform to the shared provider interface.
- Provider factory → OpenAI adapter: default/vendor · OpenAI is one supported backend.
- Provider factory → Anthropic adapter: default/vendor · Anthropic is the other supported backend.
- Express server → App data store: reads/writes · Persistent application state is stored in SQLite or PostgreSQL.
- Express server → Key vault: protects keys · User API keys are encrypted before storage and decrypted for use.
- Express server → Figma API: imports design data · Figma metadata and screenshots can be pulled into the analysis pipeline.
- Express server → Stripe: billing · Subscription checkout and webhook processing live in the backend.
- Express server → Resend: email flows · Verification and password-reset emails are sent through Resend.
- Express server → History: exposes · History and related user state are exposed through dedicated API routes.
- Admin bootstrap → Express server: admin setup · Operational helper for privileged account bootstrapping.
