{"id":29899411,"url":"https://github.com/neofox/jeromeschaeffer-vending-machine","last_synced_at":"2025-08-20T18:26:14.995Z","repository":{"id":307619443,"uuid":"1030137083","full_name":"Neofox/jeromeschaeffer-vending-machine","owner":"Neofox","description":"A simple vending machine example made for an interview","archived":false,"fork":false,"pushed_at":"2025-08-01T06:33:45.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-01T08:54:32.308Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Neofox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-01T06:31:41.000Z","updated_at":"2025-08-01T06:33:48.000Z","dependencies_parsed_at":"2025-08-01T08:54:35.990Z","dependency_job_id":"cb1cf50a-2dc5-4ad1-8a0f-af62f26d84b8","html_url":"https://github.com/Neofox/jeromeschaeffer-vending-machine","commit_stats":null,"previous_names":["neofox/jeromeschaeffer-vending-machine"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Neofox/jeromeschaeffer-vending-machine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fjeromeschaeffer-vending-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fjeromeschaeffer-vending-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fjeromeschaeffer-vending-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fjeromeschaeffer-vending-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Neofox","download_url":"https://codeload.github.com/Neofox/jeromeschaeffer-vending-machine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Neofox%2Fjeromeschaeffer-vending-machine/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271362589,"owners_count":24746510,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-20T02:00:09.606Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-01T12:34:56.367Z","updated_at":"2025-08-20T18:26:14.976Z","avatar_url":"https://github.com/Neofox.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vending Machine\n\nA vending machine simulator built with React, TypeScript and Tailwind CSS.\nThis project was made as a interview exercise.\n\n## Technology Stack and versions\n\n- **UI**: React v19.1\n- **TypeScript**: v5.8\n- **Build Tool**: Vite v7\n- **Runtime**: Bun v1.2\n- **Styling**: Tailwind CSS v4.1\n- **Testing**: Bun test runner\n- **Linting**: ESLint v9\n\n## How to Run\n\n### Prerequisites\n\n#### Option 1: Using Bun (Recommended)\n\n- **Bun** v1.2.0 or higher\n\n#### Option 2: Using Node.js/npm\n\n- **Node.js** v22.0 or higher\n- **npm** v10.0 or higher\n\n### Installation \u0026 Setup\n\n1. **Clone the repository**\n\n   ```bash\n   git clone https://github.com/Neofox/jeromeschaeffer-vending-machine.git\n   cd jeromeschaeffer-vending-machine\n   ```\n\n#### Using Bun (Recommended)\n\n2. **Install dependencies**\n\n   ```bash\n   bun install\n   ```\n\n3. **Start the development server**\n\n   ```bash\n   bun run dev\n   ```\n\n   The application will be available at `http://localhost:5173`\n\n#### Using Node.js/npm\n\n2. **Install dependencies**\n\n   ```bash\n   npm install\n   ```\n\n3. **Start the development server**\n\n   ```bash\n   npm run dev\n   ```\n\n   The application will be available at `http://localhost:5173`\n\n### Useful Scripts\n\n- `bun run dev` - Start development server\n- `bun run build` - Build for production\n- `bun run preview` - Preview production build\n- `bun run test` - Run tests\n\n## Project Structure\n\n```text\nsrc/\n├── components/               # React components\n├── store/\n│   └── index.ts              # Zustand store with state management\n├── utils/\n│   ├── payment.ts            # Payment calculation utilities\n│   ├── payment.test.ts       # Payment utility tests (use bun test)\n│   └── cn.ts                 # Class name utility\n├── main.tsx                  # App entry point\n└── index.css                 # Styles (tailwindcss)\n```\n\n## State Management\n\nThe application uses **Zustand** for state management.\nA state-machine-like pattern was chosen and **ts-pattern** was used for pattern matching the states.\n\n### Machine States\n\n1. **`idle`**\n   - Default state when no interaction is happening\n   - User can select products\n   - All products are displayed with their prices and stock\n\n2. **`awaiting-payment`**\n   - Triggered when a user selects an available product\n   - Tracks the selected product and amount of money inserted\n   - User can insert cash, pay by card, or cancel the order\n   - Progresses to `dispensing` state\n\n3. **`dispensing`**\n   - Product or change is being dispensed\n   - Tracks whether the user has taken the item and change\n   - User must collect both item and change (if any) to return to `idle`\n\n4. **`error`**\n   - Handles various error conditions (invalid product, out of stock, payment failures)\n   - Stores the previous state to allow recovery\n   - May include change to be returned to the user\n\n### Store Actions\n\n- `selectProduct(productId)` - Select a product for purchase\n- `insertCash(money)` - Insert coins or bills (fail 10% of the time)\n- `payByCard()` - Process card payment (async simulation, fail 20% of the time)\n- `takeItem()` - Collect only the dispensed item\n- `takeChange()` - Collect only the change\n- `resetFromError()` - Recover from error state\n- `cancelOrder()` - Cancel current order and return inserted money\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneofox%2Fjeromeschaeffer-vending-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneofox%2Fjeromeschaeffer-vending-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneofox%2Fjeromeschaeffer-vending-machine/lists"}