# 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)