This repository contains a funds transfer feature built with Symfony 7, PHP 8.4, Doctrine ORM, and Redis for caching and idempotency.
It demonstrates secure, idempotent, and concurrency-safe transfers between accounts.
- Account Balances: Each account's balance is accurately tracked in the database.
- Transfers: Securely create a transfer from a source account to a destination account.
- Idempotency: Repeated requests with the same idempotency key return the same, correct result, preventing accidental duplicate transfers.
- Concurrency Safety: Prevents race conditions and double-spending using Symfony Lock component.
- Database Transactions: Ensures atomicity and consistency of account balances during the transfer process.
- Redis Caching: Utilized to store idempotency responses for enhanced performance and safety checks.
Follow these steps to get the project running locally using Docker.
- Clone the Repository:
git clone git@github.com:rcsofttech85/simple-payment-system.git
- Change Directory:
cd simple-payment-system - Container Set Up: Start the Docker containers (PHP, MYSQL, Redis).
docker compose up -d
- Install Dependencies: Execute Composer within the PHP container.
docker exec -it payment_php bash run composer install - Database Set up (Create database, run migrations, load fixtures):
bin/console doctrine:database:create --if-not-exists
bin/console doctrine:migration:migrate
bin/console hautelook:fixtures:load --no-interaction
- Generate JWT Key Pair:
bin/console lexik:jwt:generate-keypair
To set up the test database and run the unit/functional tests, execute these commands:
APP_ENV=test bin/console doctrine:database:create --if-not-existsAPP_ENV=test bin/console doctrine:migration:migrateAPP_ENV=test bin/console hautelook:fixtures:load --no-interactionAPP_ENV=test bin/phpunit tests/