Update: 2026-06-10 18:11:50

This commit is contained in:
Hamza-Ayed
2026-06-10 18:11:50 +03:00
parent a0473a8b0f
commit 977adfe99d
27 changed files with 3946 additions and 206 deletions

204
knowledge/AI_CONTEXT.md Normal file
View File

@@ -0,0 +1,204 @@
# AI_CONTEXT.md — Siro (Intaleq) Ride-Hailing Platform
## Core Architecture
- **4 Flutter apps** (rider, driver, admin, service) + **PHP backend** + **MySQL** + **WebSocket**
- **State Management**: GetX (permanent controllers in AppBindings)
- **Maps**: Intaleq Maps (custom Flutter plugin) + Google Maps + Map SaaS + OSRM
- **Domain**: siromove.com | **API**: api.intaleq.xyz/intaleq_v3 | **Ride**: rides.intaleq.xyz | **Location**: location.intaleq.xyz | **Payment**: walletintaleq.intaleq.xyz
## Passenger Flow (siro_rider)
```
Splash → Auth check → MapScreen (permanent map controllers)
→ Enter destination → Price calc → Ride request (waitingRides)
→ Searching (WebSocket polling + timer) → Driver accepts (RideState.driverApplied)
→ Driver arrives (RideState.driverArrived) → Ride begins (RideState.inProgress)
→ Ride finishes → Rating + Payment → Back to map
```
- **RideState enum**: noRide, cancelled, preCheckReview, searching, driverApplied, driverArrived, inProgress, finished
- **Key Controller**: `RideLifecycleController` (4600 lines) — state machine, deviation detection, ETA calculation
- **Deviation Guard**: 50m threshold, re-routes if off path
- **Local ETA**: Route trimming by closest point, percentage-based time calculation
## Driver Flow (siro_driver)
```
Splash → Auth → MapScreen → Go Online (location streaming)
→ Ride offer via FCM + Android native overlay (TripOverlayPlugin)
→ Accept → Navigate to pickup → Arrived → Begin ride → Active ride → End ride
→ Rate passenger + Payment → Go Offline
```
- **Background**: Android foreground service for GPS + FCM background handler
- **Overlay**: Custom native plugin shows trip data with accept/reject (auto-close 15s)
- **Data package**: 33-index array (passengerLat/Lng, destination, fare, distance, name, phone, etc.)
## API Endpoints (59+ discovered)
### Auth
| Endpoint | Caller |
|----------|--------|
| POST `$server/auth/login.php` | LoginController |
| POST `$authCaptin/login.php` | Driver login |
| POST `$server/auth/signup.php` | RegisterController |
| POST `$server/loginJwtRider.php` | JWT refresh (401 handler) |
### Ride
| Endpoint | Caller |
|----------|--------|
| POST `$rideServerSide/ride/rides/add.php` | Ride request |
| POST `$rideServerSide/rides/acceptRide.php` | Driver accept |
| POST `$rideServerSide/ride/rides/updateStausFromSpeed.php` | Status updates (Arrived/Begin/Finished) |
| POST `$rideServerSide/ride/rides/getRideStatus.php` | Polling fallback |
| POST `$server/ride/rides/getRideStatusFromStartApp.php` | App restore check |
### Location
| Endpoint | Caller |
|----------|--------|
| POST `$location/{getSpeed,getComfort,getBalash,...}.php` | Nearby drivers by car type |
| POST `$location/getDriverCarsLocationToPassengerAfterApplied.php` | Driver GPS after accept |
### Payment
| Endpoint | Caller |
|----------|--------|
| POST `$paymentServer/ride/payment/add.php` | Ride payment |
| POST `$paymentServer/ride/payMob/{wallet,card}/payWithPayMob.php` | Visa/Mastercard |
| POST `$paymentServer/ride/mtn/passenger/{start,confirm}_payment.php` | MTN mobile money |
| POST `$paymentServer/ride/syriatel/passenger/{start,confirm}_payment.php` | Syriatel mobile money |
| POST `$paymentServer/ecash/payWithEcash.php` | E-Cash |
### Other
| Endpoint | Caller |
|----------|--------|
| POST `$server/ride/rate/addRateToDriver.php` | Passenger rating |
| POST `$server/ride/rate/addRateToPassenger.php` | Driver rating |
| POST `$wallet/getWalletByPassenger.php` | Wallet balance |
| POST `$walletDriver/getWalletByDriver.php` | Driver wallet |
| POST `$promo/getPromoBytody.php` | Promo code check |
| POST `$server/ride/invitor/get_unified_code.php` | Referral code |
## Database (60+ tables in intaleqDB1 + intaleq-ridesDB)
### Core Tables
| Table | PK | Key Relationships |
|-------|----|-------------------|
| `passengers` | id (varchar) | → ride, waitingRides, payments, passengerWallet, tokens, ratingDriver, notifications |
| `driver` | idn (auto) + id (varchar) | → ride, car_locations, payments, driverWallet, driverToken, driver_orders |
| `ride` | id (auto) | passenger_id → passengers, driver_id → driver |
| `waitingRides` | id (varchar) | passenger_id → passengers, SPATIAL indexes on lat/lng |
| `car_locations` | driver_id (varchar) | SPATIAL idx_location_point (POINT), BTREE idx_loc_status_time |
| `payments` | id (varchar) | passengerID, driverID, rideId |
| `ratingDriver` | id (auto) | driver_id, passenger_id, UNIQUE ride_id |
### Key Indexes
- `car_locations.location_point` — SPATIAL index for GIS queries
- `waitingRides` — idx_location_status (lat,lng,status,created_at)
- `palces11` — FULLTEXT on name/name_ar/name_en/address/category
## Real-time Systems
- **WebSocket**: PHP Socket.IO server (socket_intaleq/{driver,passenger}_socket.php)
- **Events**: `driver_location_update`, `ride_accepted`, `ride_cancelled`, `ride_finished`
- **Polling fallback**: HTTP polling every N seconds when WebSocket disconnects
- **3 reliable updates**: Stops polling after 3 consecutive WebSocket location updates
## Notifications
- **Push**: Firebase Cloud Messaging (FCM) — `FirebaseMessagesController`
- **Local**: `NotificationController` with custom channels
- **iOS Live Activity**: `IosLiveActivityService` + SwiftUI RideWidget
- **Background**: Android overlay (TripOverlayPlugin) for driver ride offers
- **Types**: Order (ride offer), OrderSpeed, ride status updates
## GIS Logic
- **Routing**: Map SaaS (`map-saas.intaleqapp.com/api/maps/route`) or OSRM (`routesy.intaleq.xyz`)
- **Geocoding**: Map SaaS reverse geocoding + search
- **ETA**: Local algorithm in `RideLifecycleController.updateRemainingRoute()` — finds closest route point, trims polyline, recalculates percentage
- **Deviation**: `checkAndRecalculateIfDeviated()` — 50m threshold, consecutive heading check
- **Driver Tracking**: `handleDriverLocationUpdate()` — camera follows driver, zoom by speed
- **Marker Rotation**: Updates driver car icon rotation based on heading
## Wallet Logic
- **Passenger Wallet**: `passengerWallet` table, deduct on ride, top-up via PayMob/MTN/Syriatel
- **Driver Wallet**: `driverWallet` table, credit after ride, withdraw
- **Payment Methods**: Cash (default), Visa (PayMob), Wallet, MTN, Syriatel, E-Cash
- **Kazan**: Percentage-based commission per country (kazan table: comfortPrice, speedPrice, familyPrice, etc.)
- **Tips**: `tips` table linked to ride/driver/passenger
## State Management Map
### Rider App Controllers (permanent in AppBindings)
| Controller | States | Dependencies |
|-----------|--------|-------------|
| RideLifecycleController | RideState enum (8 states) | CRUD, MapEngine, MapSocket, UiInteractions, NearbyDrivers |
| MapSocketController | connected/disconnected | WebSocket, RideLifecycle |
| MapEngineController | map ready/loading | IntaleqMaps, markers, polylines |
| LocationSearchController | idle/searching/result | Map SaaS API |
| NearbyDriversController | empty/populated | Location API |
| UiInteractionsController | sheet states | All ride widgets |
| LoginController | logged out/authenticating/logged in | CRUD, JWT |
| SplashScreenController | animating/checking/navigating | GetStorage, CRUD |
### Driver App
| Controller | States | Dependencies |
|-----------|--------|-------------|
| HomeCaptainController | offline/online/in-ride | LocationService, WebSocket, CRUD |
| NavigationController | idle/navigating/recalculating | Map, TTS |
| BackgroundServiceHelper | running/stopped | Android service |
## Security
- **JWT** with device fingerprint (SHA-256) in payload
- **X-Device-FP** header validated against JWT fingerprint claim
- **HMAC** for payment server (X-HMAC-Auth header)
- **401 auto-refresh**: `LoginController.getJWT()` retries once
- **Rate limiting**: login_attempts table per IP
## External Services
| Service | Endpoint | Key Type |
|---------|----------|----------|
| Google Maps | maps.googleapis.com | API Key |
| Map SaaS | map-saas.intaleqapp.com | x-api-key |
| Here Maps | autosuggest.search.hereapi.com | API Key |
| OSRM | routec.intaleq.xyz / routesy.intaleq.xyz | None |
| PayMob | paymob.com | HMAC |
| Twilio | verify.twilio.com | Account SID + Token |
| Azure OCR | ocrhamza.cognitiveservices.azure.com | Subscription Key |
| OpenAI | api.openai.com | Bearer Token |
| Llama | Together API | Bearer Token |
| SMS Kazumi | sms.kazumi.me | API Key |
## File Map (Key Files)
```
siro_rider/
lib/main.dart, app_bindings.dart, splash_screen_page.dart
lib/controller/home/map/ride_lifecycle_controller.dart (4600 lines)
lib/controller/home/map/ride_state.dart (8-state enum)
lib/controller/home/map/map_socket_controller.dart
lib/controller/home/map/map_engine_controller.dart
lib/controller/functions/crud.dart (720 lines, unified HTTP client)
lib/constant/links.dart (all API endpoints)
lib/views/home/map_widget.dart/*.dart (20+ map UI widgets)
siro_driver/
lib/main.dart (550 lines, accept/reject logic)
lib/controller/functions/background_service.dart
lib/controller/home/captin/home_captain_controller.dart
lib/views/home/Captin/driver_map_page.dart
lib/views/home/Captin/orderCaptin/order_request_page.dart
backend/
schema_primary.sql (1826 lines, 60+ tables)
schema_ride.sql (1787 lines)
auth/*.php, ride/*.php, Admin/*.php
socket_intaleq/
driver_socket.php, passenger_socket.php
siro_admin/ (Flutter Web admin panel)
20+ controllers, 30+ views
siro_service/ (Driver registration agent app)
```
## Key Business Rules
- **Ride timeout**: `_totalSearchTimeoutSeconds` → increase fee dialog
- **Wait time**: 5-minute passenger wait after driver arrival
- **Deviation**: 50m threshold before re-routing
- **Socket reliability**: 3 updates → stop polling
- **Cash payment**: Driver marks as received, confirmation dialog
- **Wallet payment**: Deduct from passengerWallet, verify balance
- **Multi-point trips**: Up to 5 waypoints (step0-step4 in ride args)
- **Car types**: Speed, Comfort, Family, Delivery, Blash (free), Late, Heavy, Nature, Electric, PinkBike, Van, FemalDriver
- **Regions**: Syria (routesy), Jordan (routesjo), Egypt (routec)

