# vishalk91-4/theta architecture

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

- Interactive diagram: https://gitdiagram.com/vishalk91-4/theta
- Repository: https://github.com/vishalk91-4/theta

## Overview

#### Purpose and Entry Points
Chef’s Choice is a meal-kit ordering platform with a React/TypeScript customer UI, a Node/Express API backed by MongoDB, payment integrations, Google OAuth, and a separate Python intent-classification chatbot/ML subsystem. Main runtime entry points are `client/src/index.tsx`, `server/index.js`, and Python training/app files `train.py`, `app.py`, and `chat.py`.

#### Frontend Application
The browser SPA is rooted at `client/src/App.tsx` and bootstrapped by `client/src/index.tsx`. It presents marketing, meal browsing, cart, authentication, account, registration, and checkout flows through page-level modules such as:
- `client/src/pages/BrowseMeals/BrowseMeals.tsx`
- `client/src/pages/Cart.tsx`
- `client/src/pages/Checkout/Checkout.tsx`

Reusable meal cards, item popups, header/footer, and checkout components compose these pages under `client/src/components`.

#### Client State and Customer Journey
`client/src/context/UserContext.tsx` is the central user/session-facing React state boundary. Registration is implemented as a multi-step workflow, spanning sign-up/login, preference selection, meal selection, and account setup:
- `client/src/pages/Registration.tsx`
- `client/src/components/Registration/Step2/Step2.tsx`
- `client/src/components/Registration/ChooseMeals/ChooseMeals.tsx`

The account area exposes profile, delivery, dietary, plan, and payment settings through `client/src/components/Registration/AccountComponent/`.

#### API and Domain Layer
The Express server starts at `server/index.js` and organizes HTTP boundaries by resource and integration routes. Core API areas are users, items/meals, categories, orders, checkout, and OAuth:
- `server/routes/api/users.js`
- `server/routes/api/items.js`
- `server/routes/api/orders.js`
- `server/routes/api/checkout.js`
- `server/routes/api/oauth.js`

Controllers implement resource behavior in `server/controllers/api/`, while service modules isolate checkout and user-oriented business/integration behavior in `server/services/checkout.js` and `server/services/users.js`.

#### Persistence, Identity, and Authorization
MongoDB is the system of record, configured through `MONGO_URI`; its principal domain models are user, menu item, category, and order:
- `server/models/user.js`
- `server/models/item.js`
- `server/models/order.js`

Authentication combines JWT utilities/middleware with Passport-managed OAuth. Protected request flow is route → auth middleware → controller/service → Mongoose model:
- `server/configuration/passport.js`
- `server/utils/authMiddleware.js`
- `server/utils/jwtUtils.js`

Google OAuth requires server-side client credentials and redirects through the OAuth route layer.

#### Payments and Checkout Boundary
Checkout UI collects delivery/payment data and order summary data before calling the backend:
- `client/src/components/Checkout/CheckoutForm.tsx`
- `client/src/pages/Checkout/DeliveryAddressForm.tsx`
- `client/src/pages/Checkout/PaymentEntryForm.tsx`

The system supports Stripe credentials and PayPal. PayPal client SDK provisioning is encapsulated by `client/src/providers/PaypalProvider.tsx`; server-side PayPal handling is separated in `server/utils/paypalUtils.js`. Payment execution/orchestration belongs in `server/services/checkout.js`, keeping provider secrets server-side.

#### ML Chatbot and Deployment
The root Python subsystem trains and serves an NLTK/PyTorch-style intent model from `intents.json`, producing/consuming `data.pth`:
- `train.py`
- `model.py`
- `nltk_utils.py`
- `chat.py`

Docker Compose coordinates client and API containers via `docker-compose.yml`, with independent images at `client/Dockerfile` and `server/Dockerfile`. Database seeding is an explicit development data lifecycle managed by `server/config/seed.js` and `server/config/seedDeleter.js`.

