# faithmutua-code/agri-verify-gmo-website architecture

> Architecture diagram of the GitHub repository faithmutua-code/agri-verify-gmo-website, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/faithmutua-code/agri-verify-gmo-website
- Repository: https://github.com/faithmutua-code/agri-verify-gmo-website

## Overview

##### Project Type & Purpose
- AgriVerify is a monolithic, full-stack Django web application.
- Purpose: Provide GMO product verification (QR scanning, code entry, image upload), AI chatbot for queries, USSD access, educational content, and quizzes.
- Key indicators:
- Django “gmo” project folder + “base” app
- Templates under base/templates
- Staticfiles collected under “staticfiles”
- mqtt.py for USSD/MQTT integration
- server.py entry point for USSD sandbox

##### File Structure
- Top-level directories:
- gmo/ – Django project config (settings, URLs, wsgi/asgi)
- base/ – Core Django app (models, views, URLs, templates, migrations)
- staticfiles/ – Collected CSS/JS assets for admin & UI themes
- media/ – Uploaded assets (product images, QR codes, videos, resources)
- Other files:
- manage.py – Django CLI entry
- mqtt.py – USSD gateway integration via MQTT
- server.py – USSD sandbox server
- db.sqlite3 – Primary datastore
- Pipfile/requirements.txt – Dependencies

##### Extract Insights from README
- Frontend: HTML5, Tailwind CSS, JavaScript
- Backend: Django + Python
- Database: SQLite
- Features & external integrations:
- AI Chatbot (likely external ML/AI API)
- USSD Access (via MQTT broker)
- QR code generator & scanner (internal or third-party lib)
- Media/video streaming

##### Main Components
- Presentation Layer:
- Web Browser / Mobile Browser
- Static Assets (CSS/JS) served from Django staticfiles
- Application Layer:
- Django Web Server (Django app + Gunicorn/uWSGI)
- REST/API Endpoints (views in base/views.py)
- USSD Server (server.py)
- MQTT Client (mqtt.py)
- Data Layer:
- SQLite Database
- File Storage (media/ directory)
- External Services:
- AI Chatbot API (e.g., OpenAI or custom ML service)
- USSD Gateway / MQTT Broker
- Optional: Email/SMS service (if implemented for notifications)

##### Relationships & Data Flow
- Browser → Django Web Server
- Requests for pages (login, dashboard, product detail, quiz)
- AJAX calls to verification endpoints
- Django Web Server ↔ SQLite
- ORM queries for users, products, chat messages, quiz results
- Django Web Server → File Storage
- Upload/retrieve images, videos, QR code assets
- Django Web Server ↔ External AI Service
- Forward user questions, receive chatbot responses
- USSD Server ↔ MQTT Broker
- Publish/subscribe messages to provide USSD menu interactions
- Staticfile Server (Django or CDN) → Browser
- Delivers CSS/JS assets

##### Architectural Patterns & Design Principles
- MVC (Model-View-Template) inherent in Django
- Layered architecture separating presentation, application logic, data
- Event-driven USSD via MQTT (pub/sub)
- Use of media directory as simple object store

##### Detail Is Key
- Django apps/routes (e.g., /login, /quiz, /product-verify).
- Staticfiles host (could be same server or CDN).
- Separate media store folder.
- Call out the mqtt.py script as the bridge between the USSD sandbox and Django backend.
- That server.py runs the USSD sandbox locally.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Web/Mobile Browser"]:::presentation
        USSDClient["USSD Client"]:::presentation
        StaticAssets["Static Assets"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        DjangoServer["Django Web Server (Gunicorn/uWSGI)"]:::application
        Serverpy["USSD Sandbox Server (server.py)"]:::application
        MQTTpy["MQTT Client Bridge (mqtt.py)"]:::application
        ProjectConfig["gmo/ (Django Config)"]:::application
        CoreApp["base/ (Core Django App)"]:::application
        Templates["base/templates/"]:::presentation
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        SQLiteDB["SQLite Database (db.sqlite3)"]:::data
        MediaStore["Media Storage (media/)"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        AIService["AI Chatbot API"]:::external
        MQTTBroker["MQTT Broker / USSD Gateway"]:::external
        EmailSMS["Email/SMS Service"]:::external
    end

    %% Connections
    Browser -->|"HTTP/HTTPS"| DjangoServer
    Browser -->|"GET CSS/JS"| StaticAssets
    StaticAssets -->|"Served via Django or CDN"| Browser

    USSDClient -->|"USSD Menu"| Serverpy
    Serverpy -->|"MQTT publish/subscribe"| MQTTBroker
    MQTTBroker -->|"MQTT messages"| MQTTpy
    MQTTpy -->|"Invoke Django endpoints"| DjangoServer

    DjangoServer -->|"ORM SQL queries"| SQLiteDB
    DjangoServer -->|"Read/Write"| MediaStore
    DjangoServer -->|"API calls"| AIService
    DjangoServer -->|"SMTP/API"| EmailSMS

    manage[/"manage.py CLI"/]:::application -->|"Django Commands"| DjangoServer

    %% Click Events
    click ProjectConfig "https://github.com/faithmutua-code/agri-verify-gmo-website/tree/main/gmo/"
    click CoreApp "https://github.com/faithmutua-code/agri-verify-gmo-website/tree/main/base/"
    click Templates "https://github.com/faithmutua-code/agri-verify-gmo-website/tree/main/base/templates/"
    click StaticAssets "https://github.com/faithmutua-code/agri-verify-gmo-website/tree/main/staticfiles/"
    click MediaStore "https://github.com/faithmutua-code/agri-verify-gmo-website/tree/main/media/"
    click Serverpy "https://github.com/faithmutua-code/agri-verify-gmo-website/blob/main/server.py"
    click MQTTpy "https://github.com/faithmutua-code/agri-verify-gmo-website/blob/main/mqtt.py"
    click manage "https://github.com/faithmutua-code/agri-verify-gmo-website/blob/main/manage.py"
    click SQLiteDB "https://github.com/faithmutua-code/agri-verify-gmo-website/blob/main/db.sqlite3"
    click Pipfile "https://github.com/faithmutua-code/agri-verify-gmo-website/tree/main/Pipfile"
    click requirements "https://github.com/faithmutua-code/agri-verify-gmo-website/blob/main/requirements.txt"
    click venv "https://github.com/faithmutua-code/agri-verify-gmo-website/tree/main/.venv/"

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#21618C,stroke-width:2px
    classDef application fill:#A9DFBF,stroke:#196F3D,stroke-width:2px
    classDef data fill:#F9E79F,stroke:#B9770E,stroke-width:2px
    classDef external fill:#D5D8DC,stroke:#707B7C,stroke-width:2px
```