View File

@@ -0,0 +1,169 @@
# API_DEPENDENCY_MATRIX.md — Complete API Endpoint Reference
## Auth Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$server/auth/login.php` | POST | `login_controller.dart` | phone, password, fingerprint | JWT, passenger_id, profile | No | `passengers` |
| `$authCaptin/login.php` | POST | driver login | phone, password, fingerprint | JWT, driver_id, profile | No | `driver` |
| `$server/auth/signup.php` | POST | `register_controller.dart` | phone, email, password, name, gender, birthdate, site | user_id | No | `passengers` |
| `$authCaptin/register.php` | POST | service/register | driver data + documents | driver_id | No | `driver` |
| `$server/auth/loginFromGooglePassenger.php` | POST | `google_sign.dart` | google_token | JWT, passenger_id | No | `passengers` |
| `$authCaptin/loginFromGoogle.php` | POST | driver Google auth | google_token | JWT, driver_id | No | `driver` |
| `$server/loginJwtRider.php` | POST | `login_controller.dart` | refresh_token | new JWT | Yes | `tokens` |
| `$server/loginJwtDriver.php` | POST | driver token refresh | refresh_token | new JWT | Yes | `driverToken` |
| `$server/loginWallet.php` | POST | `login_controller.dart` | refresh_token | wallet JWT | Yes | `tokens` |
| `$server/loginJwtWalletDriver.php` | POST | driver wallet refresh | refresh_token | wallet JWT | Yes | `driverToken` |
| `$server/loginFirstTime.php` | POST | `login_controller.dart` | phone, device_info | first_time status | No | `login_attempts` |
| `$server/auth/otpmessage.php` | POST | `otp_controller.dart` | phone | OTP sent | No | `phone_verification` |
| `$server/auth/verifyOtpMessage.php` | POST | `otp_controller.dart` | phone, otp | verified | No | `phone_verification` |
| `$server/auth/sendVerifyEmail.php` | POST | passenger | email | email sent | No | `email_verifications` |
| `$server/auth/verifyEmail.php` | POST | passenger | email, token | verified | No | `email_verifications` |
| `$server/auth/cnMap.php` | POST | various | country_code | phone mapping | No | None |
| `$server/auth/packageInfo.php` | POST | `splash_screen_controlle.dart` | platform, appName | version, app_name | No | `packageInfo` |
| `$server/auth/checkPhoneNumberISVerfiedPassenger.php` | POST | auth check | phone | verified status | No | `phone_verification_passenger` |
## Ride Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$rideServerSide/ride/rides/add.php` | POST | `ride_lifecycle_controller.dart` | passenger_id, start/end lat/lng, carType, price, distance, duration, payment_method | ride_id | Yes | `waitingRides` |
| `$rideServerSide/rides/acceptRide.php` | POST | driver main.dart | id, rideTimeStart, status='Apply', passengerToken, driver_id | accepted_ride | Yes | `waitingRides`, `ride` |
| `$rideServerSide/ride/rides/get.php` | POST | history, status check | passenger_id or ride_id | ride list | Yes | `ride` |
| `$rideServerSide/ride/rides/getRideOrderID.php` | POST | status polling | ride_id | order_id | Yes | `waitingRides` |
| `$rideServerSide/ride/rides/getRideStatus.php` | POST | polling | ride_id | status | Yes | `ride` |
| `$rideServerSide/ride/rides/getRideStatusBegin.php` | POST | polling | ride_id | begin status | Yes | `ride` |
| `$server/ride/rides/getRideStatusFromStartApp.php` | POST | `ride_lifecycle_controller.dart` | passenger_id | active ride + status | Yes | `ride`, `waitingRides` |
| `$rideServerSide/ride/rides/update.php` | POST | various | ride_id, fields | success | Yes | `ride` |
| `$rideServerSide/ride/rides/updateStausFromSpeed.php` | POST | driver | ride_id, status (Arrived/Begin/Finished) | success | Yes | `ride` |
| `$rideServerSide/ride/rides/delete.php` | POST | admin | ride_id | success | Yes | `ride` |
| `$rideServerSide/cancelRide/add.php` | POST | `cancel_raide_page.dart` | ride_id, passenger_id, driverID, note | cancelled | Yes | `canecl` |
| `$rideServerSide/cancelRide/get.php` | POST | status | ride_id | cancel info | Yes | `canecl` |
## Location Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$location/get.php` | POST | `nearby_drivers_controller.dart` | passenger_lat, passenger_lng, carType | nearby drivers | Yes | `car_locations` |
| `$location/getSpeed.php` | POST | nearby drivers | lat, lng | Speed drivers | Yes | `car_locations` |
| `$location/getComfort.php` | POST | nearby drivers | lat, lng | Comfort drivers | Yes | `car_locations` |
| `$location/getBalash.php` | POST | nearby drivers | lat, lng | Blash drivers | Yes | `car_locations` |
| `$location/getElectric.php` | POST | nearby drivers | lat, lng | Electric drivers | Yes | `car_locations` |
| `$location/getPinkBike.php` | POST | nearby drivers | lat, lng | Bike drivers | Yes | `car_locations` |
| `$location/getDelivery.php` | POST | nearby drivers | lat, lng | Delivery drivers | Yes | `car_locations` |
| `$location/getFemalDriver.php` | POST | nearby drivers | lat, lng | Female drivers | Yes | `car_locations` |
| `$location/getDriverCarsLocationToPassengerAfterApplied.php` | POST | `ride_lifecycle_controller.dart` | driver_id | driver GPS | Yes | `car_locations` |
| `$locationServerSide/addpassengerLocation.php` | POST | passenger | passengerId, lat, lng, rideId | success | Yes | `passengerlocation` |
| `$location/getLocationParents.php` | POST | driver | driver_id | nearby passengers | Yes | `car_locations` |
## Payment Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$paymentServer/ride/payment/add.php` | POST | `payment_controller.dart` | amount, payment_method, passengerID, rideId, driverID | payment_id | Yes | `payments` |
| `$paymentServer/ride/passengerWallet/addPaymentTokenPassenger.php` | POST | wallet | passengerId, amount, token | success | Yes | `payment_tokens_passenger` |
| `$paymentServer/ride/driverWallet/addPaymentToken.php` | POST | driver wallet | driverID, amount, token | success | Yes | `payment_tokens` |
| `$paymentServer/ride/payMob/wallet/payWithPayMob.php` | POST | `paymob_wallet.dart` | passengerId, amount | paymob_url | Yes | `payments` |
| `$paymentServer/ride/payMob/payWithPayMob.php` | POST | `paymob.dart` | passengerId, amount, card_data | payment_response | Yes | `payments` |
| `$paymentServer/ecash/payWithEcash.php` | POST | `e_cash_screen.dart` | passengerId, amount, ecash_data | success | Yes | `payments` |
| `$paymentServer/ride/mtn/passenger/mtn_start.php` | POST | MTN payment | passengerId, amount, phone | mtn_ref | Yes | `payments` |
| `$paymentServer/ride/mtn/passenger/mtn_confirm.php` | POST | MTN payment | mtn_ref, otp | success | Yes | `payments` |
| `$paymentServer/ride/syriatel/passenger/start_payment.php` | POST | Syriatel | passengerId, amount, phone | syriatel_ref | Yes | `payments` |
| `$paymentServer/ride/syriatel/passenger/confirm_payment.php` | POST | Syriatel | ref, otp | success | Yes | `payments` |
| `$paymentServer/ride/payment/get.php` | POST | `driver_payment_controller.dart` | driver_id | today's payments | Yes | `payments` |
| `$paymentServer/ride/payment/getCountRide.php` | POST | driver earnings | driver_id | ride_count | Yes | `payments` |
| `$paymentServer/ride/payment/getAllPayment.php` | POST | admin | date | all payments | Yes | `payments` |
## Wallet Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$wallet/getWalletByPassenger.php` | POST | `passenger_wallet_history_controller.dart` | passenger_id | balance, history | Yes | `passengerWallet` |
| `$walletDriver/getWalletByDriver.php` | POST | driver wallet | driver_id | balance, history | Yes | `driverWallet` |
| `$wallet/add.php` | POST | admin/passenger | passenger_id, amount | success | Yes | `passengerWallet` |
| `$walletDriver/add.php` | POST | admin/driver | driver_id, amount | success | Yes | `driverWallet` |
| `$wallet/get.php` | POST | admin | - | all wallets | Yes | `passengerWallet` |
| `$walletDriver/get.php` | POST | admin | - | all driver wallets | Yes | `driverWallet` |
| `$wallet/getAllPassengerTransaction.php` | POST | passenger | passenger_id | transactions | Yes | `passengerWallet` |
| `$wallet/getPassengerWalletArchive.php` | POST | passenger | passenger_id | archive | Yes | `passengerWallet` |
## Rating Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$server/ride/rate/addRateToDriver.php` | POST | `rate_conroller.dart` | passenger_id, driver_id, ride_id, rating, comment | success | Yes | `ratingDriver` |
| `$server/ride/rate/addRateToPassenger.php` | POST | driver rate | driverID, passenger_id, rideId, rating, comment | success | Yes | `ratingPassenger` |
| `$server/ride/rate/getDriverRate.php` | POST | profile | driver_id | avg_rating, count | Yes | `ratingDriver` |
| `$server/ride/rate/getPassengerRate.php` | POST | profile | passenger_id | avg_rating, count | Yes | `ratingPassenger` |
## Notification Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$server/ride/notificationPassenger/add.php` | POST | admin | passenger_id, title, body | success | Yes | `notifications` |
| `$server/ride/notificationPassenger/get.php` | POST | `passenger_notification_controller.dart` | passenger_id | notifications | Yes | `notifications` |
| `$server/ride/notificationPassenger/update.php` | POST | passenger | id, isShown | success | Yes | `notifications` |
| `$server/ride/notificationCaptain/add.php` | POST | admin | driverID, title, body | success | Yes | `notificationCaptain` |
| `$server/ride/notificationCaptain/get.php` | POST | `notification_captain_controller.dart` | driverID | notifications | Yes | `notificationCaptain` |
| `$server/ride/notificationCaptain/update.php` | POST | driver | id, isShown | success | Yes | `notificationCaptain` |
| `$server/ride/notificationCaptain/addWaitingRide.php` | POST | driver | driver_id | success | Yes | `notificationCaptain` |
| `$server/ride/notificationCaptain/getRideWaiting.php` | POST | driver | driver_id | pending rides | Yes | `notificationCaptain` |
| `$server/ride/firebase/add.php` | POST | `firbase_messge.dart` | passenger_id, token, fingerPrint | success | Yes | `tokens` |
| `$server/ride/firebase/addDriver.php` | POST | driver | captain_id, token, fingerPrint | success | Yes | `driverToken` |
| `$server/ride/firebase/getTokensPassenger.php` | POST | admin | passenger_id | tokens | Yes | `tokens` |
## Profile Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$profile/get.php` | POST | `profile_controller.dart` | passenger_id | profile | Yes | `passengers` |
| `$profile/getCaptainProfile.php` | POST | `captain_profile_controller.dart` | driver_id | driver profile | Yes | `driver` |
| `$profile/update.php` | POST | profile | id, fields | success | Yes | `passengers` |
## Promo Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$promo/get.php` | POST | `promos_controller.dart` | passenger_id | promos | Yes | `promos` |
| `$promo/getPromoBytody.php` | POST | ride request | passenger_id | valid promo | Yes | `promos` |
| `$promo/getPromoFirst.php` | POST | promo check | passenger_id | first promo | Yes | `promos` |
| `$promo/add.php` | POST | admin | promo_code, amount, passengerID, dates | success | Yes | `promos` |
| `$promo/delete.php` | POST | admin | promo_id | success | Yes | `promos` |
| `$promo/update.php` | POST | admin | promo_id, fields | success | Yes | `promos` |
## Invite/Referral Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$server/ride/invitor/get_unified_code.php` | POST | `invites_rewards_controller.dart` | user_id, user_type | referral_code | Yes | `user_referral_codes` |
| `$server/ride/invitor/add_unified_invite.php` | POST | invite | inviter_code, invited_user_id, invited_user_type | success | Yes | `unified_referrals` |
| `$server/ride/invitor/get_passenger_referrals.php` | POST | passenger | passenger_id | referrals | Yes | `unified_referrals` |
| `$server/ride/invitor/add.php` | POST | driver invite | driverId, inviterDriverPhone, inviteCode | success | Yes | `invites` |
| `$server/ride/invitor/get.php` | POST | driver | driverId | invites | Yes | `invites` |
## Admin Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$server/Admin/errorApp.php` | POST | `crud.dart` | error, userId, userType, phone, device, details | success | No | `error` |
| `$server/Admin/getPassengerDetails.php` | POST | admin | phone/email/id | passenger details | Yes | `passengers` |
| `$server/Admin/getPassengerDetailsByPassengerID.php` | POST | admin | passenger_id | details | Yes | `passengers` |
| `$server/Admin/AdminCaptain/get.php` | POST | admin | - | all captains | Yes | `driver` |
| `$server/Admin/AdminCaptain/getCaptainDetailsByEmailOrIDOrPhone.php` | POST | admin | identifier | captain details | Yes | `driver` |
| `$server/Admin/AdminRide/get.php` | POST | admin | - | all rides | Yes | `ride` |
| `$server/Admin/AdminRide/getRidesPerMonth.php` | POST | admin | month, year | rides stats | Yes | `ride` |
| `$server/ride/kazan/get.php` | POST | admin/calculator | country | kazan rates | Yes | `kazan` |
| `$server/ride/kazan/add.php` | POST | admin | country, kazan, prices | success | Yes | `kazan` |
## Misc Endpoints
| Endpoint | Method | Caller Files | Request Model | Response Model | Auth | DB Tables |
|----------|--------|-------------|---------------|----------------|------|-----------|
| `$server/ride/tips/add.php` | POST | rating | driverID, passengerID, rideID, tipAmount | success | Yes | `tips` |
| `$server/ride/driver_order/add.php` | POST | driver | driver_id, order_id, status | success | Yes | `driver_orders` |
| `$server/ride/driver_order/get.php` | POST | driver | driver_id | orders | Yes | `driver_orders` |
| `$server/ride/driver_order/getOrderCancelStatus.php` | POST | driver | order_id | cancel status | Yes | `driver_orders` |
| `$server/ride/driver_order/update.php` | POST | driver | order_id, status | success | Yes | `driver_orders` |
| `$server/ride/feedBack/add.php` | POST | feedback | passengerId, feedBack | success | Yes | `feedBack` |
| `$server/ride/chat/send_message.php` | POST | chat | sender_id, receiver_id, message, ride_id | success | Yes | None (external) |
| `$server/ride/location/get_location_area_links.php` | POST | map | lat, lng | area server links | No | `server_locations` |

