# Remote database and Google Maps setup

## Remote database schema

Apply the SQL file below in your remote PostgreSQL database before starting the API:

- `docs/remote-schema.sql`

This file was generated from the Prisma schema and is the bootstrap source for `bdgs6653_chegoou`.

## Required environment variables

Use these files as the base:

- `.env.example`
- `apps/api/.env.example`

Database variables already target:

- database: `bdgs6653_chegoou`
- user: `bdgs6653_bruno`

You still need to fill:

- `DB_HOST`
- `DB_PASSWORD`
- `REDIS_URL`
- `JWT_ACCESS_SECRET`
- `JWT_REFRESH_SECRET`
- `GOOGLE_MAPS_API_KEY`

## Google services to enable

Enable these APIs in the same Google Cloud project used by `GOOGLE_MAPS_API_KEY`:

- Maps JavaScript API
- Geocoding API
- Directions API
- Distance Matrix API
- Routes API

## Current backend integration

The API uses Google services in:

- `apps/api/src/maps/maps.service.ts`
- `apps/api/src/tracking/tracking.service.ts`

Current behavior:

- geocodes restaurant and customer addresses when coordinates are missing
- calculates route polyline and ETA using Google Routes API when available
- falls back to Directions API if Routes API is unavailable
- falls back to local haversine math if `GOOGLE_MAPS_API_KEY` is not configured
- uses Distance Matrix API for matrix travel estimates

## Recommended bootstrap order

1. Confirm the remote PostgreSQL database `bdgs6653_chegoou` is reachable.
2. Apply `docs/remote-schema.sql`.
3. Copy `.env.example` to `.env`.
4. Fill `DB_HOST` and `DB_PASSWORD` in `.env` and `apps/api/.env`.
5. Start Redis.
6. Run the API.

## Frontend maps next step

The next production step is wiring the live map screens to:

- Google Maps JavaScript on `web-admin`
- Google Maps JavaScript on `web-restaurant`
- `react-native-maps` plus websocket feeds on `mobile-customer` and `mobile-driver`
