# techops-recsys-lateral-hiring/developer-joi-delivery-nodejs architecture

> Architecture diagram of the GitHub repository techops-recsys-lateral-hiring/developer-joi-delivery-nodejs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-03-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs
- Repository: https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs

## Overview

This repo is a **single-service Node.js/Express backend** that exposes a **REST API** for a hyperlocal delivery domain (food + grocery), currently focused on:
- **Cart operations** (add product, view cart)
- **Inventory health** (stubbed endpoint in README)
- **Seeded in-memory/data-layer scaffolding** for dev/test scenarios

From the tree:

- `src/app.js`
- Express app composition: server bootstrapping, route wiring (likely), middleware, listening on port 8080.
- `src/controllers/*`
- HTTP layer (Express route handlers). Includes tests:
- `cartController.js` + `cartController.test.js`
- `inventoryController.js` + `inventoryController.test.js`
- `src/services/*`
- Use-case / application services:
- `cartService.js`
- `productService.js`
- `userService.js`
- `src/domain/*`
- Core business entities / domain model:
- `cart.js`, `product.js`, `groceryProduct.js`, `foodProduct.js`
- `outlet.js`, `groceryStore.js`, `restaurant.js`, `groceryStore.js`
- `user.js`
- `src/seedData/seedData.js`
- “Data layer” per README: initial population, factories; likely acts as repository substitute.

**Architectural pattern to represent:** layered Clean Architecture (even if simplified):
**Controllers (Interface Adapters) → Services (Use Cases) → Domain (Entities)**, with **SeedData** acting like an **in-memory repository/data source**.

##### HTTP / Controllers layer
- `CartController`
- Endpoints: `POST /cart/product`, `GET /cart/view`
- `InventoryController`
- Endpoint: `GET /inventory/health` (stub)

##### Application / Services layer
- `CartService`
- `ProductService`
- `UserService`

##### Domain layer (Entities / Models)
- `Cart`
- `Product` (base) → `GroceryProduct`, `FoodProduct` (inheritance)
- `Outlet` (base) → `GroceryStore`, `Restaurant` (inheritance)
- `User`

##### Data layer substitute
- `SeedData` (factories + initial datasets for Users/Stores/Products)

- `CartController` → `CartService`
- `InventoryController` → `ProductService` (and/or inventory logic)
- `CartService` → `ProductService` (to fetch/validate product)
- `CartService` → `UserService` (to fetch/validate user)
- `*Service` → `SeedData` (data retrieval)
- `*Service` → `Domain` (construct/update entities like `Cart`, `Product`, `Outlet`, `User`)

**Important principle to encode visually:**
- Dependencies should point inward toward **domain**, consistent with Clean Architecture (even if seedData breaks purity). If seedData is imported directly by services, reflect that honestly.

##### Domain objects (`Cart`, `Product`, `Outlet`) as created/returned

- Client → CartController: POST `/cart/product` `{userId, productId, outletId}`
- CartController → CartService: `addProductToCart(userId, productId, outletId)`
- CartService → UserService: `getUser(userId)`
- UserService → SeedData: lookup user
- CartService → ProductService: `getProduct(productId, outletId)` / validate stock
- ProductService → SeedData: lookup outlet + product inventory
- CartService → SeedData: get/create cart for user
- CartService → Domain: add `Product` to `Cart`
- CartService → CartController: return `{cart, product, sellingPrice}`
- CartController → Client: HTTP 200 + JSON

This provides “most accurate” operational understanding without guessing additional systems.