View File

@@ -0,0 +1,141 @@
# DATABASE_DEPENDENCY_MATRIX.md — Complete Database Reference
## Database: intaleqDB1 (Primary Database)
| Table | PK | FKs | Used By | Related APIs |
|-------|----|-----|---------|-------------|
| `passengers` | `id` (varchar) | - | Auth, Profile, Ride, Wallet | login, signup, profile/get, getPassengerDetails |
| `driver` | `idn` (auto) + `id` (varchar) | - | Auth, Profile, Admin | loginCaptin, register, getCaptainProfile |
| `ride` | `id` (auto) | `passenger_id` → passengers(id), `driver_id` → driver(id) | Ride lifecycle, Admin, History | getRides, updateRides, addRides |
| `waitingRides` | `id` (varchar) | `passenger_id` → passengers(id) | Ride dispatching, Matching | addRides, getRideOrderID |
| `car_locations` | `driver_id` (varchar) | `driver_id` → driver(id) | Location tracking, Nearby drivers | getCarsLocationByPassenger*, addLocation |
| `car_tracks` | `id` (auto) | `driver_id` → driver(id) | Location history | - |
| `payments` | `id` (varchar) | `passengerID` → passengers(id), `driverID` → driver(id), `rideId` → ride(id) | Payment processing | addPayment, getPayment |
| `passengerWallet` | `id` (auto) | `passenger_id` → passengers(id) | Wallet management | getWalletByPassenger, addWallet |
| `driverWallet` | `id` (auto) | `driverID` → driver(id) | Driver wallet | getWalletByDriver, addDriversWallet |
| `tokens` | `id` (auto) | `passengerID` → passengers(id) | Auth, FCM | addTokens, getTokensPassenger |
| `driverToken` | `id` (auto) | `captain_id` → driver(id) | Auth, FCM | addTokensDriver |
| `ratingDriver` | `id` (auto) | `driver_id` → driver(id), `passenger_id` → passengers(id), `ride_id` → ride(id) | Rating | addRateToDriver, getDriverRate |
| `ratingPassenger` | `id` (auto) | `passenger_id` → passengers(id), `driverID` → driver(id), `rideId` → ride(id) | Rating | addRateToPassenger |
| `promos` | `id` (auto) | `passengerID` → passengers(id) | Promotions | getPromos, addPromo |
| `notifications` | `id` (auto) | `passenger_id` → passengers(id) | Notifications | addNotificationPassenger, get |
| `notificationCaptain` | `id` (auto) | `driverID` → driver(id) | Notifications | addNotificationCaptain, get |
| `canecl` | `id` (auto) | `driverID` → driver(id), `passengerID` → passengers(id), `rideID` → ride(id) | Cancellations | addCancelRide |
| `complaint` | `id` (auto) | `ride_id` → ride(id), `passenger_id` → passengers(id), `driver_id` → driver(id) | Complaints | addComplaint, getComplaint |
| `tips` | `id` (auto) | `driverID` → driver(id), `passengerID` → passengers(id), `rideID` → ride(id) | Tips | addTips |
| `error` | `id` (auto) | - | Error logging | addError |
| `CarRegistration` | `id` (auto) | `driverID` → driver(id) | Car documents | addRegisrationCar, get |
| `captains_car` | `id` (auto) | `driverID` → driver(id) | Car registration | - |
| `driver_documents` | `id` (auto) | `driverID` → driver(id) | Document upload | uploadImageType |
| `card_images` | `id` (auto) | `driverID` → driver(id) | ID card images | uploadImagePortrate |
| `imageProfileCaptain` | `id` (auto) | `driverID` → driver(id) | Profile pictures | - |
| `criminalDocuments` | `id` (auto) | `driverId` → driver(id) | Criminal records | - |
| `driver_behavior` | `id` | `driver_id` → driver(id), `trip_id` → ride(id) | Driver scoring | - |
| `driver_gifts` | `id` (auto) | `driver_id` → driver(id) | Driver gifts | driver_gift_check_page |
| `driver_health_assurance` | `id` (auto) | `driver_id` → driver(id) | Health insurance | - |
| `driver_orders` | `id` (auto) | `driver_id` → driver(id) | Order management | addDriverOrder, get |
| `driver_ride_scam` | `id` (auto) | `driverID` → driver(id), `passengerID` → passengers(id), `rideID` → ride(id) | Scam detection | adddriverScam |
| `email_verifications` | `id` (auto) | - | Email verification | sendVerifyEmail, verifyEmail |
| `employee` | `id` (varchar) | - | Employee management | employee_page |
| `helpCenter` | `id` (auto) | `driverID` → driver(id) | Help center | addhelpCenter |
| `invites` | `id` (auto) | `driverId` → driver(id) | Driver referrals | addInviteDriver |
| `invitesToPassengers` | `id` (auto) | `driverId` → driver(id) | Passenger referrals | addInvitationPassenger |
| `kazan` | `id` (auto) | `adminId` → adminUser(id) | Pricing | getKazanPercent |
| `login_attempts` | `id` (auto) | - | Rate limiting | loginFirstTime |
| `login_attempts_drivers` | `id` (auto) | - | Rate limiting | - |
| `mishwaritrips` | `id` (auto) | `driverId` → driver(id), `passengerId` → passengers(id) | Mishwari trips | addMishwari |
| `notesForDriverService` | `id` (auto) | `phone` → driver(phone) | Admin notes | - |
| `notesForPassengerService` | `id` (auto) | `phone` → passengers(phone) | Admin notes | - |
| `otp_verification_fingerPrint` | `id` | - | OTP fingerprint | - |
| `packageInfo` | `id` (auto) | - | App version | packageInfo |
| `palces11` | `id` (auto) | - | Saved places | getPlacesSyria |
| `passenger_blacklist` | `id` (auto) | - | Passenger blacklist | blacklist_page |
| `passengerlocation` | `id` (auto) | `passengerId` → passengers(id) | Passenger GPS | addpassengerLocation |
| `payment_tokens` | `id` (auto) | `driverID` → driver(id) | Payment tokens | addPaymentTokenDriver |
| `payment_tokens_passenger` | `id` (auto) | `passengerId` → passengers(id) | Payment tokens | addPaymentTokenPassenger |
| `paymentsDriverPoints` | `id` (auto) | `driverID` → driver(id) | Points payments | addDriverPaymentPoints |
| `phone_verification` | `id` (auto) | `driverId` → driver(id) | Phone verification | otpmessage |
| `phone_verification_passenger` | `id` (auto) | - | Phone verification | verifyOtpPassenger |
| `places` / `placesEgypt` | `id` (auto) | - | Places data | savePlacesServer |
| `promptDriverIDEgypt` | `id` (auto) | - | AI prompts | - |
| `ratingApp` | `id` (auto) | - | App rating | - |
| `server_locations` | `id` (auto) | - | Server area links | get_location_area_links |
| `smsSender` | `id` (auto) | - | SMS sender ID | - |
| `token_verification*` | `id` (auto) | - | Token verification | - |
| `user_referral_codes` | `id` (auto) | `user_id` (polymorphic) | Referral codes | get_unified_code |
| `unified_referrals` | `id` (auto) | - | Unified referrals | add_unified_invite |
| `driver_cash_claims` | `id` (auto) | `driver_id` → driver(id), `referral_id` → unified_referrals(id) | Cash claims | - |
| `vehicles` | `id` (auto) | `driverID` → driver(id) | Vehicle info | - |
| `CarRegistration` (ride DB) | `id` (auto) | `driverID` → driver(id) | Car registration | addRegisrationCar |
| `adminUser` | `id` (auto) | - | Admin users | addAdminUser |
| `api_keys` | `id` (auto) | - | API keys | getApiKey |
| `blacklist_driver` | `id` (auto) | `driver_id` → driver(id) | Driver blacklist | blacklist_page |
| `carPlateEdit` | `id` (auto) | `driverId` → driver(id) | Plate edit requests | - |
| `carsToWork` | `id` (auto) | - | Work car registration | - |
| `contactEgypt` / `contactSyria` | `id` (auto) | `driverId` → driver(id) | Contact sync | savePhones |
| `driversWantWork` | `id` (auto) | - | Driver applications | - |
| `feedBack` | `id` (auto) | `passengerId` → passengers(id) | Feedback | addFeedBack |
| `hotels` | `id` | - | Hotel data | - |
| `invoicesAdmin` / `invoice_records` | `id` (auto) | - | Invoicing | - |
| `lisenceDetails` | `id` (varchar) | `driverID` → driver(id) | License details | - |
| `seferWallet` | `id` (auto) | `driverId` → driver(id), `passengerId` → passengers(id) | Sefer wallet | addSeferWallet |
| `test` / `testApp` | `id` (auto) | - | Testing | - |
| `videos` | `id` (auto) | - | Tutorial videos | - |
| `welcomeDriverCall` | `id` (auto) | `driverId` → driver(id) | Welcome calls | - |
| `write_argument_after_applied_from_background` | `id` (auto) | - | Background argument storage | - |
---
## Database: intaleq-ridesDB (Ride-specific Database)
This database mirrors many tables from intaleqDB1 for ride-specific operations. Tables present include:
- `ride`, `waitingRides`, `car_locations`, `car_tracks`, `driver`, `driverToken`, `payments`, `notifications`, `ratingDriver`, etc.
- Purpose: Isolated ride processing without affecting main DB performance.
---
## Key Indexes
| Table | Index | Type | Columns |
|-------|-------|------|---------|
| `car_locations` | `idx_location_point` | SPATIAL | `location_point` |
| `car_locations` | `idx_loc_status_time` | BTREE | `status`, `updated_at`, `latitude`, `longitude` |
| `waitingRides` | `idx_location_status` | BTREE | `start_lat`, `start_lng`, `status`, `created_at` |
| `waitingRides` | `idx_status_created` | BTREE | `status`, `created_at` |
| `waitingRides` | `idx_passenger` | BTREE | `passenger_id` |
| `palces11` | `idx_fulltext_search` | FULLTEXT | `name`, `name_ar`, `name_en`, `address`, `category` |
| `driver` | `national_number` | UNIQUE | `national_number` |
| `passengers` | `phone` | UNIQUE | `phone`, `email` |
| `ride` | `passengerfk` | BTREE | `passenger_id` |
| `ride` | `driverfk` | BTREE | `driver_id` |
| `error` | `idx_error_created_at` | BTREE | `created_at` |
| `error` | `idx_error_phone` | BTREE | `phone` |
---
## Referential Integrity
Most tables use InnoDB engine with foreign key relationships implied by business logic. Explicit FK constraints are minimal. Key relationships:
```
passengers (id) ──┬── ride (passenger_id)
├── waitingRides (passenger_id)
├── payments (passengerID)
├── passengerWallet (passenger_id)
├── tokens (passengerID)
├── ratingDriver (passenger_id)
├── ratingPassenger (passenger_id)
├── notifications (passenger_id)
└── feedBack (passengerId)
driver (id) ──┬── ride (driver_id)
├── car_locations (driver_id)
├── car_tracks (driver_id)
├── payments (driverID)
├── driverWallet (driverID)
├── driverToken (captain_id)
├── ratingDriver (driver_id)
├── ratingPassenger (driverID)
├── notificationCaptain (driverID)
├── driver_orders (driver_id)
└── driver_documents (driverID)

318
knowledge/DRIVER_JOURNEY.md Normal file
View File

@@ -0,0 +1,318 @@
# DRIVER_JOURNEY.md — Complete Driver (Captain) Lifecycle
## Stage 1: App Launch & Authentication
### Screen
- **Route**: `/``SplashScreen`
- **File**: `siro_driver/lib/splash_screen_page.dart`
- **Controllers**: `SplashScreenController`, `LocaleController`, `BackgroundServiceHelper`
### State Flow
- GetX-based auth check → JWT validation → Splash → Map or Login
### Variables
| Variable | Storage | Key |
|----------|---------|-----|
| jwt (driver) | GetStorage | `BoxName.jwt` |
| driverID | GetStorage | `BoxName.driverID` |
| isAppInForeground | GetStorage | `BoxName.isAppInForeground` |
| statusDriverLocation | GetStorage | `BoxName.statusDriverLocation` |
| rideStatus | GetStorage | `BoxName.rideStatus` |
### APIs (Driver Auth)
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$authCaptin/login.php` | POST | phone, password, fingerprint | JWT + driver data |
| `$authCaptin/register.php` | POST | driver data | account created |
| `$server/loginJwtDriver.php` | POST | refresh token | new JWT |
| `$server/loginJwtWalletDriver.php` | POST | refresh token | wallet JWT |
| `$authCaptin/loginFromGoogle.php` | POST | google token | JWT + driver data |
### Database Tables
- `driver` — driver records
- `driverToken` — FCM tokens
## Stage 2: Go Online
### Screen
- **File**: `siro_driver/lib/views/home/Captin/driver_map_page.dart``PassengerLocationMapPage`
- **Controller**: `HomeCaptainController`, `MapSocketController`
### State Flow
1. Driver presses "Go Online" button
2. `HomeCaptainController.startOnlineStatus()`
3. Location service begins continuous GPS updates
4. WebSocket connects to receive ride offers
### Background Service
- **File**: `siro_driver/lib/controller/functions/background_service.dart`
- `BackgroundServiceHelper.initialize()` — starts Android foreground service
- Location updates sent every few seconds to location server
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$location/add.php` | POST | driver_id, lat, lng, heading, speed, status, carType | success |
| `$server/ride/notificationCaptain/addWaitingRide.php` | POST | driver_id | waiting status |
| `$endPoint/ride/notificationCaptain/getRideWaiting.php` | POST | driver_id | pending rides |
### Database Tables
- `car_locations` — real-time driver GPS (SPATIAL index)
- `car_tracks` — historical location tracks
- `notificationCaptain` — pending ride notifications
### Real-time Operations
- **WebSocket Connect**: `socket_intaleq/driver_socket.php`
- **Publish**: `driver_online`, `driver_location`
- **Subscribe**: `ride_offer`, `ride_accepted`, `ride_cancelled`
## Stage 3: Ride Offer Reception
### Screen
- **Widget**: `order_request_page.dart`
- **Overlay**: `TripOverlayPlugin` (native Android overlay showing incoming trip)
### State Flow
1. FCM push received with `category=Order` or `category=OrderSpeed`
2. `backgroundMessageHandler()` processes push data
3. Extracts `DriverList` array from message data
4. Shows overlay via `TripOverlayPlugin.showOverlay(tripData, autoCloseSeconds: 15)`
5. Stores pending trip in secure storage: `pending_driver_list`
### Data Package (DriverList array indices)
| Index | Field |
|-------|-------|
| 0 | passengerLat |
| 1 | passengerLng |
| 2 | paymentAmount |
| 3 | destLat |
| 4 | destLng |
| 5 | distance |
| 7 | passengerId |
| 8 | passengerName |
| 9 | passengerToken |
| 10 | phone |
| 11 | distance (dup) |
| 13 | walletChecked |
| 15 | durationToPassenger |
| 16 | orderId |
| 18 | driverId |
| 19 | durationOfRide |
| 20-25 | steps (waypoints) |
| 26 | fare/totalCost |
| 28 | email |
| 29 | startNameLocation |
| 30 | endNameLocation |
| 31 | carType |
| 32 | kazan |
### Notifications
- **Local**: Custom notification with "ding.wav" sound, accept/reject buttons
- **Overlay**: Android system overlay with trip info + accept/reject
## Stage 4: Accept Ride
### Screen
- **Function**: `_processAcceptOrder(List<dynamic> data)` in `siro_driver/lib/main.dart`
### State Flow
1. Overlay accept button → `TripOverlayPlugin.onTripAccepted` fires
2. Or in-app accept button → `HomeCaptainController.acceptOrder()`
3. Shows loading dialog
4. Calls API to accept:
```
POST {$rideServerSide}/rides/acceptRide.php
payload: { id: orderId, rideTimeStart, status: 'Apply', passengerToken, driver_id }
```
5. On success → navigate to `PassengerLocationMapPage` with ride args
6. On failure (already taken) → show "طلب أخذه سائق آخر" dialog
### Variables Written
| Variable | Value |
|----------|-------|
| `BoxName.statusDriverLocation` | `'on'` |
| `BoxName.rideStatus` | `'Apply'` |
| `BoxName.rideArguments` | ride args map |
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$rideServerSide/rides/acceptRide.php` | POST | orderId, rideTimeStart, status, passengerToken, driver_id | ride accepted |
| `$server/ride/driver_order/add.php` | POST | driver_id, order_id, status='applied' | log |
### GIS Operations
- Route from driver → passenger pickup
- Google Maps directions URL generated
## Stage 5: Navigate to Pickup
### Screen
- **File**: `siro_driver/lib/views/home/Captin/driver_map_page.dart`
- **Navigation**: `siro_driver/lib/controller/home/navigation/navigation_controller.dart`
### State Flow
- `RideStatus: 'Apply'` → navigate to passenger
- **Timer**: `startTimerFromDriverToPassengerAfterApplied()` — ETA countdown
### GIS Operations
- **Route Drawing**: Polyline from driver → passenger pickup
- **Voice Navigation**: TTS navigation instructions
- **Deviation Detection**: Re-route if off path
### Real-time
- **WebSocket Publish**: `driver_location` with ride context
- **WebSocket Subscribe**: `passenger_location`, `ride_cancelled`
## Stage 6: Arrived at Pickup
### Action
- Driver presses "I've Arrived" button
- API call updates ride status to `Arrived`
- 5-minute passenger waiting timer starts
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$rideServerSide/ride/rides/updateStausFromSpeed.php` | POST | ride_id, status='Arrived' | success |
### Notifications
- **Push**: FCM sent to passenger "Driver has arrived"
- **In-App**: Navigation state changes to "Waiting for passenger"
## Stage 7: Start Ride
### Action
- Driver presses "Start Ride" button
- API call updates ride status to `Begin`
- Trip officially begins
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$rideServerSide/ride/rides/updateStausFromSpeed.php` | POST | ride_id, status='Begin' | success |
### GIS Operations
- Route updates from current position → passenger destination
- Live ETA recalculated
## Stage 8: Active Ride
### Screen
- **File**: `driver_map_page.dart` (same screen, different state)
### State Flow
- `RideStatus: 'Begin'` → navigating to destination
- Live trip timer and fare counter displayed
### GIS Operations
- **Route Drawing**: Blue polyline to destination
- **ETA Updates**: Continuous recalculation
- **Driver Behavior**: Speed, hard brakes, distance monitored
### Database Tables
- `driver_behavior` — speed, brakes, score per trip
## Stage 9: End Ride
### Action
- Driver presses "End Ride" button
- API call updates ride status to `Finished`
- Payment screen shown
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$rideServerSide/ride/rides/updateStausFromSpeed.php` | POST | ride_id, status='Finished' | success |
| `$paymentServer/ride/payment/add.php` | POST | amount, payment_method, passengerID, rideId, driverID | payment record |
### GIS Operations
- **Stop Location Tracking**: End ride location published
- **Route Cleanup**: Clear map route
### Real-time
- **WebSocket Publish**: `ride_finished` event
- **WebSocket Disconnect**: Ride room cleanup
## Stage 10: Rating & Payment
### Screen
- **Rate**: Rate passenger bottom sheet
- **Payment**: Cash confirmation or digital payment
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$server/ride/rate/addRateToPassenger.php` | POST | passenger_id, driverID, rideId, rating, comment | success |
| `$server/ride/payment/get.php` | POST | driver_id | today's earnings |
## Stage 11: Go Offline & Earnings
### Screen
- **Wallet**: `siro_driver/lib/views/home/Captin/wallet_page.dart`
- **Earnings**: `earnings_page.dart`
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$walletDriver/getWalletByDriver.php` | POST | driver_id | wallet balance |
| `$paymentServer/ride/driverPayment/get.php` | POST | driver_id | payment history |
| `$server/ride/payment/getCountRide.php` | POST | driver_id | ride count today |
### Go Offline Flow
1. Driver presses "Go Offline"
2. `HomeCaptainController.stopOnlineStatus()`
3. Location stops updating
4. WebSocket disconnects
5. `car_locations.status` set to `'off'`
---
## Navigation Route Map (Driver)
```
SplashScreen (/)
→ [JWT exists?]
→ Yes → PassengerLocationMapPage (/passenger-location-map)
→ No → LoginPage → OTPPage → PassengerLocationMapPage
PassengerLocationMapPage
→ [Online] → WebSocket connects, location streaming starts
→ [Ride Offer via Overlay/FCM] → Accept → PassengerLocationMapPage (with ride)
→ Navigate to pickup → Arrived → Start Ride → Active Ride → End Ride
→ [After Ride] → Rate page → Earnings update → Back to map
→ [Offline] → WebSocket disconnects, location stops
```
## Driver App Background Service Architecture
```
┌──────────────────────────────────────────────────────┐
│ Driver App (siro_driver) │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Main Isolate (flutter) │ │
│ │ - AppBindings, GetX Controllers │ │
│ │ - TripOverlayPlugin.listen() │ │
│ │ - _processAcceptOrder / Reject │ │
│ └──────────────────┬───────────────────────────┘ │
│ │ │
│ ┌──────────────────┴───────────────────────────┐ │
│ │ Background Isolate (FCM Handler) │ │
│ │ - backgroundMessageHandler() │ │
│ │ - Shows TripOverlay (autoClose: 15s) │ │
│ │ - Writes pending_driver_list to SecureStore │ │
│ └──────────────────────────────────────────────┘ │
│ │ │
│ ┌──────────────────┴───────────────────────────┐ │
│ │ Android Foreground Service │ │
│ │ - BackgroundServiceHelper.initialize() │ │
│ │ - LocationService: continuous GPS updates │ │
│ │ - Channels: driver_service, location_service │ │
│ └──────────────────────────────────────────────┘ │
│ │ │
│ ┌──────────────────┴───────────────────────────┐ │
│ │ Native Overlay (Android, Kotlin/Swift) │ │
│ │ - TripOverlayPlugin (custom native plugin) │ │
│ │ - Shows incoming trip data overlay │ │
│ │ - Accept/Reject buttons → MethodChannel │ │
│ └──────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────┘

