How riteshtiwari-arista/arista-dhatr works
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 Express server · providerFactory.js Provider factory · app-main.js Workspace UI · app.html Browser app
Components 18
Client
Static browser UI and SPA entrypoints
- Browser app · 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 · Main analysis workspace controller for the SPA.
public/app-main.js - Voice input · Optional voice interaction layer for the workspace.
public/voice-input.js - Auth pages · Landing, login, signup, reset, pricing, settings, and admin pages that frame the user flows.
public/login.html
Backend
Express monolith and orchestration
- Express server · Single-node backend that serves the frontend, exposes APIs, handles auth, analysis, history, settings, billing, and admin flows.
server.mjs - Admin bootstrap · Small utility for creating or bootstrapping an admin account.
create-admin.js - Persona model · Persona definitions and rubrics that drive multi-expert evaluation and de-duplication.
persona.json - Analysis engine · Translates one input into many persona-specific evaluations, then aggregates structured feedback and consensus.
server.mjs - History · Analysis history and related user state surfaced through the backend API.
server.mjs
AI layer
Model abstraction and vendor adapters
- Provider contract · Shared interface used to keep vendor-specific logic out of the rest of the app.
lib/ai-providers/AIProvider.js - Provider factory · Chooses the active model provider based on configuration or user settings.
lib/ai-providers/providerFactory.js - OpenAI adapter · OpenAI implementation of the provider contract.
lib/ai-providers/OpenAIProvider.js - Anthropic adapter · Anthropic implementation of the provider contract.
lib/ai-providers/AnthropicProvider.js
Data
Persistence and key protection
- App data store · Primary persistence layer for users, sessions, settings, history, and billing-related state.
- Key vault · User-managed API keys protected by server-side encryption.
External services
Third-party integrations used by the app
- Figma API · Enriches analyses with metadata, component structure, prototype flow details, and screenshots when a Figma token is available.
- Stripe · Checkout and webhook integration for subscriptions and entitlements.
- Resend · Email verification and password reset delivery.
Connections 17
- 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.