# bigc7292/discount-hunter-ai architecture

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

- Interactive diagram: https://gitdiagram.com/bigc7292/discount-hunter-ai
- Repository: https://github.com/bigc7292/discount-hunter-ai

## Overview

#### Purpose and Deployable Surfaces
Discount Hunter AI is a React SaaS frontend for searching and presenting merchant discount-code results, with region selection, authentication, saved/recent results, and an operator-style console UI. A separate TypeScript backend supports discovery, verification, browser automation, proxying, and session handling.

Frontend bootstraps at `src/index.tsx` into `src/App.tsx`; backend process entry is `backend/src/index.ts`. The frontend is Vite-based and deployable through `vercel.json`; the backend includes Docker, Railway, and Procfile deployment artifacts in `backend/Dockerfile`, `backend/railway.json`, and `backend/Procfile`.

#### Frontend Application Shell
`src/App.tsx` owns the high-level application state and composition. It switches between landing, dashboard/workspace, auth, and pricing experiences using components such as `src/components/LandingPage.tsx`, `src/components/Dashboard.tsx`, and `src/components/DashboardWorkspace.tsx`.

The UI is a client-rendered React/TypeScript application, styled through `src/index.css` and Tailwind configuration. The landing/search path is centered on `src/components/HeroSearchBar.tsx`; authenticated or working sessions use the dashboard and sidebar surfaces.

#### Search and Result Workflow
A user supplies a merchant/query and optional region through `src/components/HeroSearchBar.tsx` and `src/components/RegionSelector.tsx`. Client service boundaries are concentrated in `src/services/searchService.ts` and `src/services/apiService.ts`, which should isolate UI components from provider/backend request details.

Results flow into display and selection components: `src/components/ResultsDisplay.tsx`, `src/components/ResultCard.tsx`, and `src/components/CategoryChips.tsx`. `src/components/TerminalLog.tsx` provides a visible progress/agent-log channel, likely reflecting discovery-stage status rather than being the discovery implementation itself.

#### Backend Discovery Pipeline
The backend’s architectural core is a provider-orchestrated discovery pipeline. `backend/src/discovery/orchestrator.ts` coordinates search/extraction stages, while `backend/src/discovery.ts` appears to provide a top-level discovery-facing module. Shared contracts are defined in `backend/src/types.ts`.

Provider adapters establish external-search boundaries: `backend/src/discovery/serperService.ts`, `backend/src/discovery/tavilyService.ts`, `backend/src/discovery/firecrawlService.ts`, `backend/src/discovery/jinaService.ts`, and `backend/src/discovery/zernioService.ts`. Extracted content is processed by `backend/src/discovery/codeExtractor.ts`, with region normalization/utilities in `backend/src/discovery/regionUtils.ts`.

#### Verification, Automation, and Network Controls
Discovered codes can pass through verification and automation capabilities in `backend/src/verifier.ts` and `backend/src/browserBot.ts`. These are distinct from discovery: discovery finds candidate sources/codes; verification/browser automation can test or inspect them.

Network/location-dependent requests are separated behind `backend/src/proxyManager.ts` and `backend/src/geoProxy.ts`. This boundary is material for provider access, regional commerce behavior, and avoiding proxy concerns leaking into UI or extraction logic.

#### Identity, Persistence, and External Services
Firebase is the frontend identity and datastore integration point, initialized in `src/firebaseConfig.ts`; repository-level `firestore.rules` and `firestore.indexes.json` define Firestore access/index infrastructure. Authentication UI is handled by `src/components/AuthModal.tsx`.

User/session and result-related backend state is represented by `backend/src/sessionStore.ts` and `backend/src/profileManager.ts`; frontend recent/saved-value access is isolated in `src/services/recentSavingsService.ts`. The repository also contains `backend/src/newsletter.ts`, indicating an outbound messaging/integration boundary.

README identifies Google Gemini and NVIDIA NIM as intelligence services, while the concrete frontend AI client present is `src/services/nvidiaService.ts`. API keys and service endpoints are environment-configured through `.env.example` and `backend/.env.example`.

