This is a simple transaction processing system built with Laravel. It demonstrates handling concurrent operations, ensuring data integrity, and implementing basic security measures.
- Requirements
- Installation
- Usage Instructions
- API Endpoints
- Unit Tests
- Scaling and Architecture Improvements
- PHP 8.0 or higher
- Composer
- Laravel 11.x
- SQLite or any other supported database
-
Clone the repository with
git clone https://github.com/jidejuwon/Transaction -
Install dependencies with
composer install -
Copy .env.example file to .env
cp .env.example .env -
Generate application key with
php artisan key:generate -
Set up database connection and api token in .env DB_CONNECTION=sqlite DB_DATABASE=/path/to/database.sqlite API_TOKEN=yourapikey
-
Ensure the database file exists or create it with
touch /path/to/database.sqlite -
Run migration with
php artisan migrate -
Run seed for default user with
php artisan db:seedDefault user email [test@example.com] -
Start development server with
php artisan serve
- Make Requests: Use tools like Postman or curl to test the API endpoints.
- Import ./Transaction.postman_collection.json into postman
- Update the Bearer Auth key with the key provided in
Installation:5 (API_TOKEN)
- POST /api/transaction: Create a new transaction.
- GET /api/balance: Retrieve the current balance for a user by sending the user's email in the request body.
- Run the unit tests with
php artisan test
To scale this system and improve its architecture for production use, consider the following strategies:
-
Database Optimization: Use indexing on frequently queried fields (like user_id in transactions). Consider database partitioning or sharding as the user base grows.
-
Caching: Implement caching for frequently accessed data, such as user balances, to reduce database load. Use Redis or Memcached for fast in-memory caching.
-
Microservices Architecture: Break down the application into microservices to handle different aspects of the transaction process, such as authentication, transaction management, and user management.
-
Load Balancing: Use load balancers to distribute incoming traffic across multiple instances of your application, ensuring high availability and reliability.
-
Monitoring and Logging: Implement monitoring tools (like New Relic or Laravel Telescope) for tracking application performance. Set up proper logging to capture errors and performance metrics for further analysis.
-
Security Enhancements: Use HTTPS for all communications to secure data in transit. Implement rate limiting to prevent abuse of the API. Regularly update dependencies to fix security vulnerabilities.