# oafnglmh/agrivision-tomato architecture

> Architecture diagram of the GitHub repository oafnglmh/agrivision-tomato, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oafnglmh/agrivision-tomato
- Repository: https://github.com/oafnglmh/agrivision-tomato

## Overview

1. **Repository shape**
   - The repo is a two-part product: a **Flutter client** in `hohotree_ui/` and a **Django backend** in `hohotree_be/`.
   - The backend appears in two near-duplicate layouts: `hohotree_be/hohotree_be/` and `hohotree_be/src/`. The README treats `src/` as the canonical Django app tree, so diagrammatically you can model this as **one backend service** with a duplicated source layout/package wrapper.

2. **Frontend boundary**
   - `hohotree_ui/` is a cross-platform Flutter app targeting **Android, iOS, web, Windows, macOS, and Linux**.
   - It is organized around feature screens (`Home`, `Login`, `Register`, `Profile`, `MyPlants`, `PlantIssues`, `Guide`, `Post`, `ChatBot`, `Admin`) and service classes under `lib/Services/` that call backend APIs.

3. **Client-side data access layer**
   - The Flutter app uses a small API/data layer:
     - `common/constants/endpoints.dart` and `env_key.dart` define API and environment constants.
     - `common/util/dio.dart` suggests a shared HTTP client.
     - `data/dtos/` and `data/models/` define typed request/response payloads for auth, chat, users, and base responses.
   - This makes the UI layer distinct from transport and serialization concerns.

4. **Authentication and user management**
   - Backend: `users/` is the main identity subsystem, with `models.py`, `serializers.py`, `views.py`, `urls.py`, and admin registration.
   - Frontend: `AuthService`, `loginScreen`, `registerScreen`, and `profileScreens` consume those endpoints.
   - The presence of `templates/activation_success.html` implies an account activation flow, likely email-based, handled by the backend.

5. **Plant disease detection subsystem**
   - Backend: `plant_disease/` is the ML-powered service boundary.
   - It contains a persisted model artifact in `plant_disease/ml/model.pkl`, plus `preprocess.py` and `predict.py` for image preprocessing and inference.
   - `serializers.py`, `views.py`, and `urls.py` indicate the ML pipeline is exposed through API endpoints rather than directly embedded in the app UI.
   - This is the most clearly separated “AI” subsystem in the architecture.

6. **Chatbot subsystem**
   - Backend: `chatbot/` and frontend `ChatBotScreen/chatScreen.dart` together form the conversational feature.
   - There is a trained model artifact at `model/1.keras` and also mirrored in backend directories, suggesting the chatbot uses a separate ML model from the plant disease classifier.
   - The client-side `ChatService` likely sends messages to backend endpoints, which route into the chatbot model/inference logic.

7. **Content/social subsystem**
   - Backend: `posts/` contains `models.py` and `view.py`, indicating a lightweight content or feed feature.
   - Frontend: `PostScreen/post_screen.dart` and `PostService/post_Service.dart` represent the corresponding UI and API client.
   - This subsystem is likely database-backed and user-facing, but separate from auth and ML workflows.

8. **Payments subsystem**
   - Backend: `payments/` has `callback.py` and `view.py`, which suggests server-side payment initiation and provider callback handling.
   - Frontend: `MoMoService` and `StripeService` show support for at least **MoMo** and **Stripe** from the app side.
   - Architecturally, this is a boundary where the mobile client initiates payment, the backend validates/processes it, and external payment providers call back into the backend.

9. **API composition and routing**
   - Backend routing is centralized through `api/urls.py` and top-level `urls.py`, which aggregate feature app URLs.
   - Each major capability is split into its own Django app, keeping routing and business logic bounded by domain: users, posts, chatbot, plant_disease, and payments.
   - `asgi.py` and `wsgi.py` show the backend can be served in both async and traditional deployment modes.

10. **Persistence and seeded data**
    - Django models are present in `users`, `posts`, `chatbot`, and `plant_disease`, indicating persistent application state lives in the database.
    - `database/seed.json` suggests initial fixture/seed data for bootstrapping the system.
    - The exact database engine is not shown here, but the architecture clearly separates persisted domain data from the ML artifacts stored on disk.

