How oafnglmh/agrivision-tomato works
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: app_router.dart App router · dio.dart API layer · api/urls.py API urls · src/urls.py Django app
Components 22
Flutter client
Cross-platform UI, feature screens, and shared API/data layer.
- Flutter app · Cross-platform client entrypoint and app shell.
hohotree_ui/lib/main.dart - App router · Routes the client to feature screens.
hohotree_ui/lib/router/app_router.dart - Home · Main landing and navigation hub.
hohotree_ui/lib/Screens/HomeScreen/homeScreens.dart - Auth screens · Login and registration UI.
hohotree_ui/lib/Screens/LoginScreen/loginScreen.dart - Profile · User account and profile UI.
hohotree_ui/lib/Screens/ProfileScreen/profileScreens.dart - Plant issues · Image-based plant disease workflow UI.
hohotree_ui/lib/Screens/PlantIssuesScreen/PlantIssuesScreen.dart - Chatbot · Conversational assistance UI.
hohotree_ui/lib/Screens/ChatBotScreen/chatScreen.dart - Posts · Content/feed browsing UI.
hohotree_ui/lib/Screens/PostScreen/post_screen.dart - Payments · Payment-related client services and flows.
hohotree_ui/lib/Services/StripeService/stripe_service.dart - API 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 · Aggregates backend feature routes.
hohotree_be/src/api/urls.py - Django app · Backend project entrypoint and deployment surface.
hohotree_be/src/urls.py - Users · Authentication, registration, profiles, and activation.
hohotree_be/src/users/views.py - Posts · Lightweight feed/content subsystem.
hohotree_be/src/posts/view.py - Chatbot · Conversation endpoints backed by a trained model.
hohotree_be/src/chatbot/views.py - Plant disease · Image preprocessing and disease prediction API.
hohotree_be/src/plant_disease/views.py - Payments · Payment initiation and provider callbacks.
hohotree_be/src/payments/view.py - Database · 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 · Serialized classifier used by the plant disease pipeline.
hohotree_be/src/plant_disease/ml/model.pkl - Chat model · Trained chatbot model artifact.
hohotree_be/src/model/1.keras - Seed data · Bootstrapping data for the backend.
hohotree_be/src/database/seed.json - Activation page · Account activation success template.
hohotree_be/src/templates/activation_success.html
Connections 29
- 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.