{"id":22008890,"url":"https://github.com/albertcolom/vendor-machine","last_synced_at":"2026-04-13T21:03:20.557Z","repository":{"id":186491641,"uuid":"278379351","full_name":"albertcolom/vendor-machine","owner":"albertcolom","description":"Vending machine kata","archived":false,"fork":false,"pushed_at":"2020-07-13T08:50:45.000Z","size":73,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-28T14:17:08.831Z","etag":null,"topics":["cli","commandbus","ddd","dependency-injection","domain-events","middleware","php","suscriber"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/albertcolom.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}},"created_at":"2020-07-09T13:57:14.000Z","updated_at":"2024-04-04T21:14:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"08e75fa8-bcf4-4c2a-a765-233f95ffb2c5","html_url":"https://github.com/albertcolom/vendor-machine","commit_stats":null,"previous_names":["albertcolom/vendor-machine"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertcolom%2Fvendor-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertcolom%2Fvendor-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertcolom%2Fvendor-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertcolom%2Fvendor-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/albertcolom","download_url":"https://codeload.github.com/albertcolom/vendor-machine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245068872,"owners_count":20555841,"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","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":["cli","commandbus","ddd","dependency-injection","domain-events","middleware","php","suscriber"],"created_at":"2024-11-30T02:07:39.902Z","updated_at":"2026-04-13T21:03:20.527Z","avatar_url":"https://github.com/albertcolom.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vending-machine\n\n### Requirements\n- [Docker](https://www.docker.com/)\n- [Docker Compose](https://docs.docker.com/compose/install/)\n\n### Examples in this repo\n- [x] ***No Framework***\n- [x] **DDD** (Domain Driver Design)\n- [x] ***Dependency injection*** and container with [PHP-DI](http://php-di.org/)\n- [x] ***CommandBus*** and ***CommandQuery*** with [Tactician](https://tactician.thephpleague.com)\n- [x] Implement **DomainEvents**\n- [x] Implement **Subscriber** to update vending machine status\n- [x] Implement **Middleware** to dispatch and persist domain events\n- [x] Simple **EventStore** (var/log/domain_events.log)\n- [x] Unit testing with [PHPUnit](https://phpunit.de/)\n- [x] Simple **Repository** with json file and serialize entity with [json-serializer](https://github.com/zumba/json-serializer)\n- [x] **CLI** with [Symfony console](https://symfony.com/doc/current/components/console.html)\n\n### Project folder structure\n```sh\n.\n├── app\n│   └── config\n├── bin\n├── docker\n│   └── php\n├── src\n│   ├── Application\n│   │   ├── Catalog\n│   │   │   └── Subscriber\n│   │   ├── VendingMachine\n│   │   │   ├── Command\n│   │   │   ├── Request\n│   │   │   └── Response\n│   │   └── Wallet\n│   │       └── Subscriber\n│   ├── Domain\n│   │   ├── Catalog\n│   │   │   ├── Event\n│   │   │   ├── Exception\n│   │   │   └── Product\n│   │   ├── Core\n│   │   │   └── Event\n│   │   │       └── Repository\n│   │   ├── VendingMachine\n│   │   │   ├── Event\n│   │   │   ├── Exception\n│   │   │   ├── Repository\n│   │   │   └── Status\n│   │   └── Wallet\n│   │       ├── Coin\n│   │       ├── Event\n│   │       └── Exception\n│   └── Infrastructure\n│       ├── Repository\n│       ├── Service\n│       │   ├── Bus\n│       │   │   └── Middleware\n│       │   ├── Event\n│       │   ├── File\n│       │   └── Serialize\n│       └── Ui\n│           └── Cli\n├── tests\n│   └── unit\n│       └── Application\n│           └── VendingMachine\n└── var\n    ├── data\n    └── log\n```\n### Installation\n\nClone this repository\n```sh\n$ git clone git@github.com:albertcolom/vendor-machine.git\n```\nStart docker compose\n```sh\n$ docker-compose up -d\n```\n### CLI\n```sh\n$ docker-compose exec php bin/console\n```\nAvailable commands\n```sh\nvending-machine\n    vending-machine:coin:add       Add coin into the machine\n    vending-machine:coin:add:user  User add coin into the machine\n    vending-machine:coin:refund    Refund user coins\n    vending-machine:create         Create vending machine with catalog and wallet\n    vending-machine:create:empty   Create empty vending machine\n    vending-machine:product:add    Add product into the machine\n    vending-machine:product:buy    Buy product\n    vending-machine:summary        Vending machine summary\n```\nExample commands with parameters\n```sh\n$ docker-compose exec php bin/console vending-machine:coin:add 0.1\n$ docker-compose exec php bin/console vending-machine:coin:add:user 0.1\n$ docker-compose exec php bin/console vending-machine:coin:refund\n$ docker-compose exec php bin/console vending-machine:create\n$ docker-compose exec php bin/console vending-machine:create:empty\n$ docker-compose exec php bin/console vending-machine:product:add water 1\n$ docker-compose exec php bin/console vending-machine:product:buy water\n$ docker-compose exec php bin/console vending-machine:summary\n```\n### Read live file event log\n```sh\n$ docker-compose exec php tail -f var/log/domain_events.log\n```\nSample Output\n```sh\n[2020-07-12 19:03:09] \"CoinAmountWasCreated\" {\"coin_type\":0.05,\"quantity\":1}\n[2020-07-12 19:03:09] \"CoinAmountWasCreated\" {\"coin_type\":0.1,\"quantity\":1}\n[2020-07-12 19:03:09] \"CoinAmountWasCreated\" {\"coin_type\":1,\"quantity\":1}\n[2020-07-12 21:20:25] \"ProductLineWasCreated\" {\"product_type\":\"water\",\"price\":1,\"quantity\":1}\n[2020-07-12 21:40:01] \"CoinAmountWasRemoved\" {\"coin_type\":1,\"quantity\":3}\n[2020-07-12 21:40:01] \"ProductLineWasRemoved\" {\"product_type\":\"juice\",\"price\":1,\"quantity\":1}\n```\n\n### Test\n```sh\n$ docker-compose exec php bin/phpunit\n```\n### Screenshots\n- Success message:\n\n![Success](https://i.imgur.com/kb4iZZa.png)\n\n- Error message:\n\n![Error](https://i.imgur.com/1VXo8dk.png)\n\n- Vending machine summary:\n\n![Summary](https://i.imgur.com/XDcZxyF.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertcolom%2Fvendor-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbertcolom%2Fvendor-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertcolom%2Fvendor-machine/lists"}