Skip to content

Developer Guide

Golam Kuadir Khan Prince edited this page Nov 19, 2026 · 1 revision

Developer Guide

This guide provides technical specifications, architecture diagrams, build instructions, and release workflows for contributors and maintainers of the Electron Scattering Simulator.


Architecture and Repository Layout

The application combines a modern client-side React 19 interface with compiled Fortran 90 physics engines:

                    ┌─────────────────────────────────────────┐
                    │ React 19 + Vite Frontend (Browser / PWA)│
                    │         fetch('/api/simulate')          │
                    └───────────────────┬─────────────────────┘
                                        │
                         src/utils/localApiFallback.ts
                    (intercepts /api/* requests made by app)
                                        │
           backend with ELSEPA binary?  │
             ┌─────────── YES ──────────┴────────── NO ────────────┐
             ▼                                                     ▼
 ┌──────────────────────────────┐     HTTP 5xx      ┌──────────────────────────────────┐
 │ Optional Express Server :3000│ ────────────────► │ ELSEPA WebAssembly (f2c + emcc)  │
 │ server.ts + fortranRunner.ts │                    │ Isolated Web Worker in browser   │
 │ Native gfortran ELSEPA       │                    │ public/elsepa/elsepa.{js,wasm}   │
 └──────────────────────────────┘                    └──────────────────────────────────┘

 "TS Approximation" (Header toggle, opt-in): Simplified TypeScript model for qualitative demos

Directory Structure

├── .github/workflows/
│   ├── ci.yml                 # Lint, build (Node 20/22), Docker, path-filter gate
│   ├── elsepa-parity.yml      # Parity, feature, output, server, and browser tests
│   ├── pages.yml              # Publishes project site to gh-pages branch
│   └── release.yml            # Release packaging and GHCR container publishing
├── data/                      # ELSEPA atomic data tables (z_NNN.den, z_NNN.dfs)
├── docs/                      # Technical documentation and publication figures
├── fortran/                   # Official ELSEPA 2021 Fortran 90 sources (CC BY-NC 3.0)
│   ├── elscata.f              #   ELSCATA atomic scattering driver
│   ├── elscatm.f              #   ELSCATM molecular scattering driver
│   ├── elsepa2020.f           #   Core Dirac partial-wave scattering subroutines
│   ├── radial.f               #   RADIAL radial wave equation package
│   ├── readme.txt             #   Upstream release notes
│   └── ELSEPA-LICENSE.txt     #   CC BY-NC 3.0 license and attribution terms
├── public/
│   ├── elsepa/                # Compiled WebAssembly: elsepa.js, elsepa.wasm, elsepa.data
│   ├── manifest.json          # PWA Web App Manifest
│   └── sw.js                  # Service Worker for offline caching
├── server/
│   └── fortranRunner.ts       # Native gfortran execution & temporary run isolation
├── server.ts                  # Optional Express API server (port 3000)
├── src/
│   ├── components/            # React UI components (Workbench, Editor, Plots)
│   ├── physics/               # Input deck builder, output parser, grid generators
│   └── utils/                 # /api/ routing interceptor, dataset parser, storage
├── validations/               # Canonical reference ELSEPA output tables
└── wasm/                      # WebAssembly build pipeline, patch script, and tests

The Build-Time ELSEPA Patch (wasm/patch-elsepa.mjs)

To comply with the Creative Commons Attribution-NonCommercial 3.0 Unported License (CC BY-NC 3.0 Section 4(b)) and maintain reproducibility:

Core Rule: The files in fortran/ are the original, official upstream distribution. Never edit files in fortran/ directly.

All modifications, overrides, and enhancements are applied programmatically at build time using wasm/patch-elsepa.mjs onto temporary working copies before compilation:

  1. Atomic Weight Override (ATWGHT):
    • Introduces keyword ATWGHT in elscata.f to override standard atomic weights (in g/mol), modifying nuclear radius evaluations.
  2. Nuclear Radius and Skin Overrides (NUCRAD, NUCSKN):
    • Introduces keywords NUCRAD ($R_1$, fm) and NUCSKN ($R_2$, fm) across the Fermi, Uniform, and Helm nuclear charge distribution models.
  3. Negative Ion Support (Anions):
    • Removes STOP 'Negative ion.' statements from elscata.f and elsepa2020.f (subroutine EFIELD), enabling simulations for targets where $\text{NELEC} > Z$ ($q < 0$).
  4. Polarization Cutoff Mapping (VPOLB):
    • Maps user-specified cutoff radius $r_c$ to ELSEPA's internal cutoff parameter: $$b_{pol} = r_c^2 \sqrt{\frac{2 Z^{1/3}}{\alpha}}$$

Unmodified input decks retain identical defaults and produce bit-for-bit identical outputs to upstream ELSEPA 2021.


Rebuilding the WebAssembly Binaries

The compiled WebAssembly binaries are committed in public/elsepa/. You only need to rebuild them if the Fortran sources, patch scripts, or compilation flags are modified.

Toolchain Requirements

  • EMSDK: Activated Emscripten SDK (emscripten.org).
  • F2C: Netlib f2c source tree containing src/ and libf2c/ (netlib.org/f2c).
  • Python 3: For syntax adaptation scripts.

Build Pipeline (wasm/build.sh)

The build pipeline executes the following stages:

  1. Compiles the f2c translator to a Node executable (wasm/build/f2c.cjs).
  2. Compiles libf2c runtime sources to WebAssembly objects using emcc and archives them into libf2c.a.
  3. Invokes node wasm/patch-elsepa.mjs to prepare patched Fortran 90 sources in wasm/build/patched/.
  4. Runs wasm/f90to77.py to translate Fortran 90 constructs into strict Fortran 77 (converts MODULE CONSTANTS into an INCLUDE 'constants.inc').
  5. Runs wasm/f77fix.py to reorder non-executable DATA statements before executable code.
  6. Translates Fortran 77 to C using f2c with prototype analysis (.P files).
  7. Compiles the C translation and packages data/ atomic tables into public/elsepa/elsepa.{js,wasm,data}.
# Execute build from repository root:
EMSDK=/path/to/emsdk F2C_DIR=/path/to/netlib-f2c bash wasm/build.sh

Testing Commands

All test scripts are located in wasm/ and run using npx tsx:

# Static type checking
npm run lint

# Production bundle verification
npm run build

# Unit and feature tests (custom grids, density parsing)
npx tsx wasm/features.test.ts

# Electron density editor numerical tests
npx tsx wasm/density.test.ts

# Nuclear parameter overrides and ion tests
npx tsx wasm/overrides.test.ts

# Output parser completeness
npx tsx wasm/outputs.test.ts

# Server engine execution and security checks
npx tsx wasm/server.test.ts

# Browser-only CDP integration and offline service worker test
npx tsx wasm/browser.test.ts

# Parity test (WebAssembly vs validations/ tables)
npx tsx wasm/parity.test.ts

Continuous Integration and Delivery (CI/CD)

The repository uses four coordinated GitHub Actions workflows in .github/workflows/:

  1. ci.yml:
    • Runs on every pull request and push to main.
    • Executes npm run lint and npm run build across Node.js 20 and 22.
    • Compiles the Dockerfile using buildx.
    • Uses dorny/paths-filter to detect changes to engine-related files (fortran/, data/, wasm/, server/, src/physics/).
    • Calls elsepa-parity.yml when engine files change.
    • Enforces the single required branch protection check: CI result.
  2. elsepa-parity.yml:
    • Installs gfortran, compiles native binaries, and executes all test suites.
    • Runs wasm/benchmark.ts and wasm/browser.test.ts, attaching results to the GitHub Step Summary.
    • Includes the manual references job (triggered only via workflow_dispatch) to regenerate canonical tables in validations/.
  3. pages.yml:
    • Deploys the project presentation website (site/) and figures to the orphan gh-pages branch, served at https://the-studio-of-sadiq.github.io/Electron-Scattering/.
  4. release.yml:
    • Automatically triggered when a GitHub release is published.
    • Verifies that the release tag matches the version in package.json.
    • Builds the static web bundle, packages it with LICENSE and fortran/ELSEPA-LICENSE.txt, and attaches electron-scattering-X.X.X-web.zip to the release.
    • Builds and publishes the multi-architecture Docker container image to the GitHub Container Registry (ghcr.io/the-studio-of-sadiq/electron-scattering).

Release Process

To create a new official release:

  1. Update Version: Bump the version field in package.json (e.g., 2.0.0).
  2. Update Changelog: Document all additions, modifications, and fixes under the new release header in CHANGELOG.md.
  3. Update Citation Metadata: Update version and date-released in CITATION.cff.
  4. Commit and Merge: Commit changes, open a pull request, verify that the CI result check passes, and merge to main.
  5. Publish GitHub Release:
    • Create a new release in GitHub.
    • Set the release tag exactly equal to the version string (e.g., 2.0.0 or v2.0.0).
    • Publish the release.
  6. Automated Archiving & Artifacts:
    • Zenodo automatically detects the GitHub release and assigns a permanent DOI according to .zenodo.json.
    • The release.yml workflow runs automatically to attach the static zip bundle to the release and publish the Docker image to GHCR.

Clone this wiki locally