# ayan-choradia/positive_slope architecture

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

- Interactive diagram: https://gitdiagram.com/ayan-choradia/positive_slope
- Repository: https://github.com/ayan-choradia/positive_slope

## Overview

##### Project Type and Purpose
- Full-stack Ethereum DApp for tracking medicine authenticity.
- Frontend: Single-page application built with Vite.
- Blockchain Layer: Smart contracts deployed via Truffle on Ethereum.
- No traditional backend server; the blockchain itself is the data layer.

##### Main Components
a. Frontend (UI)
- Vite dev server / build artifact.
- HTML/CSS/JS pages (index.html, details.html, timeline.html).
- JavaScript modules (auth.js, details.js, timeline.js, main.js).
- Web3/Ethers.js integration for blockchain communication.
b. Smart Contracts
- contracts/*.sol (e.g., ProductVerification.sol, Product_Exist.sol, etc.)
- Build artifacts (build/contracts/*.json) containing ABI + deployed addresses.
c. Deployment & Development Tools
- Truffle framework: migrations (migrations/*.js), truffle-config.js.
- Tests (test/metacoin.js).
- Node/NPM (package.json, node_modules).
d. Ethereum Network
- Local test network (Ganache) or public testnet/mainnet.
e. Wallet Provider
- MetaMask or any Web3 provider for user authentication & transaction signing.

##### Relationships & Data Flow
1. Developer runs `truffle migrate` → Truffle migrations deploy smart contracts to Ethereum.
2. Frontend (in user’s browser) loads built UI and connects to a Web3 provider.
3. User actions on UI (e.g., “Submit Medicine Data”) → Web3/Ethers.js → Smart Contract function call → Transaction sent to Ethereum network.
4. Ethereum processes transaction, updates contract state. Events emitted.
5. Frontend listens to contract events or reads contract state via Web3 calls → updates UI (timeline, details).
6. Build artifacts (ABI + addresses) enable the frontend to instantiate contract wrappers.

##### Architectural Patterns & Design Principles
- Separation of Concerns: UI layer vs. blockchain (data & business logic) layer.
- Immutable Data Store: Smart contracts as the single source of truth.
- Event-driven updates: Contracts emit events to signal new data.
- Modular contract design: multiple contracts (`ProductVerification`, `Product_Exist`, etc.) for clarity.
- CI/CD hooks: Truffle tests ensure contract correctness before deployment.

##### Technologies & Frameworks
- Solidity & OpenZeppelin (standard libraries if used).
- Truffle (migrations, testing).
- Ganache or Infura (Ethereum node provider).
- Web3.js or Ethers.js for frontend/blockchain interface.
- Vite for frontend bundling.
- HTML5/CSS3/Vanilla JS.

##### Final Checklist
- All main components present (Frontend, Smart Contracts, Ethereum Network, Dev Tools).
- Labels for ABIs, migrations, tests.
- Notes on event subscriptions and on-chain state reads.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        direction TB
        UI["Frontend UI (Vite SPA)"]:::frontend
        VITE["Vite Dev Server / Build"]:::tooling
        subgraph "HTML Entry Points"
            direction TB
            INDEX["index.html"]:::frontend
            DETAILS["details.html"]:::frontend
            TIMELINE_HTML["timeline.html"]:::frontend
        end
        subgraph "CSS Styles"
            direction TB
            AUTH_CSS["auth.css"]:::frontend
            ELECT_CSS["cssforelect.css"]:::frontend
            TIMELINE_CSS["timeline.css"]:::frontend
            STYLE_CSS["style.css"]:::frontend
        end
        subgraph "JS Modules & App Logic"
            direction TB
            AUTH_JS["auth.js"]:::frontend
            DETAILS_JS["details.js"]:::frontend
            TIMELINE_JS["timeline.js"]:::frontend
            MAIN_JS["main.js"]:::frontend
            WEB3["Web3/Ethers.js"]:::frontend
        end
        subgraph "Build Config & Dependencies"
            direction TB
            VITE_CONF["vite.config.js"]:::tooling
            UI_PKG["package.json"]:::tooling
            UI_LOCK["package-lock.json"]:::tooling
        end

        UI -->|loads| INDEX
        UI --> DETAILS
        UI --> TIMELINE_HTML
        UI --> AUTH_CSS
        UI --> ELECT_CSS
        UI --> TIMELINE_CSS
        UI --> STYLE_CSS
        UI --> AUTH_JS
        UI --> DETAILS_JS
        UI --> TIMELINE_JS
        UI --> MAIN_JS
        MAIN_JS --> WEB3
        VITE --> UI
        VITE --> VITE_CONF
        VITE --> UI_PKG
        VITE --> UI_LOCK
    end

    %% Blockchain Layer
    subgraph "Blockchain Layer"
        direction TB
        CONTRACTS["contracts/*.sol"]:::blockchain
        subgraph "Build Artifacts (ABI + Addresses)"
            direction TB
            PV["ProductVerification.json"]:::blockchain
            PE["Product_Exist.json"]:::blockchain
            PEFU["Product_Exist_For_Updating.json"]:::blockchain
            PLIB["Product_Lib.json"]:::blockchain
        end
    end

    %% Tools & DevOps
    subgraph "Tooling & DevOps"
        direction TB
        TRUFFLE["Truffle Framework"]:::tooling
        MIG1["1_initial_migration.js"]:::tooling
        MIG2["2_deploy_contracts.js"]:::tooling
        TRUF_CONF["truffle-config.js"]:::tooling
        TEST["metacoin.js"]:::tooling
        ROOT_PKG["package.json"]:::tooling
        ROOT_LOCK["package-lock.json"]:::tooling
    end

    %% External Networks
    subgraph "External Networks"
        direction TB
        ETH["Ethereum Network (Ganache/Testnet/Mainnet)"]:::external
        MM["MetaMask / Wallet Provider"]:::external
    end

    %% Connections
    TRUFFLE -->|runs migrations| MIG1
    TRUFFLE --> MIG2
    MIG2 -->|deploys| CONTRACTS
    CONTRACTS --> PV
    CONTRACTS --> PE
    CONTRACTS --> PEFU
    CONTRACTS --> PLIB
    PV -->|ABI+Address| MAIN_JS
    PE -->|ABI+Address| MAIN_JS
    PEFU -->|ABI+Address| MAIN_JS
    PLIB -->|ABI+Address| MAIN_JS
    MAIN_JS -->|JSON-RPC / ABI call| ETH
    MAIN_JS -->|via Web3| MM
    MM -->|signs tx| ETH
    ETH -->|events| MAIN_JS
    ETH -->|state read| MAIN_JS

    %% Click Events
    click UI "https://github.com/ayan-choradia/positive_slope/tree/master/frontend/ui"
    click INDEX "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/index.html"
    click DETAILS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/pages/details.html"
    click TIMELINE_HTML "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/pages/timeline.html"
    click AUTH_CSS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/css/auth.css"
    click ELECT_CSS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/css/cssforelect.css"
    click TIMELINE_CSS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/css/timeline.css"
    click STYLE_CSS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/style.css"
    click AUTH_JS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/js/auth.js"
    click DETAILS_JS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/js/details.js"
    click TIMELINE_JS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/js/timeline.js"
    click MAIN_JS "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/main.js"
    click VITE_CONF "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/vite.config.js"
    click UI_PKG "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/package.json"
    click UI_LOCK "https://github.com/ayan-choradia/positive_slope/blob/master/frontend/ui/package-lock.json"
    click CONTRACTS "https://github.com/ayan-choradia/positive_slope/tree/master/contracts"
    click PV "https://github.com/ayan-choradia/positive_slope/blob/master/build/contracts/ProductVerification.json"
    click PE "https://github.com/ayan-choradia/positive_slope/blob/master/build/contracts/Product_Exist.json"
    click PEFU "https://github.com/ayan-choradia/positive_slope/blob/master/build/contracts/Product_Exist_For_Updating.json"
    click PLIB "https://github.com/ayan-choradia/positive_slope/blob/master/build/contracts/Product_Lib.json"
    click MIG1 "https://github.com/ayan-choradia/positive_slope/blob/master/migrations/1_initial_migration.js"
    click MIG2 "https://github.com/ayan-choradia/positive_slope/blob/master/migrations/2_deploy_contracts.js"
    click TRUF_CONF "https://github.com/ayan-choradia/positive_slope/blob/master/truffle-config.js"
    click TEST "https://github.com/ayan-choradia/positive_slope/blob/master/test/metacoin.js"
    click ROOT_PKG "https://github.com/ayan-choradia/positive_slope/blob/master/package.json"
    click ROOT_LOCK "https://github.com/ayan-choradia/positive_slope/blob/master/package-lock.json"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#000
    classDef blockchain fill:#E8F5E9,stroke:#2E7D32,color:#000
    classDef external fill:#ECEFF1,stroke:#455A64,color:#000
    classDef tooling fill:#FFF3E0,stroke:#EF6C00,color:#000
```
