# kevinmcfarlane/react-digit-recognizer architecture

> Architecture diagram of the GitHub repository kevinmcfarlane/react-digit-recognizer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kevinmcfarlane/react-digit-recognizer
- Repository: https://github.com/kevinmcfarlane/react-digit-recognizer

## Overview

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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Browser/Client"]:::browser
    FileInput["File Upload (CSV)"]:::input

    subgraph "React Frontend"
        ReactApp["App.tsx"]:::frontend
        UploadButton["UploadButton.tsx"]:::frontend
        EntryPoint["index.tsx"]:::frontend
        AppCss["App.css"]:::frontend
        IndexCss["index.css"]:::frontend
        AppTest["App.test.tsx"]:::frontend
        SetupTests["setupTests.ts"]:::frontend
    end

    subgraph "Rust/WebAssembly Module"
        CargoToml["Cargo.toml"]:::wasm
        LibRs["lib.rs"]:::wasm
        TrainingsCSV["Train CSV"]:::wasm
        ValidationsCSV["Validation CSV"]:::wasm
    end

    subgraph "Build & Deployment"
        PackageJson["package.json"]:::build
        PackageLock["package-lock.json"]:::build
        WasmBuild["npm run build:wasm"]:::build
    end

    Browser -->|"renders"| ReactApp
    FileInput -->|"inputs"| UploadButton
    UploadButton -->|"calls_function"| LibRs
    ReactApp -->|"interop_with"| LibRs
    LibRs -->|"returns_result"| ReactApp
    PackageJson -->|"builds_frontend"| ReactApp
    PackageJson -->|"builds_wasm"| WasmBuild
    WasmBuild -->|"triggers_compilation"| CargoToml

    click ReactApp "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/src/App.tsx"
    click UploadButton "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/src/UploadButton.tsx"
    click EntryPoint "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/src/index.tsx"
    click AppCss "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/src/App.css"
    click IndexCss "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/src/index.css"
    click AppTest "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/src/App.test.tsx"
    click SetupTests "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/src/setupTests.ts"
    
    click CargoToml "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/wasm-lib/Cargo.toml"
    click LibRs "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/wasm-lib/src/lib.rs"
    click TrainingsCSV "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/wasm-lib/trainingsample.csv"
    click ValidationsCSV "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/wasm-lib/validationsample.csv"
    
    click PackageJson "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/package.json"
    click PackageLock "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/package-lock.json"
    click WasmBuild "https://github.com/kevinmcfarlane/react-digit-recognizer/blob/master/package.json"

    classDef browser fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef frontend fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef wasm fill:#f94144,stroke:#333,stroke-width:2px;
    classDef build fill:#577590,stroke:#333,stroke-width:2px;
    classDef input fill:#f3722c,stroke:#333,stroke-width:2px;
```