View File

@@ -0,0 +1,288 @@
# PASSENGER_JOURNEY.md — Complete Passenger Lifecycle
## Stage 1: App Launch
### Screen
- **Route**: `/` → SplashScreen
- **File**: `siro_rider/lib/splash_screen_page.dart`
- **Controller**: `SplashScreenController` (in `siro_rider/lib/controller/home/splash_screen_controlle.dart`)
### State Flow
- **Type**: GetX Controller (Custom Animation)
- **Events**: `controller.init()` → animations play → `controller.checkInitialStatus()`
- **States**: Splash animation → Progress bar → Navigate based on auth status
### Variables
| Variable | Storage | Key |
|----------|---------|-----|
| jwt | GetStorage | `box.read(BoxName.jwt)` |
| passengerID | GetStorage | `box.read(BoxName.passengerID)` |
| driverID | GetStorage | `box.read(BoxName.driverID)` |
| language | GetStorage | `box.read(BoxName.lang)` |
| themeMode | GetStorage | theme preference |
| packageInfo | GetStorage | `BoxName.packagInfo` |
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$server/auth/packageInfo.php` | POST | platform, appName | version info |
### Database Tables
- `packageInfo` — app version tracking
## Stage 2: Authentication Check
### State Flow: SplashScreenController
1. Check `box.read(BoxName.jwt)` existence
2. If JWT exists → check ride status (`_checkInitialRideStatus()`) → navigate to MapScreen or Login
3. If no JWT → navigate to Onboarding/Login
### Navigation Decision
```
SplashScreen
→ JWT exists?
→ Yes → MapPagePassenger
→ No → OnboardingPage (first time) or LoginPage
```
### Screens
| Screen | Route | File |
|--------|-------|------|
| Onboarding | `/onboarding` | `siro_rider/lib/onbording_page.dart` |
| Login | `/login` | `siro_rider/lib/views/auth/login_page.dart` |
| Register | `/register` | `siro_rider/lib/views/auth/register_page.dart` |
| OTP | `/otp` | `siro_rider/lib/views/auth/otp_page.dart` |
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$server/auth/login.php` | POST | phone, password, fingerprint | JWT, passenger data |
| `$server/auth/signup.php` | POST | phone, email, password, name, ... | user created |
| `$server/auth/loginFromGooglePassenger.php` | POST | google token | JWT, passenger data |
| `$server/auth/checkPhoneNumberISVerfiedPassenger.php` | POST | phone | verification status |
| `$auth/otpmessage.php` | POST | phone | OTP sent |
| `$auth/verifyOtpMessage.php` | POST | phone, otp | verified status |
### Models
- **UserModel** → `passengers` table
- **TokenModel** → `tokens` table
## Stage 3: Map Screen — Ride Request
### Screen
- **File**: `siro_rider/lib/views/home/map_page_passenger.dart`
- **Controllers** (all permanent in AppBindings):
- `MapEngineController` — map rendering
- `MapSocketController` — WebSocket management
- `LocationSearchController` — place search
- `NearbyDriversController` — nearby driver list
- `RideLifecycleController` — ride state machine
- `UiInteractionsController` — UI bottom sheets
### State Flow: RideLifecycleController
- **RideState enum**: `noRide → searching → driverApplied → driverArrived → inProgress → finished → preCheckReview → cancelled`
### Search Flow
1. Passenger enters destination → `LocationSearchController.searchPlaces()`
2. Price estimate fetched via fare calculation
3. Passenger selects car type → confirms ride
4. Ride request sent → status = `waiting` → transitions to `searching`
### APIs (Ride Request)
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$rideServerSide/ride/rides/add.php` | POST | passenger_id, start_lat, start_lng, end_lat, end_lng, carType, price, ... | ride_id |
| `$rideServerSide/cancelRide/add.php` | POST | ride_id, passenger_id, note | cancellation |
| `$server/ride/promo/getPromoBytody.php` | POST | passenger_id | promo code |
### Database Tables
- `waitingRides` — active ride requests
- `ride` — completed rides
- `promos` — promo codes
### GIS Operations
- **Reverse Geocoding**: Map SaaS (`/api/geocoding/reverse`)
- **Search Geocoding**: Map SaaS (`/api/geocoding/search`)
- **Routing**: Map SaaS (`/api/maps/route`) or OSRM (`routesy.intaleq.xyz`)
- **ETA Calculation**: Local algorithm in `RideLifecycleController.updateRemainingRoute()`
- **Map Rendering**: `IntaleqMaps` (custom Flutter map plugin)
## Stage 4: Searching for Driver
### Screen
- **Widget**: `searching_captain_window.dart`
- **Timer**: `timer_for_cancell_trip_from_passenger.dart`
### State Flow
- `RideState.searching`
- Polling loop checks `_totalSearchTimeoutSeconds`
- On timeout → `_showIncreaseFeeDialog()`
### Real-time Operations
| Channel | Event | Direction |
|---------|-------|-----------|
| WebSocket | `driver_location_update` | Server → Passenger |
| WebSocket | `ride_accepted` | Server → Passenger |
| Polling | `getRideStatus` | Passenger → Server (fallback) |
### Notifications
- **Local**: Timer tick notifications
- **Push**: When driver accepts via FCM
### Failure Scenarios
| Scenario | Handling |
|----------|----------|
| No drivers found | Show increase fee dialog |
| Network failure | Fallback to polling, show error snackbar |
| Timeout | Auto-cancel, prompt retry |
## Stage 5: Driver Accepted
### Screen
- **Widget**: `driver_card_from_passenger.dart`, `driver_time_arrive_passenger.dart`
- **Function**: `processRideAcceptance()`
### State Flow
- `RideState.driverApplied`
- **Events**: `processRideAcceptance(driverData)`
- **Transitions**: `applied → arrived` (when driver reaches pickup)
### Variables Stored
| Variable | Description |
|----------|-------------|
| `dInfo` | Driver info (name, car, rating, phone) |
| `currentRideId` | Active ride ID |
| `rideData` | Full ride details (price, locations, timestamps) |
| `datadriverCarsLocationToPassengerAfterApplied` | Driver GPS route |
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$rideServerSide/ride/rides/getRideStatus.php` | POST | ride_id | current status |
| `$location/getDriverCarsLocationToPassengerAfterApplied.php` | POST | driver_id | GPS location |
### GIS Operations
- **Route Drawing**: Yellow polyline from driver → passenger
- **Driver Marker**: Real-time car icon following WebSocket updates
- **Deviation Detection**: `checkAndRecalculateIfDeviated()` with 50m threshold
### Real-time Operations
- **WebSocket Connect**: Join ride room
- **Subscribe**: `driver_location_update` events
- **Driver Tracking**: `handleDriverLocationUpdate()` → stop polling after 3 reliable updates
### Notifications
- **Push**: FCM when driver accepts
- **In-App**: `RideLiveNotification.showDriverOnWay()`
- **iOS Live Activity**: `IosLiveActivityService.startRideActivity()`
## Stage 6: Driver Arrived
### Screen
- **Widget**: `driver_time_arrive_passenger.dart`, `ride_begin_passenger.dart`
- **Function**: `processDriverArrival()`
### State Flow
- `RideState.driverArrived`
- **Events**: `processDriverArrival("polling")` or via socket
- **Timer**: 5-minute waiting timer starts
- **Pre-drawing**: Blue route from pickup → destination pre-calculated
### Notifications
- **In-App Dialog**: `uiInteractions.driverArrivePassengerDialoge()`
- **Push**: Driver arrived notification
## Stage 7: Ride In Progress
### Screen
- **Widget**: `ride_begin_passenger.dart`, `passengerRideLoctionWidget.dart`
### State Flow
- `RideState.inProgress`
- **Events**: `processRideBegin()`
- **Timer**: `rideIsBeginPassengerTimer()` — live ride counter
### GIS Operations
- **Blue Route**: Final path from driver → destination
- **Live ETA**: Updated via `updateRemainingRoute()` (local calculation)
- **Camera Tracking**: Follows driver, zoom adjusts by speed
- **Deviation Guard**: Continuous deviation checking, re-route if >50m off path
### Real-time Operations
- **WebSocket**: Continuous `driver_location_update` streaming
- **Polling Fallback**: If socket disconnected, poll `getRideStatus`
### iOS Live Activity
- `IosLiveActivityService` — Dynamic Island / Lock Screen widget
- `RideWidget` in ios/RideWidget — SwiftUI widget
## Stage 8: Ride Finished — Payment & Rating
### Screen
- **Rating**: `siro_rider/lib/views/Rate/rate_captain.dart`, `rating_driver_bottom.dart`
- **Payment**: `payment_method.page.dart`, `cash_confirm_bottom_page.dart`
### State Flow
- `RideState.finished``processRideFinished()`
- Disposes ride socket, stops all timers
- Navigates to RateDriverFromPassenger with driver_id, ride_id, bill
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$server/ride/rate/addRateToDriver.php` | POST | passenger_id, driver_id, ride_id, rating, comment | success |
| `$paymentServer/ride/payment/add.php` | POST | amount, payment_method, passengerID, rideId, driverID | payment record |
| `$paymentServer/ride/passengerWallet/addPaymentTokenPassenger.php` | POST | passengerId, amount, token | wallet deduction |
| `$wallet/getAllPassengerTransaction.php` | POST | passenger_id | transaction history |
| `$server/ride/tips/add.php` | POST | driverID, passengerID, rideID, tipAmount | tip saved |
### Payment Methods Flow
1. **Cash**: Show confirmation dialog, driver marks received
2. **Wallet**: Deduct from `passengerWallet` balance
3. **Visa (PayMob)**: `payWithPayMobCardPassenger``paymetVerifyPassenger`
4. **MTN**: `payWithMTNStart``payWithMTNConfirm`
5. **Syriatel**: `payWithSyriatelStart``payWithSyriatelConfirm`
### Database Tables
- `payments` — ride payment records
- `ratingDriver` — driver ratings
- `ratingPassenger` — passenger ratings
- `tips` — tips given
- `passengerWallet` — wallet balance
### Notifications
- **Push**: Receipt notification
- **In-App**: Rating prompt
## Stage 9: Post-Ride
### Screen
- **Profile**: `passenger_profile_page.dart`
- **Wallet**: `passenger_wallet.dart`
- **History**: `order_history.dart`
- **Promos**: `promos_passenger_page.dart`
### APIs
| Endpoint | Method | Input | Output |
|----------|--------|-------|--------|
| `$wallet/getWalletByPassenger.php` | GET | passenger_id | wallet balance |
| `$profile/get.php` | POST | passenger_id | profile data |
| `$rideServerSide/ride/rides/get.php` | POST | passenger_id | ride history |
| `$promo/get.php` | POST | passenger_id | available promos |
| `$server/ride/invitor/get_passenger_referrals.php` | POST | passenger_id | referral data |
---
## Navigation Route Map
```
SplashScreen (/)
→ [JWT exists?]
→ Yes → MapPagePassenger (/home/map_page_passenger)
→ No → OnboardingPage → LoginPage → OTPPage → MapPagePassenger
MapPagePassenger
→ [Ride states trigger widgets]
→ [Menu] → Profile (/profile), Wallet (/wallet), Settings, Promos
→ [Rating] → RateCaptain page
→ [Contact] → ContactUsPage (/contactSupport)
→ [Share] → ShareAppPage (/shareApp)