Main entry points: [`server/routes/api/checkout.js`](https://github.com/vishalk91-4/theta/blob/main/server/routes/api/checkout.js) (Resource and integration routes), [`client/src/App.tsx`](https://github.com/vishalk91-4/theta/blob/main/client/src/App.tsx) (SPA routes and shell), [`client/src/pages/Checkout/Checkout.tsx`](https://github.com/vishalk91-4/theta/blob/main/client/src/pages/Checkout/Checkout.tsx) (Checkout UI), [`server/services/checkout.js`](https://github.com/vishalk91-4/theta/blob/main/server/services/checkout.js) (Checkout orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Customer SPA"]
  node_client_bootstrap["Browser bootstrap<br/>React entry<br/>[index.tsx]"]
  node_client_app["SPA routes and shell<br/>React application<br/>[App.tsx]"]
  node_client_session["User session state<br/>React context<br/>[UserContext.tsx]"]
  node_client_meals["Meal browsing<br/>page module<br/>[BrowseMeals.tsx]"]
  node_client_cart["Cart<br/>page module<br/>[Cart.tsx]"]
  node_client_registration["Registration workflow<br/>multi-step UI<br/>[Registration.tsx]"]
  node_client_checkout["Checkout UI<br/>checkout flow<br/>[Checkout.tsx]"]
  node_paypal_client["PayPal client SDK<br/>payment provider<br/>[PaypalProvider.tsx]"]
end

subgraph group_api["API and Domain"]
  node_api_server["Express server<br/>Node entry<br/>[index.js]"]
  node_api_routes["Resource and integration routes<br/>HTTP routes<br/>[checkout.js]"]
  node_api_auth["JWT and OAuth auth<br/>auth middleware<br/>[authMiddleware.js]"]
  node_api_controllers["API controllers<br/>controller layer"]
  node_api_users_service["User services<br/>domain service<br/>[users.js]"]
  node_api_checkout_service["Checkout orchestration<br/>payment service<br/>[checkout.js]"]
  node_paypal_server["PayPal server integration<br/>payment utility<br/>[paypalUtils.js]"]
  node_mongo_models["Mongoose domain models<br/>persistence models<br/>[user.js]"]
  node_mongodb[("MongoDB<br/>system of record")]
end

subgraph group_ml["Intent Chatbot"]
  node_ml_training["Intent model training<br/>Python training entry<br/>[train.py]"]
  node_ml_model["Intent model artifact<br/>PyTorch model data<br/>[data.pth]"]
  node_ml_chat["Chatbot inference<br/>Python chatbot<br/>[chat.py]"]
end

subgraph group_ops["Development Deployment"]
  node_compose{{"Docker Compose<br/>container orchestration<br/>[docker-compose.yml]"}}
  node_seed_data["Database seeding<br/>development data lifecycle<br/>[seed.js]"]
end

node_client_bootstrap -->|"mounts"| node_client_app
node_client_app -->|"uses"| node_client_session
node_client_app -->|"renders"| node_client_meals
node_client_app -->|"renders"| node_client_cart
node_client_app -->|"renders"| node_client_registration
node_client_app -->|"renders"| node_client_checkout
node_client_checkout -->|"provisions SDK"| node_paypal_client
node_client_session -->|"auth and user requests"| node_api_routes
node_client_meals -->|"meal requests"| node_api_routes
node_client_cart -->|"order requests"| node_api_routes
node_client_registration -->|"registration requests"| node_api_routes
node_client_checkout -->|"checkout request"| node_api_routes
node_api_server -->|"hosts"| node_api_routes
node_api_routes -->|"protects routes"| node_api_auth
node_api_auth -->|"authorizes"| node_api_controllers
node_api_routes -->|"dispatches"| node_api_controllers
node_api_controllers -->|"user operations"| node_api_users_service
node_api_controllers -->|"checkout operations"| node_api_checkout_service
node_api_users_service -->|"reads and writes"| node_mongo_models
node_api_checkout_service -->|"creates orders"| node_mongo_models
node_api_checkout_service -->|"executes PayPal"| node_paypal_server
node_mongo_models -->|"persists"| node_mongodb
node_seed_data -.->|"populates development data"| node_mongodb
node_ml_training -->|"produces"| node_ml_model
node_ml_model -->|"loaded for inference"| node_ml_chat
node_compose -.->|"runs client container"| node_client_bootstrap
node_compose -.->|"runs API container"| node_api_server

click node_client_bootstrap "https://github.com/vishalk91-4/theta/blob/main/client/src/index.tsx"
click node_client_app "https://github.com/vishalk91-4/theta/blob/main/client/src/App.tsx"
click node_client_session "https://github.com/vishalk91-4/theta/blob/main/client/src/context/UserContext.tsx"
click node_client_meals "https://github.com/vishalk91-4/theta/blob/main/client/src/pages/BrowseMeals/BrowseMeals.tsx"
click node_client_cart "https://github.com/vishalk91-4/theta/blob/main/client/src/pages/Cart.tsx"
click node_client_registration "https://github.com/vishalk91-4/theta/blob/main/client/src/pages/Registration.tsx"
click node_client_checkout "https://github.com/vishalk91-4/theta/blob/main/client/src/pages/Checkout/Checkout.tsx"
click node_paypal_client "https://github.com/vishalk91-4/theta/blob/main/client/src/providers/PaypalProvider.tsx"
click node_api_server "https://github.com/vishalk91-4/theta/blob/main/server/index.js"
click node_api_routes "https://github.com/vishalk91-4/theta/blob/main/server/routes/api/checkout.js"
click node_api_auth "https://github.com/vishalk91-4/theta/blob/main/server/utils/authMiddleware.js"
click node_api_users_service "https://github.com/vishalk91-4/theta/blob/main/server/services/users.js"
click node_api_checkout_service "https://github.com/vishalk91-4/theta/blob/main/server/services/checkout.js"
click node_paypal_server "https://github.com/vishalk91-4/theta/blob/main/server/utils/paypalUtils.js"
click node_mongo_models "https://github.com/vishalk91-4/theta/blob/main/server/models/user.js"
click node_ml_training "https://github.com/vishalk91-4/theta/blob/main/train.py"
click node_ml_model "https://github.com/vishalk91-4/theta/blob/main/data.pth"
click node_ml_chat "https://github.com/vishalk91-4/theta/blob/main/chat.py"
click node_compose "https://github.com/vishalk91-4/theta/blob/main/docker-compose.yml"
click node_seed_data "https://github.com/vishalk91-4/theta/blob/main/server/config/seed.js"

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_client_bootstrap,node_client_app,node_client_session,node_client_meals,node_client_cart,node_client_registration,node_client_checkout,node_paypal_client toneBlue
class node_api_server,node_api_routes,node_api_auth,node_api_controllers,node_api_users_service,node_api_checkout_service,node_paypal_server,node_mongo_models,node_mongodb toneAmber
class node_ml_training,node_ml_model,node_ml_chat toneMint
class node_compose,node_seed_data toneRose
```

## Components

### Customer SPA

React/TypeScript browser application.

- [Browser bootstrap](https://github.com/vishalk91-4/theta/blob/main/client/src/index.tsx): React entry · `client/src/index.tsx`
- [SPA routes and shell](https://github.com/vishalk91-4/theta/blob/main/client/src/App.tsx): React application · `client/src/App.tsx`
- [User session state](https://github.com/vishalk91-4/theta/blob/main/client/src/context/UserContext.tsx): React context · `client/src/context/UserContext.tsx`
- [Meal browsing](https://github.com/vishalk91-4/theta/blob/main/client/src/pages/BrowseMeals/BrowseMeals.tsx): page module · `client/src/pages/BrowseMeals/BrowseMeals.tsx`
- [Cart](https://github.com/vishalk91-4/theta/blob/main/client/src/pages/Cart.tsx): page module · `client/src/pages/Cart.tsx`
- [Registration workflow](https://github.com/vishalk91-4/theta/blob/main/client/src/pages/Registration.tsx): multi-step UI · Sign-up, preferences, meal selection, and account setup. · `client/src/pages/Registration.tsx`
- [Checkout UI](https://github.com/vishalk91-4/theta/blob/main/client/src/pages/Checkout/Checkout.tsx): checkout flow · Collects delivery, payment, and order data. · `client/src/pages/Checkout/Checkout.tsx`
- [PayPal client SDK](https://github.com/vishalk91-4/theta/blob/main/client/src/providers/PaypalProvider.tsx): payment provider · `client/src/providers/PaypalProvider.tsx`

### API and Domain

Express, identity, payments, and persistence.

- [Express server](https://github.com/vishalk91-4/theta/blob/main/server/index.js): Node entry · `server/index.js`
- [Resource and integration routes](https://github.com/vishalk91-4/theta/blob/main/server/routes/api/checkout.js): HTTP routes · Users, meals, orders, checkout, and OAuth boundaries. · `server/routes/api/checkout.js`
- [JWT and OAuth auth](https://github.com/vishalk91-4/theta/blob/main/server/utils/authMiddleware.js): auth middleware · Protects requests and supports Passport-managed Google OAuth. · `server/utils/authMiddleware.js`
- **API controllers**: controller layer
- [User services](https://github.com/vishalk91-4/theta/blob/main/server/services/users.js): domain service · `server/services/users.js`
- [Checkout orchestration](https://github.com/vishalk91-4/theta/blob/main/server/services/checkout.js): payment service · Executes payment and order workflow without exposing provider secrets. · `server/services/checkout.js`
- [PayPal server integration](https://github.com/vishalk91-4/theta/blob/main/server/utils/paypalUtils.js): payment utility · `server/utils/paypalUtils.js`
- [Mongoose domain models](https://github.com/vishalk91-4/theta/blob/main/server/models/user.js): persistence models · User, item, category, and order models. · `server/models/user.js`
- **MongoDB**: system of record · Configured through MONGO_URI.

### Intent Chatbot

Python intent training and inference subsystem.

- [Intent model training](https://github.com/vishalk91-4/theta/blob/main/train.py): Python training entry · Builds the trained intent artifact from intents data. · `train.py`
- [Intent model artifact](https://github.com/vishalk91-4/theta/blob/main/data.pth): PyTorch model data · Training output consumed by chatbot inference. · `data.pth`
- [Chatbot inference](https://github.com/vishalk91-4/theta/blob/main/chat.py): Python chatbot · `chat.py`

### Development Deployment

Container orchestration and development data lifecycle.

- [Docker Compose](https://github.com/vishalk91-4/theta/blob/main/docker-compose.yml): container orchestration · Coordinates client and API containers. · `docker-compose.yml`
- [Database seeding](https://github.com/vishalk91-4/theta/blob/main/server/config/seed.js): development data lifecycle · `server/config/seed.js`

## Connections

- Browser bootstrap → SPA routes and shell: mounts
- SPA routes and shell → User session state: uses
- SPA routes and shell → Meal browsing: renders
- SPA routes and shell → Cart: renders
- SPA routes and shell → Registration workflow: renders
- SPA routes and shell → Checkout UI: renders
- Checkout UI → PayPal client SDK: provisions SDK
- User session state → Resource and integration routes: auth and user requests
- Meal browsing → Resource and integration routes: meal requests
- Cart → Resource and integration routes: order requests
- Registration workflow → Resource and integration routes: registration requests
- Checkout UI → Resource and integration routes: checkout request
- Express server → Resource and integration routes: hosts
- Resource and integration routes → JWT and OAuth auth: protects routes
- JWT and OAuth auth → API controllers: authorizes
- Resource and integration routes → API controllers: dispatches
- API controllers → User services: user operations
- API controllers → Checkout orchestration: checkout operations
- User services → Mongoose domain models: reads and writes
- Checkout orchestration → Mongoose domain models: creates orders
- Checkout orchestration → PayPal server integration: executes PayPal
- Mongoose domain models → MongoDB: persists
- Database seeding → MongoDB: populates development data
- Intent model training → Intent model artifact: produces
- Intent model artifact → Chatbot inference: loaded for inference
- Docker Compose → Browser bootstrap: runs client container
- Docker Compose → Express server: runs API container
