Cloudflare Static Deployment
Relevant source files
The following files were used as context for generating this wiki page:
Cloudflare Static Deployment serves the Nexus Scanner frontend and its immutable data releases using Cloudflare Pages and R2 storage. The system builds a React-based research application and integrates it with a content-addressed data architecture generated by a Python-based Extraction, Delivery, and Loading (EDL) pipeline. Sources: frontend/README.md:1-10, frontend/README.md:465-470
The deployment utilizes a root wrangler.jsonc configuration to build and serve the static frontend for production environments and Pull Request (PR) previews. While the frontend logic runs in the browser, advanced historical queries depend on a separate, externally hosted Python backend. Sources: frontend/README.md:465-475
Architecture and Data Flow
The static deployment separates application logic from the underlying data snapshots. The frontend acts as a consumer of immutable JSON artifacts produced by the publish_snapshot.py script. Sources: frontend/publish_snapshot.py:1-10, frontend/README.md:210-215
Deployment Components
- Cloudflare Pages: Hosts the React 19 / Vite 8 frontend bundle. Sources: frontend/README.md:465-470, frontend/package.json:20-35
- Cloudflare R2: Stores immutable chart objects, historical candles, and archived releases. Sources: frontend/chart_publication.py:115-130, frontend/README.md:245-250
- Python EDL Pipeline: Runs periodically to generate the data snapshots and upload them to the static origin. Sources: DO NOT DELETE EDL PIPELINE/README.md:25-30, frontend/publish_snapshot.py:100-110
Logic Flow for Release Publication
The following diagram illustrates the process of promoting a new data release to the static deployment:
Immutable Data Structure
Data is deployed using a content-addressed directory structure. This ensures that browsers can cache artifacts indefinitely and that different scanner versions do not conflict. Sources: frontend/README.md:225-235, frontend/chart_publication.py:210-220
Directory Layout
| Path | Purpose | Format |
|---|---|---|
/data/current.json | Active-release pointer (published last) | JSON |
/data/revisions/<hash>/stocks.json.gz | Mainboard stocks snapshot | Gzip JSON |
/data/revisions/<hash>/ipos.json.gz | IPO catalogue for the release | Gzip JSON |
/data/objects/<hash>.json.gz | Content-addressed chart/event objects | Gzip JSON |
/data/revisions/<hash>/release.json | Revision metadata and URL templates | JSON |
Sources: frontend/README.md:230-245, frontend/publish_snapshot.py:140-150, frontend/chart_publication.py:230-245
Deployment Configuration
Cloudflare deployment requires specific environment variables and build-time settings to link the static frontend to its data sources and optional backend. Sources: frontend/README.md:445-455
Environment Variables
VITE_API_BASE_URL: Defines the base path for the historical evaluation service. The frontend appends/screens/runto this base. Sources: frontend/README.md:450-455, frontend/README.md:470-475EDL_CHART_STORAGE: Set tor2to enable remote object storage; otherwise defaults tolocal. Sources: frontend/chart_publication.py:25-30R2_PUBLIC_BASE_URL: The HTTPS URL used by the browser to fetch chart objects from Cloudflare R2. Sources: frontend/chart_publication.py:135-140
Build and Deployment Procedure
- Build Frontend: Run
npm run buildto generate thedist/directory. Sources: frontend/README.md:95-100 - Stage Data: The pipeline produces validated artifacts in
frontend/public/data/revisions/. Sources: frontend/README.md:225-230 - R2 Synchronization:
rclonesynchronizes local chart objects to the R2 bucket using theR2_ACCESS_KEY_IDandR2_SECRET_ACCESS_KEY. Sources: frontend/chart_publication.py:145-165 - Promote Pointer: The pipeline updates
current.jsonto point to the new revision hash. Sources: frontend/publish_snapshot.py:155-160
Limitations of Static Deployment
The Cloudflare Pages deployment is primarily static and does not execute Python code on the edge. Sources: frontend/README.md:105-110
- Browser-Based Evaluation: Only conditions supported by the Web Worker engine function without an external service. Sources: frontend/README.md:275-285
- External API Requirement: Expressions requiring historical lookbacks (e.g., specific year-over-year fundamental growth) must be proxied to a separate Python backend. Sources: frontend/README.md:480-485
- SPA Fallback: The deployment uses Single Page Application (SPA) fallback to support deep links, but this does not provide dynamic API endpoints. Sources: frontend/README.md:475-480
Sources: frontend/README.md:465-485, frontend/publish_snapshot.py:155-165
Cloudflare Static Deployment provides a scalable, cache-efficient hosting model for Nexus Scanner by separating application delivery from the data pipeline. While the core screener functions as a static site, it relies on strict immutable naming conventions and revision-pinned metadata to maintain data integrity across releases. Sources: frontend/README.md:265-275, frontend/chart_publication.py:195-205