# hugowelk/norte-v1 architecture

> Architecture diagram of the GitHub repository hugowelk/norte-v1, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hugowelk/norte-v1
- Repository: https://github.com/hugowelk/norte-v1

## Overview

1. **What this repo is**
   - A React + TypeScript single-page app built with Vite and Tailwind/shadcn UI.
   - It is not just a marketing site: the app contains a guided quiz, a paywall, an asynchronous report-generation backend, and an admin area.

2. **Main runtime boundary**
   - The browser hosts the entire interactive frontend.
   - Supabase is the server-side boundary: it provides the database, edge functions, and generated report storage/status.
   - The frontend talks to Supabase through `src/integrations/supabase/client.ts`; backend logic lives under `supabase/functions` and schema/history under `supabase/migrations`.

3. **Primary user journey**
   - The core flow is a multi-step quiz experience in `src/components/quiz` driven by `src/components/QuizFlow.tsx`.
   - The quiz collects preferences and inputs, then moves through tradeoff, reflection, and results screens.
   - `NameEmailCapture.tsx` indicates the handoff from anonymous quiz completion to a known user/session before report generation.

4. **Scoring and recommendation layer**
   - `src/lib/algorithm.ts`, `src/lib/values.ts`, and `src/lib/valueExplanations.ts` form the client-side logic for interpreting quiz answers.
   - These files likely produce the user’s “value compass,” chosen values, and narrative explanations shown in the results and report UI.
   - This is the domain logic that converts raw quiz answers into personalized output.

5. **Paywall and post-paywall flow**
   - The app has an explicit monetization boundary, with dedicated components in `src/components/quiz/Paywall.tsx` and `src/components/post-paywall/*`.
   - `src/lib/postPaywallStore.ts` and `src/lib/pendingSession.ts` suggest the app persists state so users can recover after leaving the paywall or coming back later.
   - `SessionRecovery.tsx` indicates abandoned or interrupted sessions are a first-class case, not an edge case.

6. **Report generation and delivery**
   - Report creation is asynchronous and backend-assisted.
   - `supabase/functions/generate-report` contains locale-specific prompt templates (`prompt.en.ts`, `prompt.pt-BR.ts`), so generated report content is language-aware.
   - `check-report-status` suggests the client polls or refreshes status until the report is ready, then renders it through the report page.

7. **Report presentation layer**
   - `src/pages/ReportPage.tsx` is the end-user destination for generated results.
   - The report is composed from focused sections in `src/components/report`, including the hero, gap visualization, markdown content, actions, privacy notice, and a not-found state.
   - `ReportMarkdown.tsx` implies the generated content is stored or delivered as markdown and rendered in the client.

8. **Admin subsystem**
   - There is a separate admin area in `src/pages/Admin.tsx` and `src/pages/AdminTranslations.tsx`.
   - Supabase edge functions `admin-list` and `admin-delete-report` provide admin-only report operations.
   - `src/components/admin/ReportsChart.tsx` shows the admin side includes reporting/analytics visualization, not just CRUD.

9. **Internationalization and locale-aware content**
   - The app supports at least `en` and `pt-BR` via `src/i18n/locales/*`.
   - `src/i18n/index.ts`, `useLang.ts`, and helpers in `src/lib/i18nHelpers.ts` coordinate language selection and content completeness.
   - `LanguagePicker.tsx` makes locale a user-facing part of the product, and the backend prompt templates mirror those locales.

10. **Cross-cutting client services**
   - `src/lib/analytics.ts` centralizes event tracking for the funnel.
   - `src/lib/reportOwnership.ts` likely ensures only the correct user can access a report.
   - `src/lib/useDocumentMeta.ts` and the localized metadata files under `src/i18n/locales/*/meta.json` indicate SEO/title/description are managed per route and language.

11. **UI foundation**
   - `src/components/ui/*` is a generated/shared component library layer used across quiz, report, admin, and navigation screens.
   - This separates reusable primitives from product-specific flows, which is helpful when drawing the architecture: shared UI at the bottom, flow-specific composites above it.

12. **Build, deploy, and operational shape**
   - Vite builds the frontend; Supabase migrations/functions define the backend runtime.
   - Tests exist via Vitest (`vitest.config.ts`, `src/test/*`), but the architecture is centered on runtime separation between static client and Supabase services.
   - `public/robots.txt`, `sitemap.xml`, and `llms.txt` suggest the app is also optimized for discoverability and content indexing.

