The Location Service manages location-related functionality for the Commune Drop platform. It tracks user and carrier locations, calculates distances and routes, handles geocoding, and provides real-time location updates for order tracking.
- Real-time location tracking for users and carriers
- Distance and ETA calculations between locations
- Geocoding and reverse geocoding
- Route optimization
- Location history storage
- Geofencing for delivery zones
- Address validation and normalization
- Auth Service: For user authentication and authorization
- Order Service: For order location details
- Notification Service: For location-based alerts
- External Map Services: For geocoding and routing (Google Maps, Mapbox, etc.)
- Runtime: Node.js
- Framework: Express.js
- Database: MongoDB with geospatial indexes
- Real-time: Socket.io / WebSockets
- Caching: Redis
- External APIs: Google Maps / Mapbox / OpenStreetMap
- Node.js v16+
- MongoDB
- Redis
- Map service API keys
- Clone the repository
git clone https://github.com/commune-drop/location-service.git
cd location-service
- Install dependencies
npm install
- Configure environment variables
cp .env.example .env
# Edit .env with your configuration
- Start the service
npm start
For development:
npm run dev
Key environment variables:
PORT=3002
MONGODB_URI=mongodb://localhost:27017/location-service
AUTH_SERVICE_URL=http://auth-service:3000
ORDER_SERVICE_URL=http://order-service:3001
NOTIFICATION_SERVICE_URL=http://notification-service:3005
GOOGLE_MAPS_API_KEY=your_google_maps_api_key
MAPBOX_API_KEY=your_mapbox_api_key
LOCATION_UPDATE_INTERVAL=10000
LOCATION_HISTORY_RETENTION_DAYS=30
- Proximity search for nearby carriers
- Polygon-based delivery zones
- Heatmaps for demand analysis
- Traffic-aware routing
- Location clustering
Key data structures include:
- User locations
- Carrier locations
- Location history
- Delivery zones
- Address data
The service provides real-time location updates via:
- WebSockets for live tracking
- Server-sent events for status updates
- Pub/sub for internal service communication
The service publishes these events:
location.updatedlocation.entered_zonelocation.exited_zonecarrier.nearbyeta.updated
- Location data is encrypted at rest
- User consent required for location tracking
- Configurable location precision
- Automatic data purging based on retention policy
MIT