How adamwhite625/bach-hoa-project works
Purpose and Deployable Units
Bach Hoa is a multi-client e-commerce platform: a Node.js commerce API, React admin portal, native Android shopper app, and Python RAG chatbot. Main service entry points are backend/server.js, admin-web/src/main.jsx, android/app/src/main/java/com/example/frontend2/ui/main/MainActivity.java, and chatbotRAG/main.py.
Commerce API Core
The backend is the system-of-record boundary, exposing REST routes from backend/routes/ and delegating request logic to backend/controllers/. backend/server.js initializes the service; domain persistence is represented by MongoDB-oriented models such as backend/models/productModel.js, backend/models/orderModel.js, and backend/models/userModel.js.
Primary flow: web/mobile clients → route → authentication/upload middleware where applicable → controller → model/database → JSON response.
Identity, Administration, and Customer State
JWT-based authorization is centralized in backend/middlewares/authMiddleware.js; authentication and password workflows reside in backend/controllers/authController.js and backend/controllers/passwordController.js. The admin React application protects privileged UI through admin-web/src/components/common/AdminGuard.jsx, with auth state exposed through admin-web/src/hooks/useAuth.js.
Admin operations cover products, categories, discounts, orders, and users via pages including admin-web/src/pages/Admin/ProductManager.jsx, admin-web/src/pages/Admin/OrderManager.jsx, and admin-web/src/pages/Admin/UserManager.jsx.
Shopping and Order Lifecycle
Customer shopping flow spans product browsing, cart changes, voucher application, checkout/payment, and post-order status. Backend ownership is separated into backend/controllers/productController.js, backend/controllers/cartController.js, backend/controllers/discountController.js, backend/controllers/orderController.js, and backend/controllers/paymentController.js.
The Android app presents this flow through android/app/src/main/java/com/example/frontend2/ui/fragment/HomeFragment.java, android/app/src/main/java/com/example/frontend2/ui/fragment/CartFragment.java, and android/app/src/main/java/com/example/frontend2/ui/main/OrderDetailsActivity.java. Shared cart UI state is managed by android/app/src/main/java/com/example/frontend2/ui/main/CartSharedViewModel.java.
Android Client Boundary
The Android app is a Java/Gradle native client using Retrofit-style API access. android/app/src/main/java/com/example/frontend2/data/remote/ApiClient.java, android/app/src/main/java/com/example/frontend2/data/remote/ApiService.java, and android/app/src/main/java/com/example/frontend2/data/model/ define the remote boundary and API DTOs. android/app/src/main/java/com/example/frontend2/utils/SharedPrefManager.java provides local persisted client state, likely including session information.
AI Chatbot Pipeline
chatbotRAG is an independent FastAPI service, not part of the Node API tree. chatbotRAG/build_db.py ingests markdown knowledge from chatbotRAG/data/ into the committed Chroma vector store at chatbotRAG/chroma_db/. chatbotRAG/main.py exposes the chat API, while chatbotRAG/chatbot_core.py implements retrieval/generation using OpenAI credentials. The Android chat UI models include android/app/src/main/java/com/example/frontend2/data/model/ChatMessage.java and ChatMessageRequest.java.
Infrastructure and External Dependencies
MongoDB is the primary database, configurable through backend/config/db.js. Cloudinary handles image uploads via backend/config/cloudinary.js and upload middleware; Gmail-backed email is encapsulated by backend/services/emailService.js. The chatbot requires OpenAI and Chroma. Docker deployment artifacts exist at Dockerfile, backend/Dockerfile, chatbotRAG/Dockerfile, and docker-compose.yml; CI/CD is defined in .github/workflows/deploy.yml.
Main entry points: orderController.js Commerce controllers · AdminGuard.jsx Admin access guard · chatbot_core.py Retrieval & generation · server.js Commerce API
Components 23
Client apps
- Admin portal
admin-web/src/main.jsx - Admin access guard · Protects privileged administration UI.
admin-web/src/components/common/AdminGuard.jsx - Admin auth state
admin-web/src/hooks/useAuth.js - Admin operations · Manages products, orders, users, categories, and discounts.
admin-web/src/pages/Admin/ProductManager.jsx - Android shopper app
android/app/src/main/java/com/example/frontend2/ui/main/MainActivity.java - Shopping & orders UI · Supports browsing, cart, and order-status flows.
android/app/src/main/java/com/example/frontend2/ui/fragment/HomeFragment.java - Commerce API client
android/app/src/main/java/com/example/frontend2/data/remote/ApiClient.java - Chat UI messages
android/app/src/main/java/com/example/frontend2/data/model/ChatMessage.java
Commerce API
- Commerce API · System of record for commerce and identity.
backend/server.js - REST routes
- JWT authorization
backend/middlewares/authMiddleware.js - Commerce controllers · Own products, carts, discounts, orders, payments, and identity workflows.
backend/controllers/orderController.js - Commerce models · Persists products, orders, and users.
backend/models/orderModel.js - Image upload integration
backend/config/cloudinary.js - Email service
backend/services/emailService.js
RAG chatbot
- Chat API · Independent chatbot service.
chatbotRAG/main.py - Retrieval & generation
chatbotRAG/chatbot_core.py - Knowledge ingestion · Loads markdown knowledge into Chroma.
chatbotRAG/build_db.py - Chroma vector store
Data & external services
- MongoDB
backend/config/db.js - Cloudinary
- Gmail
- OpenAI
Connections 22
- Admin portal → Admin access guard: protects UI
- Admin access guard → Admin auth state: reads session
- Admin access guard → Admin operations: permits
- Admin operations → Commerce API: REST requests
- Android shopper app → Shopping & orders UI: hosts
- Shopping & orders UI → Commerce API client: uses
- Commerce API client → Commerce API: REST requests
- Android shopper app → Chat UI messages: hosts
- Chat UI messages → Chat API: chat requests
- Commerce API → REST routes: mounts
- REST routes → JWT authorization: authorizes protected routes
- REST routes → Commerce controllers: delegates
- Commerce controllers → Commerce models: reads and writes
- Commerce models → MongoDB: persists
- Commerce controllers → Image upload integration: handles uploads
- Image upload integration → Cloudinary: stores images
- Commerce controllers → Email service: sends notifications
- Email service → Gmail: delivers through
- Chat API → Retrieval & generation: serves queries
- Retrieval & generation → Chroma vector store: retrieves context
- Retrieval & generation → OpenAI: generates response
- Knowledge ingestion → Chroma vector store: builds index