# asofiorg/agroscan architecture

> Architecture diagram of the GitHub repository asofiorg/agroscan, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/asofiorg/agroscan
- Repository: https://github.com/asofiorg/agroscan

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TD
    User["User"]

    subgraph "AI/ML Pipeline"
        ai["AI Data Collection & Training"]:::aiProcess
        ma_docs["Model Artifacts (docs)"]:::aiProcess
        ma_public["Model Artifacts (public)"]:::aiProcess
        ma_merge["Consolidated Model Artifacts"]:::aiProcess
    end

    subgraph "Build & Deployment"
        bp["Build Process (build.ts)"]:::buildComp
        docsAssets["Docs Assets"]:::buildComp
        srcAssets["Src Assets"]:::buildComp
        pubAssets["Public Assets"]:::buildComp
        ssa["Static Website Assets"]:::buildComp
    end

    subgraph "Frontend"
        fs["Static Website"]:::frontend
        ibm["In-Browser Inference (tf.js)"]:::frontend
    end

    %% AI/ML Pipeline Flow
    ai -->|"Train"| ma_docs
    ai -->|"Train"| ma_public
    ma_docs --> ma_merge
    ma_public --> ma_merge
    ma_merge -->|"ExportModel"| ssa

    %% Build & Deployment Flow
    bp -->|"Assemble"| ssa
    docsAssets --> ssa
    srcAssets --> ssa
    pubAssets --> ssa

    %% Frontend Flow
    ssa -->|"DeployAssets"| fs
    fs -->|"LoadModel"| ibm

    %% User Interactions
    User -->|"Access"| fs
    ibm -->|"Display"| User

    %% Click Events for AI/Machine Learning Component
    click ai "https://github.com/asofiorg/agroscan/blob/main/ai/index.ts"
    click ai "https://github.com/asofiorg/agroscan/blob/main/ai/dataset.ts"
    click ai "https://github.com/asofiorg/agroscan/blob/main/ai/test.ts"

    %% Click Events for ML Model Artifacts
    click ma_docs "https://github.com/asofiorg/agroscan/tree/main/docs/cocoa-disease/"
    click ma_public "https://github.com/asofiorg/agroscan/tree/main/public/cocoa-disease/"

    %% Click Events for Build and Deployment Component
    click bp "https://github.com/asofiorg/agroscan/blob/main/build.ts"
    click docsAssets "https://github.com/asofiorg/agroscan/tree/main/docs/"
    click srcAssets "https://github.com/asofiorg/agroscan/tree/main/src/"
    click pubAssets "https://github.com/asofiorg/agroscan/tree/main/public/"

classDef aiProcess fill:#ADD8E6,stroke:#000,stroke-width:2px;
classDef buildComp fill:#90EE90,stroke:#000,stroke-width:2px;
classDef frontend fill:#FFF799,stroke:#000,stroke-width:2px;
```