11. **Configuration and environment separation**
    - Backend settings are split into `settings/common.py` and `settings/local.py`, implying environment-specific configuration.
    - `docker-compose.yml`, `Dockerfile`, and `.env` point to containerized deployment with externalized secrets/configuration.
    - The backend README also mentions a `media/` directory for uploaded images, which matters for the plant-disease workflow.

12. **End-to-end flow to diagram**
    - Primary request path: **Flutter UI → shared service layer → backend REST endpoints → Django app/domain logic → database or model artifact → response back to UI**.
    - For ML features, the flow extends to **uploaded image/message → preprocessing/inference model → API response**.
    - For payments, the flow extends externally to **payment provider callbacks** returning into the backend.

13. **Important architectural boundary summary**
    - The clearest service boundaries are:
      - **Presentation client**: Flutter app
      - **Core backend API**: Django
      - **Identity/content/domain apps**: users, posts
      - **ML services**: plant disease detection, chatbot
      - **External integrations**: Stripe, MoMo
      - **Storage**: database, seed data, uploaded media, model files
    - If drawing the diagram, treat the ML artifacts as **runtime dependencies of backend features**, not separate deployable services unless further evidence is found.

Main entry points: [`hohotree_ui/lib/router/app_router.dart`](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/router/app_router.dart) (App router), [`hohotree_ui/lib/common/util/dio.dart`](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/common/util/dio.dart) (API layer), [`hohotree_be/src/api/urls.py`](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/api/urls.py) (API urls), [`hohotree_be/src/urls.py`](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/urls.py) (Django app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Flutter client"]
  node_ui["Flutter app<br/>presentation<br/>[main.dart]"]
  node_router["App router<br/>navigation<br/>[app_router.dart]"]
  node_ui_home["Home<br/>feature screen<br/>[homeScreens.dart]"]
  node_ui_auth["Auth screens<br/>feature screens<br/>[loginScreen.dart]"]
  node_ui_profile["Profile<br/>feature screen"]
  node_ui_plants["Plant issues<br/>feature screen"]
  node_ui_chat["Chatbot<br/>feature screen<br/>[chatScreen.dart]"]
  node_ui_posts["Posts<br/>feature screen<br/>[post_screen.dart]"]
  node_ui_pay["Payments<br/>feature integration"]
  node_ui_api["API layer<br/>client data layer<br/>[dio.dart]"]
end

subgraph group_backend["Django backend"]
  node_api_root["API urls<br/>routing<br/>[urls.py]"]
  node_backend_root["Django app<br/>service entry<br/>[urls.py]"]
  node_users["Users<br/>identity app<br/>[views.py]"]
  node_posts["Posts<br/>content app<br/>[view.py]"]
  node_chatbot["Chatbot<br/>ml app<br/>[views.py]"]
  node_plant["Plant disease<br/>ml app<br/>[views.py]"]
  node_payments["Payments<br/>integration app<br/>[view.py]"]
  node_db[("Database<br/>persistent state<br/>[seed.json]")]
end

subgraph group_artifacts["Runtime artifacts"]
  node_plant_model["Plant model<br/>artifact<br/>[model.pkl]"]
  node_chat_model["Chat model<br/>artifact<br/>[1.keras]"]
  node_seed["Seed data<br/>fixture<br/>[seed.json]"]
  node_activation["Activation page<br/>template"]
end

node_ui -->|"navigates"| node_router
node_router -->|"routes"| node_ui_home
node_router -->|"routes"| node_ui_auth
node_router -->|"routes"| node_ui_profile
node_router -->|"routes"| node_ui_plants
node_router -->|"routes"| node_ui_chat
node_router -->|"routes"| node_ui_posts
node_router -->|"routes"| node_ui_pay
node_ui_home -->|"calls"| node_ui_api
node_ui_auth -->|"calls"| node_ui_api
node_ui_profile -->|"calls"| node_ui_api
node_ui_plants -->|"calls"| node_ui_api
node_ui_chat -->|"calls"| node_ui_api
node_ui_posts -->|"calls"| node_ui_api
node_ui_pay -->|"calls"| node_ui_api
node_ui_api -->|"REST API"| node_backend_root
node_backend_root -->|"includes"| node_api_root
node_api_root -->|"routes"| node_users
node_api_root -->|"routes"| node_posts
node_api_root -->|"routes"| node_chatbot
node_api_root -->|"routes"| node_plant
node_api_root -->|"routes"| node_payments
node_users -->|"persists"| node_db
node_posts -->|"persists"| node_db
node_chatbot -->|"persists"| node_db
node_plant -->|"loads"| node_plant_model
node_chatbot -->|"loads"| node_chat_model
node_users -->|"renders"| node_activation
node_backend_root -.->|"boots with"| node_seed

click node_ui "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/main.dart"
click node_router "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/router/app_router.dart"
click node_ui_home "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/HomeScreen/homeScreens.dart"
click node_ui_auth "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/LoginScreen/loginScreen.dart"
click node_ui_profile "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/ProfileScreen/profileScreens.dart"
click node_ui_plants "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/PlantIssuesScreen/PlantIssuesScreen.dart"
click node_ui_chat "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/ChatBotScreen/chatScreen.dart"
click node_ui_posts "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/PostScreen/post_screen.dart"
click node_ui_pay "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Services/StripeService/stripe_service.dart"
click node_ui_api "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/common/util/dio.dart"
click node_api_root "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/api/urls.py"
click node_backend_root "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/urls.py"
click node_users "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/users/views.py"
click node_posts "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/posts/view.py"
click node_chatbot "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/chatbot/views.py"
click node_plant "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/plant_disease/views.py"
click node_payments "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/payments/view.py"
click node_db "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/database/seed.json"
click node_plant_model "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/plant_disease/ml/model.pkl"
click node_chat_model "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/model/1.keras"
click node_seed "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/database/seed.json"
click node_activation "https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/templates/activation_success.html"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui,node_router,node_ui_home,node_ui_auth,node_ui_profile,node_ui_plants,node_ui_chat,node_ui_posts,node_ui_pay,node_ui_api toneBlue
class node_api_root,node_backend_root,node_users,node_posts,node_chatbot,node_plant,node_payments,node_db toneAmber
class node_plant_model,node_chat_model,node_seed,node_activation toneMint
```

## Components

### Flutter client

Cross-platform UI, feature screens, and shared API/data layer.

- [Flutter app](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/main.dart): presentation · Cross-platform client entrypoint and app shell. · `hohotree_ui/lib/main.dart`
- [App router](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/router/app_router.dart): navigation · Routes the client to feature screens. · `hohotree_ui/lib/router/app_router.dart`
- [Home](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/HomeScreen/homeScreens.dart): feature screen · Main landing and navigation hub. · `hohotree_ui/lib/Screens/HomeScreen/homeScreens.dart`
- [Auth screens](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/LoginScreen/loginScreen.dart): feature screens · Login and registration UI. · `hohotree_ui/lib/Screens/LoginScreen/loginScreen.dart`
- [Profile](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/ProfileScreen/profileScreens.dart): feature screen · User account and profile UI. · `hohotree_ui/lib/Screens/ProfileScreen/profileScreens.dart`
- [Plant issues](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/PlantIssuesScreen/PlantIssuesScreen.dart): feature screen · Image-based plant disease workflow UI. · `hohotree_ui/lib/Screens/PlantIssuesScreen/PlantIssuesScreen.dart`
- [Chatbot](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/ChatBotScreen/chatScreen.dart): feature screen · Conversational assistance UI. · `hohotree_ui/lib/Screens/ChatBotScreen/chatScreen.dart`
- [Posts](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Screens/PostScreen/post_screen.dart): feature screen · Content/feed browsing UI. · `hohotree_ui/lib/Screens/PostScreen/post_screen.dart`
- [Payments](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/Services/StripeService/stripe_service.dart): feature integration · Payment-related client services and flows. · `hohotree_ui/lib/Services/StripeService/stripe_service.dart`
- [API layer](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_ui/lib/common/util/dio.dart): client data layer · Shared HTTP client, endpoints, constants, DTOs, and models. · `hohotree_ui/lib/common/util/dio.dart`

### Django backend

Canonical Django app tree under src/ with domain apps and API routing.

- [API urls](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/api/urls.py): routing · Aggregates backend feature routes. · `hohotree_be/src/api/urls.py`
- [Django app](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/urls.py): service entry · Backend project entrypoint and deployment surface. · `hohotree_be/src/urls.py`
- [Users](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/users/views.py): identity app · Authentication, registration, profiles, and activation. · `hohotree_be/src/users/views.py`
- [Posts](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/posts/view.py): content app · Lightweight feed/content subsystem. · `hohotree_be/src/posts/view.py`
- [Chatbot](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/chatbot/views.py): ml app · Conversation endpoints backed by a trained model. · `hohotree_be/src/chatbot/views.py`
- [Plant disease](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/plant_disease/views.py): ml app · Image preprocessing and disease prediction API. · `hohotree_be/src/plant_disease/views.py`
- [Payments](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/payments/view.py): integration app · Payment initiation and provider callbacks. · `hohotree_be/src/payments/view.py`
- [Database](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/database/seed.json): persistent state · Domain models and persisted application data. · `hohotree_be/src/database/seed.json`

### Runtime artifacts

On-disk ML models, seed data, and activation template used by backend features.

- [Plant model](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/plant_disease/ml/model.pkl): artifact · Serialized classifier used by the plant disease pipeline. · `hohotree_be/src/plant_disease/ml/model.pkl`
- [Chat model](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/model/1.keras): artifact · Trained chatbot model artifact. · `hohotree_be/src/model/1.keras`
- [Seed data](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/database/seed.json): fixture · Bootstrapping data for the backend. · `hohotree_be/src/database/seed.json`
- [Activation page](https://github.com/oafnglmh/agrivision-tomato/blob/main/hohotree_be/src/templates/activation_success.html): template · Account activation success template. · `hohotree_be/src/templates/activation_success.html`

## Connections

- Flutter app → App router: navigates · App shell delegates screen selection to the router.
- App router → Home: routes · Home is a primary destination.
- App router → Auth screens: routes · Login and register flows.
- App router → Profile: routes · Profile management screens.
- App router → Plant issues: routes · Plant issue analysis screens.
- App router → Chatbot: routes · Chat assistant screens.
- App router → Posts: routes · Content/feed screens.
- App router → Payments: routes · Payment-related screens and services.
- Home → API layer: calls · Feature screens use shared API utilities.
- Auth screens → API layer: calls · Authentication screens use the API layer.
- Profile → API layer: calls · Profile screens fetch and update user data.
- Plant issues → API layer: calls · Image upload and prediction requests.
- Chatbot → API layer: calls · Message exchange with backend chat endpoints.
- Posts → API layer: calls · Feed content requests.
- Payments → API layer: calls · Payment services call backend endpoints.
- API layer → Django app: REST API · Shared client layer talks to backend HTTP endpoints.
- Django app → API urls: includes · Top-level project URL config composes API routes.
- API urls → Users: routes · Identity endpoints.
- API urls → Posts: routes · Content endpoints.
- API urls → Chatbot: routes · Chat endpoints.
- API urls → Plant disease: routes · Disease prediction endpoints.
- API urls → Payments: routes · Payment endpoints and callbacks.
- Users → Database: persists · User records and activation state.
- Posts → Database: persists · Post content and related data.
- Chatbot → Database: persists · Chat-related domain state.
- Plant disease → Plant model: loads · Inference pipeline uses serialized classifier.
- Chatbot → Chat model: loads · Conversation logic uses trained model artifact.
- Users → Activation page: renders · Email activation flow uses success template.
- Django app → Seed data: boots with · Seed data supports initial database setup.