Main entry points: [`src/components/QuizFlow.tsx`](https://github.com/hugowelk/norte-v1/blob/main/src/components/QuizFlow.tsx) (Quiz Flow), [`src/integrations/supabase/client.ts`](https://github.com/hugowelk/norte-v1/blob/main/src/integrations/supabase/client.ts) (Supabase Client), [`src/App.tsx`](https://github.com/hugowelk/norte-v1/blob/main/src/App.tsx) (App Shell), [`src/components/quiz`](https://github.com/hugowelk/norte-v1/tree/main/src/components/quiz) (Quiz Steps)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client App"]
  node_src_main["Bootstrap<br/>entrypoint<br/>[main.tsx]"]
  node_src_app["App Shell<br/>router-shell<br/>[App.tsx]"]
  node_page_index["Landing<br/>page<br/>[Index.tsx]"]
  node_quiz_flow["Quiz Flow<br/>funnel-flow<br/>[QuizFlow.tsx]"]
  node_quiz_steps["Quiz Steps<br/>quiz-stage set"]
  node_paywall["Paywall<br/>monetization<br/>[Paywall.tsx]"]
  node_post_paywall["Post-Paywall"]
  node_session_recovery["Session Recovery<br/>state-recovery"]
  node_report_page["Report Page<br/>[ReportPage.tsx]"]
  node_report_sections["Report Sections<br/>report composition"]
  node_admin_pages["Admin Area<br/>admin pages<br/>[Admin.tsx]"]
  node_admin_ui["Admin Tools<br/>admin ui"]
end

subgraph group_backend["Supabase"]
  node_supabase_client["Supabase Client<br/>api client<br/>[client.ts]"]
  node_edge_generate["Generate Report<br/>edge function<br/>[index.ts]"]
  node_edge_status["Check Status<br/>edge function<br/>[index.ts]"]
  node_edge_admin["Admin APIs<br/>edge functions<br/>[index.ts]"]
  node_migrations[("Migrations<br/>schema history")]
end

subgraph group_shared["Shared Layers"]
  node_shared_ui["UI Library<br/>component primitives"]
  node_value_logic["Value Logic<br/>domain logic<br/>[algorithm.ts]"]
  node_analytics["Analytics<br/>telemetry<br/>[analytics.ts]"]
  node_i18n["i18n<br/>localization<br/>[index.ts]"]
  node_locale_content["Locale Content<br/>[common.json]"]
end

node_src_main -->|"bootstraps"| node_src_app
node_src_app -->|"routes"| node_page_index
node_src_app -->|"hosts"| node_quiz_flow
node_quiz_flow -->|"orchestrates"| node_quiz_steps
node_quiz_flow -->|"gates"| node_paywall
node_paywall -->|"hands off"| node_post_paywall
node_quiz_flow -->|"recovers"| node_session_recovery
node_quiz_steps -->|"uses"| node_value_logic
node_quiz_steps -->|"tracks"| node_analytics
node_quiz_steps -->|"localizes"| node_i18n
node_post_paywall -->|"loads"| node_supabase_client
node_supabase_client -->|"calls"| node_edge_generate
node_supabase_client -->|"polls"| node_edge_status
node_supabase_client -->|"admin ops"| node_edge_admin
node_edge_generate -->|"persists"| node_migrations
node_edge_status -->|"reads"| node_migrations
node_report_page -->|"composes"| node_report_sections
node_report_sections -->|"fetches"| node_supabase_client
node_report_sections -->|"renders"| node_value_logic
node_admin_pages -->|"uses"| node_admin_ui
node_admin_ui -->|"queries"| node_edge_admin
node_i18n -->|"sources"| node_locale_content
node_report_page -->|"localizes"| node_i18n
node_src_app -->|"uses"| node_shared_ui
node_quiz_flow -->|"uses"| node_shared_ui
node_report_sections -->|"uses"| node_shared_ui
node_admin_ui -->|"uses"| node_shared_ui

click node_src_main "https://github.com/hugowelk/norte-v1/blob/main/src/main.tsx"
click node_src_app "https://github.com/hugowelk/norte-v1/blob/main/src/App.tsx"
click node_page_index "https://github.com/hugowelk/norte-v1/blob/main/src/pages/Index.tsx"
click node_quiz_flow "https://github.com/hugowelk/norte-v1/blob/main/src/components/QuizFlow.tsx"
click node_quiz_steps "https://github.com/hugowelk/norte-v1/tree/main/src/components/quiz"
click node_paywall "https://github.com/hugowelk/norte-v1/blob/main/src/components/quiz/Paywall.tsx"
click node_post_paywall "https://github.com/hugowelk/norte-v1/tree/main/src/components/post-paywall"
click node_session_recovery "https://github.com/hugowelk/norte-v1/blob/main/src/components/SessionRecovery.tsx"
click node_report_page "https://github.com/hugowelk/norte-v1/blob/main/src/pages/ReportPage.tsx"
click node_report_sections "https://github.com/hugowelk/norte-v1/tree/main/src/components/report"
click node_admin_pages "https://github.com/hugowelk/norte-v1/blob/main/src/pages/Admin.tsx"
click node_admin_ui "https://github.com/hugowelk/norte-v1/tree/main/src/components/admin"
click node_shared_ui "https://github.com/hugowelk/norte-v1/tree/main/src/components/ui"
click node_value_logic "https://github.com/hugowelk/norte-v1/blob/main/src/lib/algorithm.ts"
click node_analytics "https://github.com/hugowelk/norte-v1/blob/main/src/lib/analytics.ts"
click node_i18n "https://github.com/hugowelk/norte-v1/blob/main/src/i18n/index.ts"
click node_supabase_client "https://github.com/hugowelk/norte-v1/blob/main/src/integrations/supabase/client.ts"
click node_edge_generate "https://github.com/hugowelk/norte-v1/blob/main/supabase/functions/generate-report/index.ts"
click node_edge_status "https://github.com/hugowelk/norte-v1/blob/main/supabase/functions/check-report-status/index.ts"
click node_edge_admin "https://github.com/hugowelk/norte-v1/blob/main/supabase/functions/admin-list/index.ts"
click node_migrations "https://github.com/hugowelk/norte-v1/tree/main/supabase/migrations"
click node_locale_content "https://github.com/hugowelk/norte-v1/blob/main/src/i18n/locales/en/common.json"

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_src_main,node_src_app,node_page_index,node_quiz_flow,node_quiz_steps,node_paywall,node_post_paywall,node_session_recovery,node_report_page,node_report_sections,node_admin_pages,node_admin_ui toneBlue
class node_supabase_client,node_edge_generate,node_edge_status,node_edge_admin,node_migrations toneAmber
class node_shared_ui,node_value_logic,node_analytics,node_i18n,node_locale_content toneMint
```

## Components

### Client App

Browser-hosted React frontend and user-facing flows.

- [Bootstrap](https://github.com/hugowelk/norte-v1/blob/main/src/main.tsx): entrypoint · Vite/React application bootstrap and root wiring. · `src/main.tsx`
- [App Shell](https://github.com/hugowelk/norte-v1/blob/main/src/App.tsx): router-shell · Top-level app composition and route selection. · `src/App.tsx`
- [Landing](https://github.com/hugowelk/norte-v1/blob/main/src/pages/Index.tsx): page · Public entry page and main funnel starting point. · `src/pages/Index.tsx`
- [Quiz Flow](https://github.com/hugowelk/norte-v1/blob/main/src/components/QuizFlow.tsx): funnel-flow · Orchestrates the guided quiz experience across multiple stages. · `src/components/QuizFlow.tsx`
- [Quiz Steps](https://github.com/hugowelk/norte-v1/tree/main/src/components/quiz): quiz-stage set · Core quiz screens for values, tradeoffs, reflection, capture, and results. · `src/components/quiz`
- [Paywall](https://github.com/hugowelk/norte-v1/blob/main/src/components/quiz/Paywall.tsx): monetization · Payment gate and recovery-aware handoff into post-paywall flow. · `src/components/quiz/Paywall.tsx`
- [Post-Paywall](https://github.com/hugowelk/norte-v1/tree/main/src/components/post-paywall): post-paywall flow · Deferred content and continuation screens shown after payment. · `src/components/post-paywall`
- [Session Recovery](https://github.com/hugowelk/norte-v1/blob/main/src/components/SessionRecovery.tsx): state-recovery · Resumes interrupted or abandoned quiz/report sessions. · `src/components/SessionRecovery.tsx`
- [Report Page](https://github.com/hugowelk/norte-v1/blob/main/src/pages/ReportPage.tsx): report page · End-user destination for generated personalized reports. · `src/pages/ReportPage.tsx`
- [Report Sections](https://github.com/hugowelk/norte-v1/tree/main/src/components/report): report composition · Hero, gap visualization, markdown, actions, privacy, and empty-state report UI. · `src/components/report`
- [Admin Area](https://github.com/hugowelk/norte-v1/blob/main/src/pages/Admin.tsx): admin pages · Administrative report management and translation oversight. · `src/pages/Admin.tsx`
- [Admin Tools](https://github.com/hugowelk/norte-v1/tree/main/src/components/admin): admin ui · Admin navigation and analytics/charting components. · `src/components/admin`

### Supabase

Server-side database, edge functions, and generated report storage/status.

- [Supabase Client](https://github.com/hugowelk/norte-v1/blob/main/src/integrations/supabase/client.ts): api client · Frontend gateway to Supabase services. · `src/integrations/supabase/client.ts`
- [Generate Report](https://github.com/hugowelk/norte-v1/blob/main/supabase/functions/generate-report/index.ts): edge function · Async report generation with locale-specific prompt templates. · `supabase/functions/generate-report/index.ts`
- [Check Status](https://github.com/hugowelk/norte-v1/blob/main/supabase/functions/check-report-status/index.ts): edge function · Polls report readiness and delivery status. · `supabase/functions/check-report-status/index.ts`
- [Admin APIs](https://github.com/hugowelk/norte-v1/blob/main/supabase/functions/admin-list/index.ts): edge functions · Admin-only list and delete operations for reports. · `supabase/functions/admin-list/index.ts`
- [Migrations](https://github.com/hugowelk/norte-v1/tree/main/supabase/migrations): schema history · Database schema and policy evolution for report/session storage. · `supabase/migrations`

### Shared Layers

Reusable client services, UI primitives, and locale/content foundations.

- [UI Library](https://github.com/hugowelk/norte-v1/tree/main/src/components/ui): component primitives · Reusable shadcn-style UI primitives shared across the app. · `src/components/ui`
- [Value Logic](https://github.com/hugowelk/norte-v1/blob/main/src/lib/algorithm.ts): domain logic · Client-side scoring, value selection, and narrative explanation logic. · `src/lib/algorithm.ts`
- [Analytics](https://github.com/hugowelk/norte-v1/blob/main/src/lib/analytics.ts): telemetry · Centralized funnel/event tracking utilities. · `src/lib/analytics.ts`
- [i18n](https://github.com/hugowelk/norte-v1/blob/main/src/i18n/index.ts): localization · Language selection, completeness checks, and locale-aware metadata/content helpers. · `src/i18n/index.ts`
- [Locale Content](https://github.com/hugowelk/norte-v1/blob/main/src/i18n/locales/en/common.json): content · Localized strings and metadata for supported languages. · `src/i18n/locales/en/common.json`

## Connections

- Bootstrap → App Shell: bootstraps · Root rendering mounts the app shell.
- App Shell → Landing: routes · App shell routes into the public landing and funnel entry.
- App Shell → Quiz Flow: hosts · Main app shell embeds the guided quiz experience.
- Quiz Flow → Quiz Steps: orchestrates · Flow controller advances through quiz stages.
- Quiz Flow → Paywall: gates · Quiz completion can lead into the monetization boundary.
- Paywall → Post-Paywall: hands off · Paid users continue into deferred post-paywall content.
- Quiz Flow → Session Recovery: recovers · Interrupted sessions can be resumed mid-funnel.
- Quiz Steps → Value Logic: uses · Quiz answers are scored and translated into value outcomes.
- Quiz Steps → Analytics: tracks · Key funnel steps emit analytics events.
- Quiz Steps → i18n: localizes · Quiz copy and labels are language-aware.
- Post-Paywall → Supabase Client: loads · Deferred screens fetch or confirm backend state through the client.
- Supabase Client → Generate Report: calls · Frontend requests asynchronous report creation.
- Supabase Client → Check Status: polls · Frontend checks report readiness until completion.
- Supabase Client → Admin APIs: admin ops · Admin screens reach report management functions.
- Generate Report → Migrations: persists · Generated reports rely on database/storage schema and policies.
- Check Status → Migrations: reads · Status checks depend on persisted backend records.
- Report Page → Report Sections: composes · Report page assembles the presentation sections.
- Report Sections → Supabase Client: fetches · Report content/status is loaded from backend services.
- Report Sections → Value Logic: renders · Generated outcomes are presented using the same domain model.
- Admin Area → Admin Tools: uses · Admin routes embed navigation and analytics views.
- Admin Tools → Admin APIs: queries · Admin charts and lists are backed by admin edge functions.
- i18n → Locale Content: sources · Language selection resolves to locale-specific copy and metadata.
- Report Page → i18n: localizes · Report presentation adapts to the selected language.
- App Shell → UI Library: uses · Product flows are built from shared UI primitives.
- Quiz Flow → UI Library: uses · Quiz screens depend on common UI components.
- Report Sections → UI Library: uses · Report presentation is assembled from shared primitives.
- Admin Tools → UI Library: uses · Admin screens reuse the same component library.
