# jaydalal12/blockchain-indexer architecture

> Architecture diagram of the GitHub repository jaydalal12/blockchain-indexer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jaydalal12/blockchain-indexer
- Repository: https://github.com/jaydalal12/blockchain-indexer

## Overview

##### Project Type and Purpose
- This is a full-stack web application (“Blockchain Indexing Dashboard”) composed of:
- A React-based SPA in the `client/` folder
- A Node.js + Express backend in the `server/` folder
- A PostgreSQL database for persistence
- Integration with the external Helius webhook API to index blockchain transactions
- Purpose: Allow users to configure transaction categories and address filters, create webhooks on Helius, persist incoming events to Postgres, and display them in a live dashboard.

##### File Structure
- client/
- Typical Create-React-App structure (`public/`, `src/`, `.env`)
- `src/App.js`, routes, API calls via Axios to the backend (base URL from REACT_APP_SERVER_BASE_URL)
- server/
- `index.js` boots Express, configures middleware (dotenv, CORS, JSON, JWT auth)
- `routes/` defines REST endpoints (`auth.js`, `indexing.js`) and a webhook receiver (`/webhook`)
- `services/helius.js` encapsulates calls to Helius API (create/delete webhook)
- `schema.sql` defines `users` and `webhook_data` tables
- tests/
- Basic unit tests (e.g., `indexing.test.js`) for backend logic

##### README for Insights
- Stack: React, Express, PostgreSQL, JWT, Axios
- Key flows:
- Auth (register/login) → JWT issuance → protected routes
- Indexing config → create/delete Helius webhook → store `webhook_id`
- Webhook events → POST `/webhook` → server persists JSONB payload to `webhook_data`
- Frontend polling/manual refresh → GET `/api/webhook-data` → render table

##### Main Components & Their Interactions
a. Frontend (React SPA)
- UI for auth, config, dashboard
- Axios REST calls to Backend
- Uses React Router, react-select, react-toastify
b. Backend (Express API)
- Auth endpoints (`/register`, `/login`) → JWT
- Indexing endpoints (`/start-indexing`, `/stop-indexing`, `/data`)
- Webhook endpoint (`/webhook`) exposed to Helius
- Service layer (`services/helius.js`) handles external HTTP calls
- Database access via `pg`
c. PostgreSQL Database
- Stores user credentials, Postgres connection details, `webhook_id`
- Persists incoming `webhook_data` JSONB with timestamp
d. External Services
- Helius Webhook API (creates & delivers blockchain transaction events)
- Optional ngrok for local tunneling of webhook endpoint

Relationships & Data Flows:
1. User browser → (HTTPS) → React SPA
2. React SPA → (REST + JWT) → Express API
3. Express API ↔ (SQL) ↔ PostgreSQL DB
4. Express API → (HTTPS) → Helius API (create/delete webhooks)
5. Helius → (Webhook POST) → Express `/webhook` endpoint → DB write
6. React polling/refresh → Express → fetch persisted data → display

##### Architectural Patterns & Principles
- Layered Architecture:
- Presentation (React)
- API / Business Logic (Express Routes + Services)
- Data Access (PostgreSQL)
- Separation of Concerns: Services folder isolates external API logic
- Stateless Auth: JWT tokens for session management
- Configurable Extensibility: Environment-driven base URLs, pluggable webhook filters

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Swimlanes simulated via subgraphs stacked vertically
    subgraph "Client Layer" 
        direction TB
        Browser["Browser / User"]:::actor
        ReactSPA["React SPA"]:::frontend
        subgraph "React Components"
            direction TB
            AuthUI["Auth UI"]:::frontend
            ConfigUI["Config UI"]:::frontend
            DashboardUI["Dashboard UI"]:::frontend
        end
        Browser -->|"UI Interaction"| ReactSPA
        ReactSPA -->|"renders components"| AuthUI
        ReactSPA -->|"renders components"| ConfigUI
        ReactSPA -->|"renders components"| DashboardUI
    end

    subgraph "API Server Layer"
        direction TB
        ExpressApp["Express API Server"]:::backend
        subgraph "Routes"
            direction TB
            AuthRoutes["Auth Routes (/register, /login)"]:::backend
            IndexingRoutes["Indexing & Webhook Routes"]:::backend
        end
        subgraph "Services"
            direction TB
            HeliusService["Helius Service"]:::backend
        end
        ExpressApp -->|"/register, /login"| AuthRoutes
        ExpressApp -->|"/start-indexing, /stop-indexing, /data, /webhook"| IndexingRoutes
        ExpressApp -->|uses| HeliusService
    end

    subgraph "Database Layer"
        direction TB
        Postgres["PostgreSQL"]:::database
        UsersTable["users"]:::database
        WebhookDataTable["webhook_data"]:::database
        Postgres --> UsersTable
        Postgres --> WebhookDataTable
    end

    subgraph "External Services"
        direction TB
        HeliusAPI["Helius Webhook API"]:::external
        Ngrok["ngrok (dev only)"]:::external
    end

    %% Data Flows
    AuthUI -->|"POST /register, /login"| AuthRoutes
    AuthRoutes -->|"issue JWT"| ReactSPA
    ConfigUI -->|"POST /start-indexing"| IndexingRoutes
    IndexingRoutes -->|"SQL INSERT webhook_id"| Postgres
    IndexingRoutes -->|"HTTP POST create/delete webhook"| HeliusService
    HeliusService -->|"HTTPS"| HeliusAPI
    HeliusAPI -->|"Webhook POST /webhook"| IndexingRoutes
    IndexingRoutes -->|"SQL INSERT JSONB payload"| Postgres
    DashboardUI -->|"GET /api/webhook-data (JWT)"| IndexingRoutes
    IndexingRoutes -->|"SQL SELECT webhook_data"| DashboardUI
    Browser -->|"/webhook via ngrok"| Ngrok
    Ngrok -->|"/webhook endpoint"| IndexingRoutes

    %% Click Events
    click ReactSPA "https://github.com/jaydalal12/blockchain-indexer/tree/main/client/"
    click AuthUI "https://github.com/jaydalal12/blockchain-indexer/blob/main/client/src/App.js"
    click ConfigUI "https://github.com/jaydalal12/blockchain-indexer/blob/main/client/src/App.js"
    click DashboardUI "https://github.com/jaydalal12/blockchain-indexer/blob/main/client/src/App.js"
    click Browser "https://github.com/jaydalal12/blockchain-indexer/blob/main/client/public/index.html"
    click ReactSPA "https://github.com/jaydalal12/blockchain-indexer/blob/main/client/.env"
    click ExpressApp "https://github.com/jaydalal12/blockchain-indexer/blob/main/server/index.js"
    click AuthRoutes "https://github.com/jaydalal12/blockchain-indexer/blob/main/server/routes/auth.js"
    click IndexingRoutes "https://github.com/jaydalal12/blockchain-indexer/blob/main/server/routes/indexing.js"
    click HeliusService "https://github.com/jaydalal12/blockchain-indexer/blob/main/server/services/helius.js"
    click Postgres "https://github.com/jaydalal12/blockchain-indexer/blob/main/server/schema.sql"
    click Postgres "https://github.com/jaydalal12/blockchain-indexer/blob/main/server/.env"
    click WebhookDataTable "https://github.com/jaydalal12/blockchain-indexer/blob/main/tests/indexing.test.js"

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#3399ff,color:#000
    classDef backend fill:#d4edda,stroke:#28a745,color:#000
    classDef database fill:#fff3cd,stroke:#ffcc00,color:#000
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#000
    classDef actor fill:#f8d7da,stroke:#dc3545,color:#000
```
