How kevinmcfarlane/react-digit-recognizer works
This project is a full-stack web application that uses a React frontend (bootstrapped via Create React App) integrated with a Rust WebAssembly library for performing a digit recognition machine learning task. The overall architecture is centered on client–side execution where the heavy lifting is done by the WebAssembly module (compiled from Rust) and the React UI provides an interactive interface.
Key architectural components include:
React Frontend
• The “src” directory contains standard React components (e.g., App.tsx, UploadButton.tsx) that handle user interactions such as uploading training and validation data sets.
• Styling (via App.css and index.css) and testing files (App.test.tsx, setupTests.ts) are standard parts of a Create React App environment.
• The index.tsx entry point bootstraps the UI in the browser.
Rust/WebAssembly Module
• Under the “wasm-lib” directory you have all Rust project files (Cargo.toml, lib.rs, etc.) that implement the machine learning logic for digit recognition.
• The Rust code is compiled into WebAssembly—integrated with the frontend through tooling such as wasm-bindgen.
• The provided CSV sample files (trainingsample.csv and validationsample.csv) suggest that this module uses real dataset examples to test or train the model.
Communication Flow
• The React UI is responsible for gathering input files from the user and then, through JavaScript interop, calling exported functions from the WebAssembly module.
• Once the machine learning prediction is computed by the Rust code, the result (typically a percentage of correctly predicted digits) is passed back to the UI, where it is displayed to the user.
Build & Deployment
• Standard npm scripts (e.g., “npm start”) are used for development.
• A custom script (“npm run build:wasm”) handles building and packaging the Rust WebAssembly component—indicating a deliberate separation of concerns between UI building and WASM compilation.
a. Main components:
• Browser / Client: Represented as the execution environment for the React app.
• React UI Layer: Contains components (App, UploadButton, etc.) and associated assets (CSS, tests).
• WebAssembly Module: The Rust digit recognizer compiled to wasm, which exposes its functions.
• Data Inputs: Include file uploads (training and validation CSV datasets) that feed into the system.
• (Optional) Build Tooling: A representation of the npm and cargo build processes that produce the final artifacts.
b. Relationships and interactions:
c. Architectural patterns or principles:
• Separation of concerns: the UI handles presentation/input, while performance-critical logic is isolated in the WebAssembly module.
• The integration pattern of using web standard technologies (React for UI, WebAssembly for native performance) is an important design principle.
d. Relevant technologies:
• React, TypeScript, Create React App.
• Rust, Cargo, and WebAssembly (likely using wasm-bindgen to connect the Rust code with JavaScript).
• For a full-stack application such as this one, emphasize the boundaries between the browser UI, the business logic in Rust (compiled as WebAssembly), and the build/deployment pipeline.
This level of detail will assist in accurately representing the system’s architecture, making it clear how each component interacts and what responsibilities each part holds in delivering the digit recognition functionality.