View File

@@ -0,0 +1,135 @@
# PROJECT_OVERVIEW — Siro (Intaleq) Ride-Hailing Platform
## Business Purpose
Siro (Intaleq) is a multi-region ride-hailing platform connecting passengers with drivers (captains). It operates across Syria, Jordan, and Egypt. The platform supports multiple car types (Speed, Comfort, Family, Delivery, Electric, Van, Bike) with dynamic pricing via a "Kazan" percentage-based commission system.
### Core Ride-Hailing Workflow
1. Passenger requests ride → System searches nearby drivers → Driver accepts → Navigate to pickup → Ride begins → Ride completes → Payment processed → Rating submitted
### User Types
- **Passenger** (Rider) — Requests rides via siro_rider app
- **Driver** (Captain) — Accepts rides via siro_driver app
- **Admin** — Manages system via siro_admin app (Flutter Web/PWA)
- **Service Agent** — Manages driver registration via siro_service app
- **Employee** — Staff managing drivers, passengers, complaints
### Driver Types
| Type | Code | Description |
|------|------|-------------|
| Speed | Speed | Standard rides |
| Comfort | Comfort | Premium rides |
| Family | Family | Larger vehicle |
| Delivery | Delivery | Package delivery |
| Free/Blash | Blash | Economy |
| Late | Late | Off-peak |
| Heavy | Heavy | Cargo |
| Nature | Nature | Scenic routes |
| Electric | Electric | EV |
| Pink Bike | PinkBike | Motorcycle |
| Van | Van | Minibus |
| Female Driver | FemalDriver | Women-only |
### Payment Methods
- Cash
- Visa/Credit Card (PayMob)
- Wallet (internal balance)
- MTN Mobile Money
- Syriatel Mobile Money
- E-Cash
- Stripe
### External Integrations
| Service | Purpose |
|---------|---------|
| Google Maps | Map rendering, geocoding, routing |
| Here Maps | Place autocomplete |
| Map SaaS (intaleqapp.com) | Custom routing, reverse geocoding, places |
| OpenStreetMap (routec/routesy) | OSRM routing |
| Firebase | Push notifications, analytics, crashlytics |
| PayMob | Payment gateway |
| Twilio | SMS verification |
| WhatsApp Cloud API | OTP delivery |
| Azure OCR | Document scanning |
| OpenAI GPT | Document data extraction |
| Llama AI | Document data extraction |
| Agora | Voice/video calls |
| WebRTC | Signaling service |
| SMS Kazumi | SMS provider (Egypt) |
---
## System Modules
| Module | Purpose | Dependencies | Main Files |
|--------|---------|--------------|------------|
| **Authentication** | Login, signup, OTP, JWT management, Google/Apple auth | Firebase, Twilio, WhatsApp | `siro_rider/lib/controller/auth/*.dart`, `backend/auth/*.php` |
| **Dispatching** | Ride request → driver matching → offer → accept | WebSocket, MySQL GIS | `socket_intaleq/*.php`, `backend/ride/*.php` |
| **Matching** | Nearby driver search via spatial queries | MySQL SPATIAL indexes | `backend/ride/location/*.php` |
| **Maps & GIS** | Map rendering, routing, geocoding, driver tracking | Google Maps, Map SaaS, OSRM | `siro_rider/lib/controller/home/map/*.dart` |
| **Payments** | Ride payment, wallet, PayMob, MTN, Syriatel, E-Cash | PayMob, Stripe | `siro_rider/lib/controller/payment/*.dart`, `backend/ride/payment/*.php` |
| **Wallet** | Passenger & driver balance management | Payment server (walletintaleq.xyz) | `siro_rider/lib/controller/payment/passenger_wallet_history_controller.dart` |
| **Notifications** | Push (FCM), local, in-app notifications | Firebase | `siro_rider/lib/controller/firebase/*.dart` |
| **Chat** | In-app messaging between driver & passenger | PHP API | `backend/ride/chat/send_message.php` |
| **Rating** | Post-ride driver & passenger ratings | MySQL | `siro_rider/lib/controller/rate/*.dart`, `backend/ride/rate/*.php` |
| **Promotions** | Promo codes, referral rewards | MySQL | `siro_rider/lib/controller/home/profile/promos_controller.dart` |
| **AI Services** | OCR document scanning, data extraction | Azure OCR, OpenAI, Llama | `siro_rider/lib/controller/functions/crud.dart` (getLlama, getChatGPT, arabicTextExtractByVisionAndAI) |
| **Admin Functions** | Dashboard, driver/passenger management, analytics | All backend APIs | `siro_admin/lib/controller/admin/*.dart` |
| **Realtime Tracking** | WebSocket driver location streaming, passenger tracking | Socket.IO (PHP) | `socket_intaleq/*.php`, `siro_rider/lib/controller/home/map/map_socket_controller.dart` |
| **Referral System** | Unified referral codes for drivers & passengers | MySQL | `backend/migration_referral_system.sql`, `backend/ride/invitor/*.php` |
| **Complaints** | Post-ride issue resolution | MySQL | `siro_rider/lib/controller/home/profile/complaint_controller.dart`, `backend/Admin/AdminRide/` |
| **Emergency** | SOS signals, safety features | Agora, WebRTC | `siro_rider/lib/services/emergency_signal_service.dart` |
## Architecture Overview
```
┌─────────────────────────────────────────────────────┐
│ Mobile Apps (Flutter) │
│ ┌─────────────┐ ┌──────────────┐ ┌────────────┐ │
│ │ siro_rider │ │ siro_driver │ │ siro_admin │ │
│ │ (Passenger) │ │ (Captain) │ │ (Admin) │ │
│ └──────┬──────┘ └──────┬───────┘ └─────┬──────┘ │
└─────────┼─────────────────┼─────────────────┼────────┘
│ │ │
▼ ▼ ▼
┌─────────────────────────────────────────────────────┐
│ API Gateway (api.intaleq.xyz) │
│ ┌───────────┐ ┌──────────┐ ┌───────────────────┐ │
│ │ Auth API │ │ Ride API │ │ Payment API │ │
│ └───────────┘ └──────────┘ └───────────────────┘ │
└──────────────────────┬──────────────────────────────┘
┌──────────────────────┴──────────────────────────────┐
│ Backend Servers (PHP) │
│ ┌──────────┐ ┌──────────┐ ┌───────────────────┐ │
│ │ Main API │ │ Ride API │ │ Payment Server │ │
│ │ intaleq_v3│ │ rides. │ │ walletintaleq.xyz│ │
│ └──────────┘ └──────────┘ └───────────────────┘ │
│ ┌──────────┐ ┌──────────┐ ┌───────────────────┐ │
│ │ Location │ │ Socket │ │ Map SaaS │ │
│ │ location.│ │ rides. │ │ map-saas. │ │
│ └──────────┘ └──────────┘ └───────────────────┘ │
└──────────────────────┬──────────────────────────────┘
┌──────────────────────┴──────────────────────────────┐
│ MySQL Databases │
│ ┌────────────────┐ ┌─────────────────────┐ │
│ │ intaleqDB1 │ │ intaleq-ridesDB │ │
│ │ (Primary Main) │ │ (Ride-specific) │ │
│ └────────────────┘ └─────────────────────┘ │
└─────────────────────────────────────────────────────┘
```
## Tech Stack
| Layer | Technology |
|-------|-----------|
| Mobile | Flutter (Dart) with GetX state management |
| Backend | PHP (native, no framework) |
| Database | MySQL 8.0 with GIS (SPATIAL indexes, POINT columns) |
| Realtime | PHP WebSockets (Socket.IO compatible) |
| Maps | Google Maps (primary), Intaleq Maps (custom), OSRM routing |
| Payments | PayMob, custom wallet server |
| Auth | JWT, Firebase Auth, Google Sign-In, Apple Sign-In |
| Storage | GetStorage (local), FlutterSecureStorage |
| Push | Firebase Cloud Messaging (FCM) |

