How asofiorg/agroscan works
Main Components
• AI/Machine Learning Component
– The “ai” directory holds the code (dataset.ts, index.ts, test.ts) and also stores the training and testing data (organized into subfolders for “fito”, “healthy”, “monilia”, “pod_borer”). This is where image data is managed and the AI model is built or tested.
– The ML model artifacts appear in the “docs/cocoa-disease” and “public/cocoa-disease” directories (with files such as model.json, weights.bin, metadata.json). These indicate that the model is constructed elsewhere (perhaps by the “ai” module) and then exported for in-browser inference.
• Frontend / Static Website Component
– The “src” and “docs” directories hold various HTML, CSS, and JavaScript files, including PWA elements (like sw.js) and manifest files. They offer the user interface for the scanning functionality.
– The “public” directory duplicates some website assets (and the cocoa-disease model components) indicating that static assets are organized for deployment.
• Build and Deployment Component
– The “build.ts” script (executed with Bun via “bun run build.ts”) orchestrates the build process that generates the “dist” folder, which is then exposed as the static website.
– GitHub Pages is used for static website hosting.
Relationships and Data Flow
• The AI module gathers training and test data from its subdirectories. It builds (or tests) a model whose artifacts are then saved into the deployment directories.
• The build process (triggered by build.ts) packages all needed frontend static files (from src/docs/public) along with the model artifacts into the “dist” folder.
• When a user accesses the site (via GitHub Pages), the browser downloads the static assets. The JavaScript (e.g., tf.js, scan.js) then loads the ML model and performs inference on images (or data) provided by the user.
Architectural Patterns and Technologies
• Separation of Concerns: There is a clear distinction between the AI model development (in the “ai” folder) and the presentation layer (in “src”, “docs”, “public”).
• Static Site Generation: The build script assembles all parts for deployment as a static site, making use of modern tools (Bun) and static hosting (GitHub Pages).
• Client-Side Inference: The model artifacts (model.json, weights.bin) along with TensorFlow.js (tf.js) indicate that inference is performed in the browser.