##### Component (layered)
- `app.js` composition
- Controllers
- Services
- Domain entities + inheritance
- SeedData
##### Sequence for
- POST `/cart/product`
- (optional) GET `/cart/view`
##### Test view (optional but accurate)
- Jest tests (`*.test.js`) exercising controllers

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% =========================
  %% Diagram A: Context / Container
  %% =========================
  subgraph "A) Context / Container"
    Client["Client\n(Postman / Mobile / Web)"]:::external

    subgraph "JOI Delivery API\n(Node.js + Express) — Port 8080"
      API["REST API\n/cart/*, /inventory/*"]:::system
      AppJS["Express App Composition\n(app.js)"]:::runtime
    end

    SeedDataStore[("Seed Data / In-memory Data Store\n(seedData.js)\n(No persistent DB yet)")]:::data
  end

  Client -->|"HTTP REST"| API
  API -->|"wired_by"| AppJS
  API -->|"read_write_in_memory"| SeedDataStore

  %% =========================
  %% Diagram B: Component / Layered (Clean Architecture-ish)
  %% =========================
  subgraph "B) Component Diagram — Internal Layering"
    direction TB

    subgraph "JOI Delivery API (Express app boundary)"
      direction TB

      App["app.js\n(bootstrap + middleware + route wiring)"]:::runtime

      subgraph "HTTP / Controllers (Interface Adapters)"
        direction TB
        CartController["CartController\nPOST /cart/product\nGET /cart/view"]:::controller
        InventoryController["InventoryController\nGET /inventory/health (stub)"]:::controller
      end

      subgraph "Application / Services (Use Cases)"
        direction TB
        CartService["CartService"]:::service
        ProductService["ProductService"]:::service
        UserService["UserService"]:::service
      end

      subgraph "Domain (Entities / Models)"
        direction TB
        Cart["Cart"]:::domain
        Product["Product (base)"]:::domain
        GroceryProduct["GroceryProduct"]:::domain
        FoodProduct["FoodProduct"]:::domain
        Outlet["Outlet (base)"]:::domain
        GroceryStore["GroceryStore"]:::domain
        Restaurant["Restaurant"]:::domain
        User["User"]:::domain
      end

      subgraph "Data Layer Substitute"
        direction TB
        SeedData["SeedData\n(factories + datasets: Users/Outlets/Products/Carts)"]:::data
      end
    end

    subgraph "Development / Test (optional)"
      direction TB
      Jest["Jest Test Runner"]:::test
      CartControllerTest["cartController.test.js"]:::test
      InventoryControllerTest["inventoryController.test.js"]:::test
    end
  end

  %% Request flow
  App -->|"routes_to"| CartController
  App -->|"routes_to"| InventoryController

  CartController -->|"calls add/view"| CartService
  InventoryController -->|"calls inventory_health"| ProductService

  CartService -->|"validate_user"| UserService
  CartService -->|"fetch_validate_product"| ProductService

  %% Services -> Data
  UserService -->|"lookup_user"| SeedData
  ProductService -->|"lookup_outlet_product"| SeedData
  CartService -->|"get_or_create_cart"| SeedData

  %% Services -> Domain
  CartService -->|"update_cart"| Cart
  CartService -->|"uses"| User
  ProductService -->|"returns"| Product
  ProductService -->|"uses"| Outlet

  %% Domain inheritance
  Product -->|"inherits_to"| GroceryProduct
  Product -->|"inherits_to"| FoodProduct
  Outlet -->|"inherits_to"| GroceryStore
  Outlet -->|"inherits_to"| Restaurant

  %% Tests
  Jest -->|"executes"| CartControllerTest
  Jest -->|"executes"| InventoryControllerTest
  CartControllerTest -->|"tests"| CartController
  InventoryControllerTest -->|"tests"| InventoryController

  %% =========================
  %% Diagram C: Sequence — POST /cart/product
  %% =========================
  subgraph "C) Sequence — POST /cart/product"
    direction TB
    ClientSeq["Client"]:::external
    CartCtrlSeq["CartController"]:::controller
    CartSvcSeq["CartService"]:::service
    UserSvcSeq["UserService"]:::service
    ProductSvcSeq["ProductService"]:::service
    SeedSeq[("SeedData (in-memory)")]:::data
    DomainSeq["Domain Objects\n(Cart, Product, Outlet, User)"]:::domain
  end

  ClientSeq -->|"POST /cart/product\n{userId, productId, outletId}"| CartCtrlSeq
  CartCtrlSeq -->|"addProductToCart(userId, productId, outletId)"| CartSvcSeq

  CartSvcSeq -->|"getUser(userId)"| UserSvcSeq
  UserSvcSeq -->|"lookup user"| SeedSeq
  SeedSeq -.->|"User"| UserSvcSeq
  UserSvcSeq -.->|"User"| CartSvcSeq

  CartSvcSeq -->|"getProduct(productId, outletId)"| ProductSvcSeq
  ProductSvcSeq -->|"lookup outlet + product"| SeedSeq
  SeedSeq -.->|"Outlet + Product"| ProductSvcSeq
  ProductSvcSeq -.->|"Product"| CartSvcSeq

  CartSvcSeq -->|"get/create cart for user"| SeedSeq
  SeedSeq -.->|"Cart snapshot"| CartSvcSeq

  CartSvcSeq -->|"add Product to Cart"| DomainSeq
  DomainSeq -.->|"updated Cart"| CartSvcSeq

  CartSvcSeq -.->|"{cart, product, sellingPrice}"| CartCtrlSeq
  CartCtrlSeq -.->|"HTTP 200 + JSON"| ClientSeq

  %% =========================
  %% Click Events (from component_mapping)
  %% =========================
  click AppJS "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/app.js"
  click App "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/app.js"

  click CartController "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/controllers/cartController.js"
  click InventoryController "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/controllers/inventoryController.js"
  click CartControllerTest "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/controllers/cartController.test.js"
  click InventoryControllerTest "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/controllers/inventoryController.test.js"

  click CartService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/services/cartService.js"
  click ProductService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/services/productService.js"
  click UserService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/services/userService.js"

  click Cart "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/domain/cart.js"
  click Product "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/domain/product.js"
  click GroceryProduct "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/domain/groceryProduct.js"
  click FoodProduct "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/domain/foodProduct.js"
  click Outlet "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/domain/outlet.js"
  click GroceryStore "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/domain/groceryStore.js"
  click Restaurant "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/domain/restaurant.js"
  click User "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/domain/user.js"

  click SeedDataStore "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/seedData/seedData.js"
  click SeedData "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/seedData/seedData.js"

  %% Directory click events
  click CartController "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/tree/main/src/controllers/"
  click InventoryController "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/tree/main/src/controllers/"
  click CartService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/tree/main/src/services/"
  click ProductService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/tree/main/src/services/"
  click UserService "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/tree/main/src/services/"
  click Cart "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/tree/main/src/domain/"
  click Product "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/tree/main/src/domain/"
  click SeedData "https://github.com/techops-recsys-lateral-hiring/developer-joi-delivery-nodejs/blob/main/src/seedData/seedData.js"

  %% =========================
  %% Styles
  %% =========================
  classDef external fill:#ffffff,stroke:#111827,stroke-width:1.5px,color:#111827
  classDef system fill:#ede9fe,stroke:#6d28d9,stroke-width:2px,color:#111827
  classDef runtime fill:#e0f2fe,stroke:#0284c7,stroke-width:2px,color:#0f172a

  classDef controller fill:#dbeafe,stroke:#2563eb,stroke-width:2px,color:#0f172a
  classDef service fill:#dcfce7,stroke:#16a34a,stroke-width:2px,color:#052e16
  classDef domain fill:#fef9c3,stroke:#ca8a04,stroke-width:2px,color:#422006
  classDef data fill:#e5e7eb,stroke:#374151,stroke-width:2px,color:#111827
  classDef test fill:#ffe4e6,stroke:#be123c,stroke-width:2px,color:#4c0519
```
