# nuanceaidev/ranksphere architecture

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

- Interactive diagram: https://gitdiagram.com/nuanceaidev/ranksphere
- Repository: https://github.com/nuanceaidev/ranksphere

## Overview

1. **Overall shape**
   - This is a **client-side React SPA** built with **Vite, TypeScript, Tailwind CSS**, and shipped as static files in `dist/`.
   - There is **no custom backend server** in the repo. The app talks directly to **Supabase** for data/storage and to **ValueSERP** for live rank checks.

2. **Application shell**
   - `src/App.tsx` is the top-level composition point.
   - `Sidebar` appears to drive navigation and client selection, while the main workspace swaps between dashboard sections like **Overview, Keywords, Rankings, Analytics**.
   - `ThemeContext` provides the dark/light mode boundary across the app.

3. **UI subsystem boundaries**
   - `src/components/` is organized by domain responsibility:
     - `ClientModal` and `DeleteConfirmModal` handle client CRUD interactions.
     - `Keywords` manages keyword entry and CSV import.
     - `Rankings` and `RankTypeToggle` present rank comparison and filtering.
     - `Overview` and `Analytics` present summary/reporting views.
     - `Sidebar` is the primary navigation/control surface.
   - These components are mostly orchestration and presentation over shared data.

4. **Data access layer**
   - `src/lib/supabase.ts` is the single integration point for the database/storage client.
   - `src/lib/valueserp.ts` is the dedicated integration for external rank lookup requests.
   - `src/types/index.ts` defines the shared domain model used across components, keeping UI, API results, and database records aligned.

5. **Persistent data model**
   - The Supabase migrations under `supabase/migrations/` are the source of truth for schema.
   - The core entities described by the README are:
     - **clients**: name, domain, industry
     - **keywords**: keyword records with monthly rank snapshots
   - The architecture is centered on **client-owned keyword sets** rather than a global keyword list.

6. **Keyword ranking flow**
   - Keywords can be added manually or via CSV upload in the UI.
   - Importantly, keyword creation is **decoupled from rank fetching**: new keywords are stored first, and live rank data is fetched later.
   - The “Fetch Ranks” workflow calls **ValueSERP once per keyword**, with a deliberate delay between calls to avoid API limits and duplicate work.
   - The resulting monthly snapshot updates power the comparison views in Rankings/Overview.

7. **Analytics screenshots flow**
   - `Analytics` handles uploading screenshots such as GA4 or GBP images.
   - Files are stored in **Supabase Storage** in an `analytics_screenshots` bucket, organized by a client/month path pattern.
   - The bucket is intended to be publicly readable so the images can be embedded into generated reports.
   - The README also describes storage lifecycle cleanup, making screenshots effectively **temporary report inputs**.

8. **Reporting flow**
   - The reporting feature combines data from three sources: **client metadata**, **keyword ranking snapshots**, and **analytics screenshots**.
   - Reports are generated as **PDFs in the browser** using the bundled PDF/image tooling implied by the build output and README.
   - The report output includes summary metrics, rank deltas, and screenshots only when those screenshots exist for the selected month.

9. **External dependencies and deployment boundaries**
   - **Supabase** is the persistence boundary: PostgreSQL for structured data and Storage for binary assets.
   - **ValueSERP** is the only external live-search/ranking data source.
   - The app is configured through environment variables in `.env` / `.env.example`, including the Supabase connection and `VITE_VALUESERP_API_KEY`.
   - `vite.config.ts`, `tailwind.config.js`, `postcss.config.js`, and `eslint.config.js` indicate a standard frontend build/tooling pipeline, with `dist/` holding the deployable static artifact.

10. **What to show in an architecture diagram**
   - Draw the browser app as the center.
   - Connect it to:
     - **Supabase Postgres** for clients and keywords
     - **Supabase Storage** for analytics screenshots
     - **ValueSERP API** for rank lookups
   - Show **client-side report generation** inside the app, consuming database records plus storage assets.
   - Keep the main domain boundary around **client → keywords → rankings → analytics → report generation**.

