The Central Admin Laravel Application is the core system that manages multiple supermarkets in a hypermarket network. It is responsible for:
- Managing supermarkets, locations, suppliers, products, and categories.
- Receiving income reports from supermarkets.
- Handling stock alerts and triggering a supply process.
- Finding the nearest supermarket before ordering from a supplier.
- Sending and receiving TCP messages for supermarket communication.
- Implementing error handling and retry logic for failed TCP requests.
- Admin Authentication: Only one admin user can manage the system.
- Supermarket Management: Create, update, and delete supermarkets.
- Supplier Management: Track suppliers and their products.
- Stock Transfer System: Finds the nearest supermarket to fulfill stock shortages.
- Supplier Ordering: If no supermarket has stock, orders are placed automatically.
- Real-time TCP Communication: Receives stock alerts and income reports.
- Automatic Retries: Retries failed TCP requests with exponential backoff.
The Central Admin App communicates with supermarkets via TCP:
- Receives Income Reports from supermarkets.
- Receives Stock Alerts when a product is running low.
- Finds the nearest supermarket and sends a stock transfer request.
- Handles Supplier Orders if no supermarket has stock.
- Retries TCP Requests if they fail.
git clone https://github.com/your-repo/central-admin.git
cd central-admincomposer install
npm installCreate a .env file and set up the database and server details:
cp .env.example .env
php artisan key:generateUpdate the database settings in .env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=central_admin
DB_USERNAME=root
DB_PASSWORD=yourpasswordphp artisan migrate --seedThis will create tables for supermarkets, suppliers, products, locations, stock alerts, and income reports.
php artisan tcp:listenThis will start the TCP server that listens for income reports and stock alerts from supermarkets.
php artisan queue:workThis ensures background jobs (e.g., TCP retries) are processed.
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/admin/login |
Logs in the admin and returns a token |
GET |
/api/supermarkets |
Retrieves all supermarkets |
POST |
/api/supermarkets |
Creates a new supermarket |
GET |
/api/locations |
Retrieves all locations |
POST |
/api/products |
Adds a new product |
POST |
/api/suppliers |
Adds a new supplier |
- Supermarket Sends an Income Report
- Central Admin receives the report and stores it.
- Supermarket Sends a Stock Alert
- Central Admin finds the nearest supermarket with stock.
- Sends a Stock Transfer Request to the nearest supermarket.
- Sender Supermarket Responds
- If accepted, stock is transferred.
- If no stock is available, an order is placed with the supplier.
- Retries on Failure
- If the TCP request fails, it is retried up to 3 times with exponential backoff.
- TCP Errors: Failed requests are logged in
storage/logs/laravel.log. - Retries: If a TCP request fails, the system retries with increasing delays.
- Queue System: All critical TCP requests run in the background to prevent crashes.