Gesture-Driven Shopping App (Angular + handtrackjs)
Implements hand gesture control in an Angular storefront using handtrackjs, with custom gesture combos for navigation and quantity control and a clean cart flow.
Overview
This group assignment delivers a gesture-controlled shopping experience in the browser. The app detects hands with handtrackjs, maps gestures to UI actions in Angular, and supports a minimal cart with visual feedback. I focused on the gesture pipeline, the event model between the detector and the UI, and the product navigation and cart interaction.
Created features
- Working Angular app with a product carousel, detail card, and a cart page
- Gesture control using
handtrackjswith a stable sampling loop - Two custom gesture combinations for quantity changes
- Clean layout and clear on-screen feedback for each action
Tech Stack
- Angular components for Home, Carousel, Cart, and routing stubs
- handtrackjs for client-side detection
- ngx-toastr for lightweight notifications in the carousel
- JSON inventory for product data and a simple in-memory cart service
Gesture Pipeline
Component: HandtrackerComponent
- Loads the model once with parameters such as
scoreThresholdandmaxNumBoxes. - Starts the camera and schedules detection at a fixed SAMPLERATE of 500 ms.
- For each run, counts labels:
open,closed,point, andpinch. - Emits a single normalized string via
EventEmitter<PredictionEvent>.
Detected labels
- One open hand, two open hands
- One closed hand, two closed hands
- One pointing hand, two pointing hands
- One pinching hand, two pinching hands
-
Custom combinations:
- Open Hand and Closed Hand
- Open Hand and Hand Pointing
The component only emits when a label is present and falls back to None if no hands are detected.
Interaction Model
Component: HomePageComponent The prediction(event) handler receives a gesture string and maps it to UI actions.
Navigation gestures
-
Two Open Handsswitches to Home -
Two Closed Handsswitches to Cart
Home page actions
-
Closed Handselects the previous item in the carousel -
Open Handselects the next item -
Hand Pointingtriggers Add to Cart -
Open Hand and Closed Handtriggers Increase quantity -
Open Hand and Hand Pointingtriggers Decrease quantity
The component uses well-named element ids to trigger semantic buttons so the gesture layer remains decoupled from carousel internals.
Carousel and Cart
CarouselComponent
- Maintains a local
qtywith guardrails - Exposes
prevItem,nextItem,increaseQty,decreaseQty, andaddToCart - Uses Toastr to show immediate feedback such as “Quantity increased by 1”
- Calls a
CartCalculatorservice to add the current item
CartPageComponent
- Hydrates
itemsfrom the cart service and computes totals - Sums
price × quantityusing the static catalog inHomePageComponent.allItems
Files and Responsibilities
-
handtracker.component.ts: camera start and stop, periodic detection, gesture labeling, event emission -
home-page.component.ts: maps gestures to navigation and actions, loads inventory fromassets/inventory.json -
carousel.component.ts: carousel movement, quantity changes, add-to-cart -
cart-page.component.ts: cart summary and total calculation -
route-page.component.ts: input-driven routing shell for current page and item -
*.spec.ts: Angular unit test scaffolds that validate component creation
Design Notes
- Clarity: every gesture produces a corresponding on-screen change or toast so users understand system state.
- Fallbacks: keyboard and mouse controls remain available, which helps in demos and accessibility testing.
How to Run
-
npm installto restore dependencies. -
ng servein a modern desktop browser. - Allow camera permission when prompted.
- Use gestures or conventional controls to navigate and add items.