A secure and scalable transaction processing system built with Laravel, featuring concurrent operation handling, data integrity protection, and comprehensive testing.
- RESTful API for transaction processing
- Real-time balance tracking
- Concurrent transaction handling
- Data integrity protection
- Comprehensive testing suite
- API Authentication
- Transaction history and filtering
- Balance monitoring
- PHP 8.1 or higher
- Composer
- SQLite (for testing)
- Laravel 10.x
- Clone the repository:
git clone https://github.com/brian-chebon/transaction-processing-system.git
cd transaction-processing-system- Install dependencies:
composer install- Set up environment:
cp .env.example .env
php artisan key:generate- Configure database in
.env:
DB_CONNECTION=sqlite
DB_DATABASE=database/database.sqlite
- Run migrations:
touch database/database.sqlite
php artisan migrate- Seed the database:
php artisan db:seed- Install Sanctum:
php artisan sanctum:installRun the comprehensive test suite:
php artisan testRun specific test categories:
php artisan test --testsuite=Feature
php artisan test --testsuite=UnitAll API endpoints require authentication using Laravel Sanctum. Include the bearer token in your request headers:
Authorization: Bearer <your-token>
-
Create Transaction
POST /api/v1/transactionsBody:
{ "amount": 100.0, "type": "credit", "description": "Optional description" } -
Get Transaction History
GET /api/v1/transactionsQuery Parameters:
- type: credit/debit
- date_from: YYYY-MM-DD
- date_to: YYYY-MM-DD
-
Get Current Balance
GET /api/v1/balance -
Get Detailed Balance
GET /api/v1/balance/details
The API returns appropriate HTTP status codes and JSON responses:
{
"status": "error",
"message": "Error description",
"errors": {
"field": ["Error details"]
}
}transaction-system/
├── app/
│ ├── Exceptions/
│ │ ├── AccountNotFoundException.php
│ │ ├── InsufficientFundsException.php
│ │ ├── InvalidTransactionException.php
│ │ └── Handler.php
│ ├── Http/
│ │ ├── Controllers/
│ │ ├── Middleware/
│ │ └── Requests/
│ ├── Models/
│ ├── Providers/
│ ├── Repositories/
│ └── Services/
├── database/
│ ├── factories/
│ ├── migrations/
│ └── seeders/
└── tests/
├── Feature/
└── Unit/
- Controllers: Handle HTTP requests and responses
- Services: Implement business logic
- Repositories: Manage data access
- Models: Define database structure and relationships
- Middleware: Handle authentication and request processing
- Database transactions for atomicity
- Pessimistic locking for balance updates
- Idempotency support via transaction references
- API Authentication using Sanctum
- Request validation
- SQL injection protection
- Rate limiting
- Safe balance calculations
Configure logging channels in config/logging.php:
'channels' => [
'transactions' => [
'driver' => 'daily',
'path' => storage_path('logs/transactions.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
],
'security' => [
'driver' => 'daily',
'path' => storage_path('logs/security.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 30,
],
'metrics' => [
'driver' => 'daily',
'path' => storage_path('logs/metrics.log'),
'level' => env('LOG_LEVEL', 'debug'),
'days' => 7,
],
],# View transaction logs
tail -f storage/logs/transactions.log
# View security logs
tail -f storage/logs/security.log
# View metrics logs
tail -f storage/logs/metrics.log- Database transaction isolation
- Efficient indexing
- Cache implementation
- Request validation
-
High Availability
- Load balancing
- Database replication
- Cache clustering
-
Performance
- Queue implementation for async processing
- Read replicas for balance queries
- Horizontal scaling
-
Monitoring
- Transaction logging
- Performance metrics
- Error tracking
Common commands for troubleshooting:
# Clear cache
php artisan cache:clear
# Clear config
php artisan config:clear
# Rebuild autoload files
composer dump-autoload
# Reset database
php artisan migrate:fresh --seedCreating new components:
# Create controller
php artisan make:controller TransactionController
# Create model
php artisan make:model Transaction -mf
# Create test
php artisan make:test TransactionTest
# Create seeder
php artisan make:seeder TransactionSeeder- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request