Main entry points: [`src/services/apiService.ts`](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/services/apiService.ts) (Client API boundary), [`src/App.tsx`](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/App.tsx) (Application shell), [`src/components/HeroSearchBar.tsx`](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/HeroSearchBar.tsx) (Landing search), [`backend/src/index.ts`](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/index.ts) (Backend entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React Frontend"]
  node_fe_entry["Frontend bootstrap<br/>React entry<br/>[index.tsx]"]
  node_app_shell["Application shell<br/>React composition<br/>[App.tsx]"]
  node_landing_search["Landing search<br/>search UI<br/>[HeroSearchBar.tsx]"]
  node_region_selector["Region selector<br/>search UI<br/>[RegionSelector.tsx]"]
  node_workspace["Dashboard workspace<br/>authenticated UI"]
  node_results_ui["Results presentation<br/>result UI<br/>[ResultsDisplay.tsx]"]
  node_terminal_log["Progress log<br/>status UI<br/>[TerminalLog.tsx]"]
  node_client_api{{"Client API boundary<br/>frontend services<br/>[apiService.ts]"}}
  node_recent_savings["Saved and recent results<br/>frontend persistence service"]
  node_auth_modal["Authentication UI<br/>auth UI<br/>[AuthModal.tsx]"]
  node_ai_client{{"NVIDIA AI client<br/>intelligence integration<br/>[nvidiaService.ts]"}}
end

subgraph group_backend["Backend Service"]
  node_backend_entry["Backend entry<br/>TypeScript service entry<br/>[index.ts]"]
  node_discovery_api{{"Discovery module<br/>discovery facade<br/>[discovery.ts]"}}
  node_orchestrator["Discovery orchestrator<br/>pipeline coordinator<br/>[orchestrator.ts]"]
  node_providers{{"Search provider adapters<br/>external discovery adapters<br/>[serperService.ts]"}}
  node_extractor["Code extractor<br/>content processing<br/>[codeExtractor.ts]"]
  node_verification["Verification and browser bot<br/>code validation<br/>[verifier.ts]"]
  node_network{{"Proxy and geo controls<br/>network boundary<br/>[proxyManager.ts]"}}
end

subgraph group_state["Identity &amp; State"]
  node_firebase[("Firebase integration<br/>identity and datastore<br/>[firebaseConfig.ts]")]
  node_session_profile[("Session and profiles<br/>backend state<br/>[sessionStore.ts]")]
end

node_fe_entry -->|"mounts"| node_app_shell
node_app_shell -->|"renders"| node_landing_search
node_app_shell -->|"renders"| node_workspace
node_app_shell -->|"opens"| node_auth_modal
node_landing_search -->|"selects region"| node_region_selector
node_landing_search -->|"submits query"| node_client_api
node_client_api -->|"calls"| node_backend_entry
node_backend_entry -->|"serves"| node_discovery_api
node_discovery_api -->|"starts"| node_orchestrator
node_orchestrator -->|"uses regional access"| node_network
node_orchestrator -->|"queries"| node_providers
node_providers -->|"returns source content"| node_extractor
node_extractor -->|"passes candidate codes"| node_verification
node_client_api -->|"supplies results"| node_results_ui
node_client_api -.->|"supplies progress"| node_terminal_log
node_results_ui -->|"saves selections"| node_recent_savings
node_auth_modal -->|"authenticates with"| node_firebase
node_recent_savings -->|"stores user data"| node_firebase
node_backend_entry -->|"manages"| node_session_profile
node_workspace -->|"hosts"| node_results_ui
node_client_api -.->|"uses intelligence"| node_ai_client

click node_fe_entry "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/index.tsx"
click node_app_shell "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/App.tsx"
click node_landing_search "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/HeroSearchBar.tsx"
click node_region_selector "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/RegionSelector.tsx"
click node_workspace "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/DashboardWorkspace.tsx"
click node_results_ui "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/ResultsDisplay.tsx"
click node_terminal_log "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/TerminalLog.tsx"
click node_client_api "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/services/apiService.ts"
click node_recent_savings "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/services/recentSavingsService.ts"
click node_firebase "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/firebaseConfig.ts"
click node_auth_modal "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/AuthModal.tsx"
click node_backend_entry "https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/index.ts"
click node_discovery_api "https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/discovery.ts"
click node_orchestrator "https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/discovery/orchestrator.ts"
click node_providers "https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/discovery/serperService.ts"
click node_extractor "https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/discovery/codeExtractor.ts"
click node_verification "https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/verifier.ts"
click node_network "https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/proxyManager.ts"
click node_session_profile "https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/sessionStore.ts"
click node_ai_client "https://github.com/bigc7292/discount-hunter-ai/blob/main/src/services/nvidiaService.ts"

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_fe_entry,node_app_shell,node_landing_search,node_region_selector,node_workspace,node_results_ui,node_terminal_log,node_client_api,node_recent_savings,node_auth_modal,node_ai_client toneBlue
class node_backend_entry,node_discovery_api,node_orchestrator,node_providers,node_extractor,node_verification,node_network toneAmber
class node_firebase,node_session_profile toneMint
```

## Components

### React Frontend

- [Frontend bootstrap](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/index.tsx): React entry · `src/index.tsx`
- [Application shell](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/App.tsx): React composition · Selects landing, workspace, auth, and pricing experiences. · `src/App.tsx`
- [Landing search](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/HeroSearchBar.tsx): search UI · `src/components/HeroSearchBar.tsx`
- [Region selector](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/RegionSelector.tsx): search UI · `src/components/RegionSelector.tsx`
- [Dashboard workspace](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/DashboardWorkspace.tsx): authenticated UI · `src/components/DashboardWorkspace.tsx`
- [Results presentation](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/ResultsDisplay.tsx): result UI · Displays and filters returned discount candidates. · `src/components/ResultsDisplay.tsx`
- [Progress log](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/TerminalLog.tsx): status UI · Visible discovery-stage progress channel. · `src/components/TerminalLog.tsx`
- [Client API boundary](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/services/apiService.ts): frontend services · Isolates UI from backend and provider request details. · `src/services/apiService.ts`
- [Saved and recent results](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/services/recentSavingsService.ts): frontend persistence service · `src/services/recentSavingsService.ts`
- [Authentication UI](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/components/AuthModal.tsx): auth UI · `src/components/AuthModal.tsx`
- [NVIDIA AI client](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/services/nvidiaService.ts): intelligence integration · `src/services/nvidiaService.ts`

### Backend Service

- [Backend entry](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/index.ts): TypeScript service entry · `backend/src/index.ts`
- [Discovery module](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/discovery.ts): discovery facade · `backend/src/discovery.ts`
- [Discovery orchestrator](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/discovery/orchestrator.ts): pipeline coordinator · Coordinates provider search and extraction stages. · `backend/src/discovery/orchestrator.ts`
- [Search provider adapters](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/discovery/serperService.ts): external discovery adapters · Serper, Tavily, Firecrawl, Jina, and Zernio integrations. · `backend/src/discovery/serperService.ts`
- [Code extractor](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/discovery/codeExtractor.ts): content processing · `backend/src/discovery/codeExtractor.ts`
- [Verification and browser bot](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/verifier.ts): code validation · Tests or inspects discovered codes independently of discovery. · `backend/src/verifier.ts`
- [Proxy and geo controls](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/proxyManager.ts): network boundary · Controls regional and provider-facing requests. · `backend/src/proxyManager.ts`

### Identity & State

- [Firebase integration](https://github.com/bigc7292/discount-hunter-ai/blob/main/src/firebaseConfig.ts): identity and datastore · Frontend authentication and Firestore integration point. · `src/firebaseConfig.ts`
- [Session and profiles](https://github.com/bigc7292/discount-hunter-ai/blob/main/backend/src/sessionStore.ts): backend state · `backend/src/sessionStore.ts`

## Connections

- Frontend bootstrap → Application shell: mounts
- Application shell → Landing search: renders
- Application shell → Dashboard workspace: renders
- Application shell → Authentication UI: opens
- Landing search → Region selector: selects region
- Landing search → Client API boundary: submits query
- Client API boundary → Backend entry: calls
- Backend entry → Discovery module: serves
- Discovery module → Discovery orchestrator: starts
- Discovery orchestrator → Proxy and geo controls: uses regional access
- Discovery orchestrator → Search provider adapters: queries
- Search provider adapters → Code extractor: returns source content
- Code extractor → Verification and browser bot: passes candidate codes
- Client API boundary → Results presentation: supplies results
- Client API boundary → Progress log: supplies progress
- Results presentation → Saved and recent results: saves selections
- Authentication UI → Firebase integration: authenticates with
- Saved and recent results → Firebase integration: stores user data
- Backend entry → Session and profiles: manages
- Dashboard workspace → Results presentation: hosts
- Client API boundary → NVIDIA AI client: uses intelligence