View File

@@ -0,0 +1,253 @@
# SYSTEM_ARCHITECTURE.md — Full System Architecture
## Layer Architecture
```
┌────────────────────────────────────────────────────────────────────┐
│ UI LAYER (Flutter Widgets) │
│ │
│ siro_rider: │
│ Routes: /, /shareApp, /wallet, /profile, /contactSupport │
│ Screens: SplashScreen, LoginPage, MapPagePassenger, Wallet, etc. │
│ │
│ siro_driver: │
│ Routes: /, /OrderRequestPage, /passenger-location-map │
│ Screens: SplashScreen, LoginPage, PassengerLocationMapPage, etc. │
│ │
│ siro_admin: │
│ Routes: /login, /admin/dashboard, /admin/captain, /admin/rides │
│ │
│ siro_service: │
│ Service agent app for driver registration & management │
└──────────────────────┬─────────────────────────────────────────────┘
│ GetX (Get.find, Get.put, Obx)
┌──────────────────────┴─────────────────────────────────────────────┐
│ STATE LAYER (GetX Controllers) │
│ │
│ Controllers are registered in: AppBindings (permanent) │
│ │
│ Rider: │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ MapEngineController → Map rendering, camera, markers │ │
│ │ MapSocketController → WebSocket lifecycle management │ │
│ │ RideLifecycleController → Ride state machine (RideState enum)│ │
│ │ LocationSearchController → Place search & autocomplete │ │
│ │ NearbyDriversController → Nearby driver list management │ │
│ │ UiInteractionsController → Bottom sheets, dialogs │ │
│ │ LoginController → Auth & JWT management │ │
│ │ PaymentController → Payment processing │ │
│ │ SplashScreenController → App init & auth check │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ Driver: │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ HomeCaptainController → Online/offline, ride management │ │
│ │ MapSocketController → WebSocket ride offers │ │
│ │ NavigationController → Turn-by-turn navigation │ │
│ │ BackgroundServiceHelper → Android foreground service │ │
│ │ LocationController → GPS tracking │ │
│ └─────────────────────────────────────────────────────────────┘ │
└──────────────────────┬─────────────────────────────────────────────┘
│ Dependency Injection via GetX
┌──────────────────────┴─────────────────────────────────────────────┐
│ REPOSITORY LAYER (CRUD + Services) │
│ │
│ CRUD class (siro_rider/lib/controller/functions/crud.dart) │
│ - post() → Main API POST with JWT + Device-FP headers │
│ - get() → API GET (POST method) with retry logic │
│ - postWallet() → Payment server POST with JWT + HMAC + FP │
│ - getWallet() → Payment server GET with JWT + HMAC + FP │
│ - sendWhatsAppAuth() → WhatsApp OTP delivery │
│ - getAgoraToken() → Agora voice/video call tokens │
│ - getLlama() → Llama AI data extraction │
│ - getChatGPT() → OpenAI GPT data extraction │
│ - arabicTextExtractByVisionAndAI() → Azure OCR │
│ - getGoogleApi() → Google Maps API wrapper │
│ - getHereMap() → Here Maps API wrapper │
│ - getMapSaas()/postMapSaas() → Custom map service │
│ - sendVerificationRequest() → Twilio verification │
│ - postPayMob() → PayMob payment gateway │
│ │
│ NetGuard (network/connection_check.dart) → Internet monitoring │
└──────────────────────┬─────────────────────────────────────────────┘
│ HTTP Calls
┌──────────────────────┴─────────────────────────────────────────────┐
│ SERVICE LAYER (PHP Backend) │
│ │
│ Main API: api.intaleq.xyz/intaleq_v3 │
│ Ride API: rides.intaleq.xyz/intaleq │
│ Location API: location.intaleq.xyz/intaleq/ride/location │
│ Payment API: walletintaleq.intaleq.xyz/v2/main │
│ Map SaaS: map-saas.intaleqapp.com/api │
│ OSRM Route: routec.intaleq.xyz / routesy.intaleq.xyz │
└──────────────────────┬─────────────────────────────────────────────┘
│ MySQL + WebSocket
┌──────────────────────┴─────────────────────────────────────────────┐
│ DATA LAYER (MySQL Databases) │
│ │
│ Database: intaleqDB1 (primary) │
│ Database: intaleq-ridesDB (ride-specific) │
│ Tables: 60+ tables covering users, rides, payments, etc. │
└─────────────────────────────────────────────────────────────────────┘
```
---
## Dependency Graph
```
Rider App (siro_rider) ───→ Main API ─────→ intaleqDB1
├──→ Map SaaS ───────→ Custom Map Service
├──→ OSRM ───────────→ OpenStreetMap
├──→ Payment API ────→ Wallet DB
├──→ Firebase ───────→ FCM
├──→ WebSocket ──────→ Ride Socket Server
└──→ Google Maps ────→ Google APIs
Driver App (siro_driver) ───→ Main API ─────→ intaleqDB1
├──→ Location API ───→ car_locations
├──→ Payment API ────→ Wallet DB
├──→ WebSocket ──────→ Driver Socket Server
├──→ Firebase ───────→ FCM
└──→ Google Maps ────→ Google APIs
Admin App (siro_admin) ────→ Main API ─────→ intaleqDB1
├──→ Payment API
├──→ Firebase
└──→ Internal Services
Socket Server (socket_intaleq) ──→ MySQL
├──→ driver_socket.php ──→ Driver Socket.IO
└──→ passenger_socket.php ──→ Passenger Socket.IO
Ride Server (rides.intaleq.xyz) ──→ MySQL (intaleq-ridesDB)
Location Server (location.intaleq.xyz) ──→ MySQL (car_locations)
Payment Server (walletintaleq.intaleq.xyz) ──→ Wallet MySQL
```
---
## External Services
| Service | Integration Point | Auth Method | Purpose |
|---------|-----------------|-------------|---------|
| **Google Maps** | `https://maps.googleapis.com/maps/api/` | API Key | Map rendering, geocoding |
| **Here Maps** | `https://autosuggest.search.hereapi.com/v1/autosuggest` | API Key | Place autocomplete |
| **Map SaaS** | `https://map-saas.intaleqapp.com/api/` | x-api-key | Custom routing, geocoding |
| **OSRM Server** | `https://routec.intaleq.xyz/route` | None | OpenStreetMap routing |
| **Firebase** | Firebase SDK | google-services.json | FCM, Analytics, Crashlytics |
| **PayMob** | PayMob SDK | API Key + HMAC | Payment gateway (Visa/Mastercard) |
| **Twilio** | Twilio Verify API | Account SID + Auth Token | SMS OTP verification |
| **WhatsApp Cloud** | Graph API | OAuth Token | WhatsApp OTP delivery |
| **Azure OCR** | `https://ocrhamza.cognitiveservices.azure.com/` | Subscription Key | Document text extraction |
| **OpenAI** | OpenAI API | API Key | Document data extraction (GPT-3.5) |
| **Llama AI** | Llama API | Bearer Token | Document data extraction |
| **Agora** | Agora SDK | App Certificate | Voice/video calls |
| **SMS Kazumi** | `https://sms.kazumi.me/api/` | API Key | SMS provider (Egypt) |
---
## Security Architecture
### Authentication
| Mechanism | Implementation |
|-----------|---------------|
| **JWT** | Custom JWT tokens issued at login, validated on each request |
| **Fingerprint** | Device fingerprint hashed with SHA-256, stored in JWT payload |
| **HMAC** | HMAC authentication for payment server requests |
| **Bearer Tokens** | Standard Bearer token in Authorization header |
| **Social Auth** | Google Sign-In, Apple Sign-In |
### Authorization
- **Role-based**: Passenger, Driver, Admin, Service Agent
- **Device Binding**: X-Device-FP header verified against JWT fingerprint claim
- **Wallet Auth**: Separate JWT + HMAC for payment operations
### Token Handling
| Token | Storage | Expiry | Refresh |
|-------|---------|--------|---------|
| JWT (main) | GetStorage | 1 hour (default) | `getJWT()` auto-refresh on 401 |
| JWT (wallet) | GetStorage | 1 hour | `getJwtWallet()` auto-refresh |
| FCM Token | GetStorage + DB | Firebase-managed | On app start |
| Refresh Token | FlutterSecureStorage | Long-lived | On login |
### Encryption
- **AES-256-CBC**: Custom encrypt/decrypt for sensitive data
- **SHA-256**: Device fingerprint hashing
- **Base64**: Basic auth credentials encoding
- **SSL/TLS**: All API calls over HTTPS
### Secure Storage
| Data | Storage Method |
|------|---------------|
| JWT tokens | GetStorage (encrypted box) |
| Refresh tokens | FlutterSecureStorage (Keychain/Keystore) |
| Fingerprint | GetStorage (encrypted) |
| HMAC keys | GetStorage (encrypted) |
### Session Management
- Auto-logout on token expiry (401 response)
- Fingerprint migration tools in admin panel
- Login attempt rate limiting (`login_attempts` table)
---
## Caching Strategy
| Cache Type | Implementation | Data Cached |
|-----------|---------------|-------------|
| **GetStorage** (Local) | Key-value store in app sandbox | JWT, user ID, preferences, ride state |
| **FlutterSecureStorage** | OS-level encrypted storage | Refresh tokens, sensitive data |
| **SQLite (DbSql)** | Local SQLite database | Offline maps, ride history |
| **Memory Cache** | GetX controller state | Active ride data, driver list, map markers |
| **Server Cache** | MySQL + Query Cache | Driver locations (car_locations), places |
| **In-Memory (NetGuard)** | Singleton notification state | Network error debouncing |
---
## WebSocket Architecture
```
┌──────────────┐ ┌──────────────────┐ ┌──────────────┐
│ Rider App │◄───────►│ Passenger Socket │◄───────►│ MySQL DB │
│ │ │ (PHP) │ │ │
└──────────────┘ └──────────────────┘ └──────────────┘
│ (Internal IPC)
┌──────────────┐ ┌──────────────────┐ ┌──────────────┐
│ Driver App │◄───────►│ Driver Socket │◄───────►│ MySQL DB │
│ │ │ (PHP) │ │ │
└──────────────┘ └──────────────────┘ └──────────────┘
```
**Socket Events:**
- `driver_location_update` — Real-time driver GPS to passenger
- `ride_accepted` — Driver accepted notification
- `ride_cancelled` — Ride cancellation event
- `ride_finished` — Ride completion event
- `passenger_location` — Passenger location (for driver)
- `driver_online` / `driver_offline` — Online status changes
---
## Admin Module Structure
| Module | Controller | Views |
|--------|-----------|-------|
| Dashboard | `DashboardController`, `DashboardV2Controller` | `admin_home_page.dart` |
| Captain Management | `CaptainAdminController` | `captain.dart`, `captain_details.dart` |
| Passenger Management | `PassengerAdminController` | `passenger.dart`, `passenger_details_page.dart` |
| Ride Management | `RideAdminController`, `RideLookupController` | `rides.dart`, `ride_lookup_page.dart` |
| Financial | `FinancialV2Controller` | `financial_v2_page.dart` |
| Analytics | `AnalyticsV2Controller`, `StaticController` | `advanced_analytics_page.dart` |
| Complaints | `ComplaintController` | `complaint_list_page.dart` |
| Pricing/Kazan | `KazanController` | `kazan_editor_page.dart` |
| Promotions | `PromoController` | `promo_management_page.dart` |
| Wallet | `WalletAdminController` | `wallet.dart` |
| Driver Docs | `DriverDocsController` | `driver_documents_review_page.dart` |
| Security | `SecurityV2Controller` | `audit_logs_page.dart` |
| Quality | `QualityController` | `blacklist_page.dart`, `driver_scorecard_page.dart` |
| Staff | `StaffController` | `add_staff_page.dart`, `pending_admins_page.dart` |
| Server Monitor | `ServerMonitorController` | `monitor_server_page.dart` |
| Invoices | `GetAllInvoiceController` | `invoice_list_page.dart` |