How brweinstein/corsa works
Project type and purpose
• This is an educational, client-side web application—a full-stack project in the sense that it includes a Rust/WASM “backend” core and a Next.js/React “frontend” UI.
File structure
Top level:
• rust/ – Cargo project with src/lib.rs, src/number_theory.rs, src/rsa.rs, src/util.rs
• web/ – Next.js app (App Router) with React components, styles, tests, plus build configs (package.json, next.config.js, tailwind.config.ts)
• README.md, LICENSE, .gitignore
Observations:
• rust/ is purely computational logic. It’s packaged to WebAssembly via wasm-bindgen (build script in web/package.json).
• web/ contains:
– src/app: Next.js entry points (layout.tsx, page.tsx, head.tsx)
– src/components and nested panels for visualizations and controls
– src/lib: small wrappers for WASM calls (wasm.ts) and helper functions (num.ts)
– public/pkg (not shown) holds the compiled WASM artifacts
• Tests are split: cargo test for Rust, Vitest/RTL for the web.
README for additional insights
• Tech stack is explicitly called out: Rust→WASM, Next.js/React/TS, Tailwind, Vitest.
• Build instructions: wasm-pack build step, then npm install and npm run dev.
• No external database or API services—everything runs in the browser.
Main components and relationships
a. Rust core (Cargo project)
– Exposes number_theory and RSA functions via wasm-bindgen
– Output: .wasm binary + JS glue in web/public/pkg
b. Web application (Next.js)
– Server‐side: Node.js/Next.js build and static generation (app router)
– Client‐side: React components that import the WASM module and call into the Rust logic
c. UI components
– Panels (PrimesPanel, EncryptDecryptPanel, VisualizersPanel, etc.)
– Visualizers (CircleVisualizer, TwoLineVisualizer) render SVG/canvas
– StepController and Panel orchestrate user inputs and render cycles
d. Build pipeline
– wasm-pack (Cargo → WASM)
– npm scripts (bundle JS/TSX, integrate WASM, run dev server)
e. Developer environment
– Local dev machine runs both Cargo and Node toolchains
– Tests: Rust testing vs. Vitest/RTL
Architectural patterns and design principles
• Separation of concerns:
• Number theory & RSA logic entirely in Rust (strongly typed, tested in cargo).
• UI and rendering in Next.js/React (type-safe TSX, CSS modules/Tailwind).
• Module boundaries: WASM as a library boundary between compute and presentation.
• Progressive enhancement: fallback JS stub if WASM package missing.
• Componentized UI: each panel/visualizer is isolated, reusable.