# phuctran22/agrixanh architecture

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

- Interactive diagram: https://gitdiagram.com/phuctran22/agrixanh
- Repository: https://github.com/phuctran22/agrixanh

## Overview

AgriXanh is a clean-produce marketplace with customer, seller, and admin portals, backed by a FastAPI API and MongoDB with a mock-data fallback. The main workflow is browsing products, managing a cart, placing and paying for orders, and then managing fulfillment and inventory; AI Vision assessment and loyalty are additional product capabilities. The map preserves these documented and indexed subsystems. Some router implementations and frontend pages were not excerpted, so their internal calls are omitted rather than inferred.

Main entry points: [`frontend/src/services/api.js`](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/services/api.js) (API client), [`backend/main.py`](https://github.com/phuctran22/agrixanh/blob/main/backend/main.py) (FastAPI application), [`frontend/src/App.jsx`](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/App.jsx) (Portal router), [`backend/app/core/database.py`](https://github.com/phuctran22/agrixanh/blob/main/backend/app/core/database.py) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["Portal router<br/>[App.jsx]"]
  node_catalog_ui["Product catalog<br/>[Products.jsx]"]
  node_cart_ui["Cart and account<br/>[Cart.jsx]"]
  node_seller_ui["Seller portal"]
  node_admin_ui["Admin portal<br/>[AdminProducts.jsx]"]
  node_auth_state["Local auth and cart<br/>[authStore.js]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_commerce["Marketplace services"]
  node_auth_api["Authentication<br/>[auth.py]"]
  node_products_api["Product catalog API<br/>[products.py]"]
  node_orders_api["Orders<br/>[orders.py]"]
  node_payments_api["Payments<br/>[payments.py]"]
  node_loyalty_api["Loyalty program<br/>[loyalty.py]"]
  node_ai_api["AI Vision<br/>[ai_vision.py]"]
end

subgraph group_platform["Platform internals"]
  node_entry["FastAPI application<br/>[main.py]"]
  node_database_layer["Database access<br/>[database.py]"]
  node_mock_data["Mock seed data<br/>[mock_data.py]"]
  node_schemas["Domain schemas<br/>[schemas.py]"]
  node_security["JWT and password security<br/>[security.py]"]
  node_loyalty_models["Loyalty models<br/>[loyalty.py]"]
end

subgraph group_operations["Seller and admin operations"]
  node_inventory_api["Inventory<br/>[inventory.py]"]
  node_statistics_api["Statistics<br/>[statistics.py]"]
end

node_customer(("Customer"))
node_seller(("Seller"))
node_admin(("Admin"))
node_mongo[("MongoDB")]

node_customer -->|"uses portal"| node_app
node_seller -->|"uses portal"| node_app
node_admin -->|"uses portal"| node_app
node_app -->|"routes to"| node_catalog_ui
node_app -->|"routes to"| node_cart_ui
node_app -->|"routes to"| node_seller_ui
node_app -->|"routes to"| node_admin_ui
node_catalog_ui -->|"requests data"| node_api_client
node_cart_ui -->|"requests data"| node_api_client
node_cart_ui -->|"reads and updates"| node_auth_state
node_seller_ui -->|"requests data"| node_api_client
node_admin_ui -->|"requests data"| node_api_client
node_app -->|"checks user"| node_auth_state
node_api_client -->|"calls auth routes"| node_auth_api
node_api_client -->|"calls product routes"| node_products_api
node_api_client -->|"calls order routes"| node_orders_api
node_api_client -->|"calls payment routes"| node_payments_api
node_api_client -->|"calls inventory routes"| node_inventory_api
node_api_client -->|"calls loyalty routes"| node_loyalty_api
node_entry -->|"registers router"| node_auth_api
node_entry -->|"registers router"| node_products_api
node_entry -->|"registers router"| node_orders_api
node_entry -->|"registers router"| node_payments_api
node_entry -->|"registers router"| node_ai_api
node_entry -->|"registers router"| node_inventory_api
node_entry -->|"registers router"| node_statistics_api
node_entry -->|"registers router"| node_loyalty_api
node_entry -->|"connects lifecycle"| node_database_layer
node_database_layer -->|"connects and seeds"| node_mongo
node_database_layer -->|"loads seed records"| node_mock_data
node_auth_api -->|"reads database"| node_database_layer
node_auth_api -->|"hashes and validates tokens"| node_security
node_auth_api -->|"uses request models"| node_schemas
node_products_api -->|"reads database"| node_database_layer
node_products_api -->|"uses product models"| node_schemas
node_orders_api -->|"reads and writes"| node_database_layer
node_orders_api -->|"uses order models"| node_schemas
node_orders_api -->|"uses loyalty operations"| node_loyalty_api
node_orders_api -->|"uses product operations"| node_products_api
node_orders_api -->|"uses loyalty models"| node_loyalty_models
node_loyalty_api -->|"reads and writes"| node_database_layer
node_loyalty_api -->|"decodes tokens"| node_security
node_loyalty_api -->|"uses loyalty models"| node_loyalty_models
node_inventory_api -->|"reads database"| node_database_layer
node_ai_api -->|"uses analysis models"| node_schemas

click node_app "https://github.com/phuctran22/agrixanh/blob/main/frontend/src/App.jsx"
click node_catalog_ui "https://github.com/phuctran22/agrixanh/blob/main/frontend/src/pages/Products.jsx"
click node_cart_ui "https://github.com/phuctran22/agrixanh/blob/main/frontend/src/pages/Cart.jsx"
click node_seller_ui "https://github.com/phuctran22/agrixanh/blob/main/frontend/src/pages/seller/SellerAIEvaluate.jsx"
click node_admin_ui "https://github.com/phuctran22/agrixanh/blob/main/frontend/src/pages/admin/AdminProducts.jsx"
click node_auth_state "https://github.com/phuctran22/agrixanh/blob/main/frontend/src/store/authStore.js"
click node_api_client "https://github.com/phuctran22/agrixanh/blob/main/frontend/src/services/api.js"
click node_auth_api "https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/auth.py"
click node_products_api "https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/products.py"
click node_orders_api "https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/orders.py"
click node_payments_api "https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/payments.py"
click node_loyalty_api "https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/loyalty.py"
click node_ai_api "https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/ai_vision.py"
click node_inventory_api "https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/inventory.py"
click node_statistics_api "https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/statistics.py"
click node_entry "https://github.com/phuctran22/agrixanh/blob/main/backend/main.py"
click node_database_layer "https://github.com/phuctran22/agrixanh/blob/main/backend/app/core/database.py"
click node_mock_data "https://github.com/phuctran22/agrixanh/blob/main/backend/app/utils/mock_data.py"
click node_schemas "https://github.com/phuctran22/agrixanh/blob/main/backend/app/models/schemas.py"
click node_security "https://github.com/phuctran22/agrixanh/blob/main/backend/app/core/security.py"
click node_loyalty_models "https://github.com/phuctran22/agrixanh/blob/main/backend/app/models/loyalty.py"

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_app,node_catalog_ui,node_cart_ui,node_seller_ui,node_admin_ui,node_auth_state,node_api_client toneBlue
class node_auth_api,node_products_api,node_orders_api,node_payments_api,node_loyalty_api,node_ai_api,node_mongo toneAmber
class node_entry,node_database_layer,node_mock_data,node_schemas,node_security,node_loyalty_models toneMint
class node_inventory_api,node_statistics_api toneRose
class node_customer,node_seller,node_admin toneIndigo
```

## Components

### Web application

- [Portal router](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Product catalog](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/pages/Products.jsx): `frontend/src/pages/Products.jsx`
- [Cart and account](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/pages/Cart.jsx): `frontend/src/pages/Cart.jsx`
- [Seller portal](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/pages/seller/SellerAIEvaluate.jsx): `frontend/src/pages/seller/SellerAIEvaluate.jsx`
- [Admin portal](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/pages/admin/AdminProducts.jsx): `frontend/src/pages/admin/AdminProducts.jsx`
- [Local auth and cart](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/store/authStore.js): `frontend/src/store/authStore.js`
- [API client](https://github.com/phuctran22/agrixanh/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Marketplace services

- [Authentication](https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/auth.py): `backend/app/api/auth.py`
- [Product catalog API](https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/products.py): `backend/app/api/products.py`
- [Orders](https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/orders.py): `backend/app/api/orders.py`
- [Payments](https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/payments.py): `backend/app/api/payments.py`
- [Loyalty program](https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/loyalty.py): `backend/app/api/loyalty.py`
- [AI Vision](https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/ai_vision.py): `backend/app/api/ai_vision.py`

### Platform internals

- [FastAPI application](https://github.com/phuctran22/agrixanh/blob/main/backend/main.py): `backend/main.py`
- [Database access](https://github.com/phuctran22/agrixanh/blob/main/backend/app/core/database.py): `backend/app/core/database.py`
- [Mock seed data](https://github.com/phuctran22/agrixanh/blob/main/backend/app/utils/mock_data.py): `backend/app/utils/mock_data.py`
- [Domain schemas](https://github.com/phuctran22/agrixanh/blob/main/backend/app/models/schemas.py): `backend/app/models/schemas.py`
- [JWT and password security](https://github.com/phuctran22/agrixanh/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Loyalty models](https://github.com/phuctran22/agrixanh/blob/main/backend/app/models/loyalty.py): `backend/app/models/loyalty.py`

### Seller and admin operations

- [Inventory](https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/inventory.py): `backend/app/api/inventory.py`
- [Statistics](https://github.com/phuctran22/agrixanh/blob/main/backend/app/api/statistics.py): `backend/app/api/statistics.py`

### Other components

- **Customer**
- **Seller**
- **Admin**
- **MongoDB**

## Connections

- Customer → Portal router: uses portal (evidence: `frontend/src/App.jsx`)
- Seller → Portal router: uses portal (evidence: `frontend/src/App.jsx`)
- Admin → Portal router: uses portal (evidence: `frontend/src/App.jsx`)
- Portal router → Product catalog: routes to (evidence: `frontend/src/App.jsx`)
- Portal router → Cart and account: routes to (evidence: `frontend/src/App.jsx`)
- Portal router → Seller portal: routes to (evidence: `frontend/src/App.jsx`)
- Portal router → Admin portal: routes to (evidence: `frontend/src/App.jsx`)
- Product catalog → API client: requests data (evidence: `frontend/src/services/api.js`)
- Cart and account → API client: requests data (evidence: `frontend/src/services/api.js`)
- Cart and account → Local auth and cart: reads and updates (evidence: `frontend/src/store/authStore.js`)
- Seller portal → API client: requests data (evidence: `frontend/src/services/api.js`)
- Admin portal → API client: requests data (evidence: `frontend/src/services/api.js`)
- Portal router → Local auth and cart: checks user (evidence: `frontend/src/App.jsx`)
- API client → Authentication: calls auth routes (evidence: `frontend/src/services/api.js`)
- API client → Product catalog API: calls product routes (evidence: `frontend/src/services/api.js`)
- API client → Orders: calls order routes (evidence: `frontend/src/services/api.js`)
- API client → Payments: calls payment routes (evidence: `frontend/src/services/api.js`)
- API client → Inventory: calls inventory routes (evidence: `frontend/src/services/api.js`)
- API client → Loyalty program: calls loyalty routes (evidence: `frontend/src/services/api.js`)
- FastAPI application → Authentication: registers router (evidence: `backend/main.py`)
- FastAPI application → Product catalog API: registers router (evidence: `backend/main.py`)
- FastAPI application → Orders: registers router (evidence: `backend/main.py`)
- FastAPI application → Payments: registers router (evidence: `backend/main.py`)
- FastAPI application → AI Vision: registers router (evidence: `backend/main.py`)
- FastAPI application → Inventory: registers router (evidence: `backend/main.py`)
- FastAPI application → Statistics: registers router (evidence: `backend/main.py`)
- FastAPI application → Loyalty program: registers router (evidence: `backend/main.py`)
- FastAPI application → Database access: connects lifecycle (evidence: `backend/main.py`)
- Database access → MongoDB: connects and seeds (evidence: `backend/app/core/database.py`)
- Database access → Mock seed data: loads seed records (evidence: `backend/app/core/database.py`)
- Authentication → Database access: reads database (evidence: `backend/app/api/auth.py`)
- Authentication → JWT and password security: hashes and validates tokens (evidence: `backend/app/api/auth.py`)
- Authentication → Domain schemas: uses request models (evidence: `backend/app/api/auth.py`)
- Product catalog API → Database access: reads database (evidence: `backend/app/api/products.py`)
- Product catalog API → Domain schemas: uses product models (evidence: `backend/app/api/products.py`)
- Orders → Database access: reads and writes (evidence: `backend/app/api/orders.py`)
- Orders → Domain schemas: uses order models (evidence: `backend/app/api/orders.py`)
- Orders → Loyalty program: uses loyalty operations (evidence: `backend/app/api/orders.py`)
- Orders → Product catalog API: uses product operations (evidence: `backend/app/api/orders.py`)
- Orders → Loyalty models: uses loyalty models (evidence: `backend/app/api/orders.py`)
- Loyalty program → Database access: reads and writes (evidence: `backend/app/api/loyalty.py`)
- Loyalty program → JWT and password security: decodes tokens (evidence: `backend/app/api/loyalty.py`)
- Loyalty program → Loyalty models: uses loyalty models (evidence: `backend/app/api/loyalty.py`)
- Inventory → Database access: reads database (evidence: `backend/app/api/inventory.py`)
- AI Vision → Domain schemas: uses analysis models (evidence: `backend/app/api/ai_vision.py`)