Main entry points: [`src/App.tsx`](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/App.tsx) (App shell), [`src/lib/supabase.ts`](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/lib/supabase.ts) (Supabase client), [`src/types/index.ts`](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/types/index.ts) (Domain types), [`src/components/Rankings.tsx`](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Rankings.tsx) (Rankings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_app["Browser app"]
  node_n_main(("Entry<br/>bootstrap<br/>[main.tsx]"))
  node_n_app["App shell<br/>composition<br/>[App.tsx]"]
  node_n_theme{{"Theme<br/>context<br/>[ThemeContext.tsx]"}}
  node_n_report["Report builder<br/>browser pdf export"]
end

subgraph group_grp_ui["UI features"]
  node_n_sidebar["Sidebar<br/>navigation<br/>[Sidebar.tsx]"]
  node_n_overview["Overview<br/>dashboard view<br/>[Overview.tsx]"]
  node_n_keywords["Keywords<br/>keyword manager<br/>[Keywords.tsx]"]
  node_n_rankings["Rankings<br/>comparison view<br/>[Rankings.tsx]"]
  node_n_rank_toggle["Rank toggle<br/>filter control<br/>[RankTypeToggle.tsx]"]
  node_n_analytics["Analytics<br/>report inputs<br/>[Analytics.tsx]"]
  node_n_client_modal["Client modal<br/>client CRUD<br/>[ClientModal.tsx]"]
  node_n_delete_modal["Delete confirm<br/>destructive dialog"]
end

subgraph group_grp_data["Data layer"]
  node_n_types["Domain types<br/>shared model<br/>[index.ts]"]
  node_n_supabase["Supabase client<br/>db/storage client<br/>[supabase.ts]"]
  node_n_valueserp["ValueSERP client<br/>rank API client<br/>[valueserp.ts]"]
end

subgraph group_grp_persist["Persistence"]
  node_n_schema[("Migrations<br/>schema source")]
  node_n_storage[("Screenshots bucket<br/>object storage<br/>[README.md]")]
  node_n_pg[("Supabase Postgres<br/>database")]
  node_n_valueserp_api{{"ValueSERP API<br/>external service"}}
end

node_n_main -->|"bootstraps"| node_n_app
node_n_app -->|"wraps"| node_n_theme
node_n_app -->|"navigates"| node_n_sidebar
node_n_app -->|"shows"| node_n_overview
node_n_app -->|"shows"| node_n_keywords
node_n_app -->|"shows"| node_n_rankings
node_n_app -->|"shows"| node_n_analytics
node_n_app -->|"opens"| node_n_client_modal
node_n_app -->|"confirms"| node_n_delete_modal
node_n_rankings -->|"filters"| node_n_rank_toggle
node_n_keywords -->|"uses"| node_n_types
node_n_rankings -->|"uses"| node_n_types
node_n_analytics -->|"uses"| node_n_types
node_n_overview -->|"uses"| node_n_types
node_n_app -->|"reads/writes"| node_n_supabase
node_n_keywords -->|"stores"| node_n_supabase
node_n_analytics -->|"uploads"| node_n_supabase
node_n_supabase -->|"connects"| node_n_pg
node_n_supabase -->|"connects"| node_n_storage
node_n_schema -->|"defines"| node_n_pg
node_n_rankings -->|"fetches"| node_n_valueserp
node_n_valueserp -->|"calls"| node_n_valueserp_api
node_n_report -->|"reads"| node_n_supabase
node_n_report -->|"embeds"| node_n_storage
node_n_report -->|"uses"| node_n_types
node_n_app -->|"exports"| node_n_report

click node_n_main "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/main.tsx"
click node_n_app "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/App.tsx"
click node_n_theme "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/contexts/ThemeContext.tsx"
click node_n_sidebar "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Sidebar.tsx"
click node_n_overview "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Overview.tsx"
click node_n_keywords "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Keywords.tsx"
click node_n_rankings "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Rankings.tsx"
click node_n_rank_toggle "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/RankTypeToggle.tsx"
click node_n_analytics "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Analytics.tsx"
click node_n_client_modal "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/ClientModal.tsx"
click node_n_delete_modal "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/DeleteConfirmModal.tsx"
click node_n_types "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/types/index.ts"
click node_n_supabase "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/lib/supabase.ts"
click node_n_valueserp "https://github.com/nuanceaidev/ranksphere/blob/Dev/src/lib/valueserp.ts"
click node_n_storage "https://github.com/nuanceaidev/ranksphere/blob/Dev/supabase/storage/README.md"

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_n_main,node_n_app,node_n_theme,node_n_report toneBlue
class node_n_sidebar,node_n_overview,node_n_keywords,node_n_rankings,node_n_rank_toggle,node_n_analytics,node_n_client_modal,node_n_delete_modal toneAmber
class node_n_types,node_n_supabase,node_n_valueserp toneMint
class node_n_schema,node_n_storage,node_n_pg,node_n_valueserp_api toneRose
```

## Components

### Browser app

Client-side React workspace and shell

- [Entry](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/main.tsx): bootstrap · Mounts the SPA and global styles · `src/main.tsx`
- [App shell](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/App.tsx): composition · Top-level layout and workspace routing · `src/App.tsx`
- [Theme](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/contexts/ThemeContext.tsx): context · Dark/light mode boundary · `src/contexts/ThemeContext.tsx`
- **Report builder**: browser pdf export · Combines client data, ranks, and screenshots into PDFs

### UI features

Domain-oriented presentation and interaction components

- [Sidebar](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Sidebar.tsx): navigation · Client selection and primary navigation · `src/components/Sidebar.tsx`
- [Overview](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Overview.tsx): dashboard view · Summary metrics and high-level status · `src/components/Overview.tsx`
- [Keywords](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Keywords.tsx): keyword manager · Keyword entry and CSV import · `src/components/Keywords.tsx`
- [Rankings](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Rankings.tsx): comparison view · Rank snapshots, deltas, and filters · `src/components/Rankings.tsx`
- [Rank toggle](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/RankTypeToggle.tsx): filter control · Switches rank comparison modes · `src/components/RankTypeToggle.tsx`
- [Analytics](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/Analytics.tsx): report inputs · Screenshot upload and report assets · `src/components/Analytics.tsx`
- [Client modal](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/ClientModal.tsx): client CRUD · Create and edit client records · `src/components/ClientModal.tsx`
- [Delete confirm](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/components/DeleteConfirmModal.tsx): destructive dialog · Confirms removals · `src/components/DeleteConfirmModal.tsx`

### Data layer

Shared types and service integrations

- [Domain types](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/types/index.ts): shared model · Shared client and keyword shapes · `src/types/index.ts`
- [Supabase client](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/lib/supabase.ts): db/storage client · Single integration point for persistence · `src/lib/supabase.ts`
- [ValueSERP client](https://github.com/nuanceaidev/ranksphere/blob/Dev/src/lib/valueserp.ts): rank API client · Fetches live rank results · `src/lib/valueserp.ts`

### Persistence

Database schema and storage boundaries

- **Migrations**: schema source · Postgres schema and data model migrations
- [Screenshots bucket](https://github.com/nuanceaidev/ranksphere/blob/Dev/supabase/storage/README.md): object storage · Public analytics screenshot assets · `supabase/storage/README.md`
- **Supabase Postgres**: database · Structured storage for clients and keywords
- **ValueSERP API**: external service · Live search ranking source

## Connections

- Entry → App shell: bootstraps · Entry mounts the application shell
- App shell → Theme: wraps · Theme context spans the SPA
- App shell → Sidebar: navigates · Sidebar drives client and section switching
- App shell → Overview: shows · Overview is one workspace section
- App shell → Keywords: shows · Keywords section manages keyword data
- App shell → Rankings: shows · Rankings compares monthly snapshots
- App shell → Analytics: shows · Analytics handles screenshot/report inputs
- App shell → Client modal: opens · Client CRUD flows use modal forms
- App shell → Delete confirm: confirms · Destructive actions use confirmation dialog
- Rankings → Rank toggle: filters · Rankings uses toggle controls for comparisons
- Keywords → Domain types: uses · Keyword and client shapes stay aligned
- Rankings → Domain types: uses · Rank snapshots consume shared domain types
- Analytics → Domain types: uses · Screenshot metadata is typed through the shared model
- Overview → Domain types: uses · Summary views are built on shared entities
- App shell → Supabase client: reads/writes · UI persists clients, keywords, and assets through Supabase
- Keywords → Supabase client: stores · Keyword creation and import persist first
- Analytics → Supabase client: uploads · Screenshots are stored in Supabase Storage
- Supabase client → Supabase Postgres: connects · Structured app data lives in Postgres
- Supabase client → Screenshots bucket: connects · Binary report inputs live in object storage
- Migrations → Supabase Postgres: defines · Migrations are the source of truth for schema
- Rankings → ValueSERP client: fetches · Rank checks query the live external API
- ValueSERP client → ValueSERP API: calls · External ranking lookups happen per keyword
- Report builder → Supabase client: reads · Report generation consumes stored client and keyword data
- Report builder → Screenshots bucket: embeds · Reports include available screenshots for the month
- Report builder → Domain types: uses · Report assembly shares the same domain model
- App shell → Report builder: exports · Browser-side PDF generation is part of the workspace
