π Real-time Location Intelligence & Geofencing Microservice
PlaceLive-Geofencing is the core location intelligence engine for the PlaceLive ecosystem, responsible for real-time geofence detection, dynamic place radius calculations, and powering the revolutionary shop sponsorship model. This microservice detects when users enter/exit dynamically-calculated areas around "sponsored" places, enabling hyperlocal, privacy-preserving alerts that transform how people discover and interact with nearby businesses.
- Dynamic Geofence Creation: Automatically generate and manage geofences per place with customizable parameters
- Real-time Entry/Exit Detection: Instant detection when users cross geofence boundaries with millisecond precision
- Adaptive Range Control: Smart radius calculations (200-500m) based on place type, traffic patterns, and user behavior
- Battery-Optimized Logic: Client-side pre-filtering and intelligent update intervals to preserve mobile battery life
- Privacy-First Architecture: Honor user permissions, friend circles, and visibility controls
- Shop Sponsorship Integration: Enable businesses to "go live" and appear in user recommendations within geofenced areas
- Traffic Pattern Analysis: Monitor usage patterns for different places during various time periods (morning, noon, night)
- Bid-Based Messaging System: Support competitive bidding for place visibility based on distance and timing
- Psychological Messaging Engine: Deliver carefully crafted positive messages that build trust without revealing direct pricing
- ElasticSearch Integration: Lightning-fast place search using multiMatch queries across multiple fields
- Scalable Architecture: Built to handle millions of concurrent users with efficient database queries
- Generic CRUD Foundation: Extends PlaceLive's common-library for accelerated development
- Container-Ready: Full Docker support for seamless deployment
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Mobile Apps ββββββ API Gateway ββββββ Geofencing β
β (Android/iOS) β β β β Service β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β
βΌ
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β ElasticSearch ββββββ MySql ββββββ Common Library β
β (Place Search) β β (Geofence Data) β β (Generic CRUD) β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
- Framework: Spring Boot 2.x with Spring Data JPA
- Database: PostgreSQL with spatial extensions
- Search Engine: ElasticSearch for place discovery
- Architecture: Microservice with RESTful APIs
- Deployment: Docker containerization
- Integration: Event-driven communication via REST/Kafka
User Input: query, userId
|
βΌ
Search places from ElasticSearch (multiMatch on fields)
|
βΌ
for each place:
βββΊ Get Geofences for place β [geofenceRepo.findByPlaceId]
β ββ If no geofence β continue
β
βββΊ Get user by ID β [userRepo.findById]
β ββ If user not found β continue
β
βββΊ Get follower IDs from user.getFollowers()
β ββ If empty β continue
β
βββΊ Find Tracker entries β [trackerRepo.findByGeofenceIdInAndUserIdInAndIsUserInTrue]
β ββ Get active friend IDs from Tracker entries
β ββ If none β continue
β
βββΊ Get UserDocuments for activeFriendIds β [userRepo.findAllById]
β
βββΊ Add to enhancedResults: new PlaceWithFriendsDTO(place, activeFriends)
- Java 11 or higher
- Maven 3.6+
- MySql 8+
- ElasticSearch 7.x
- Docker (optional)
-
Clone the repository
git clone https://github.com/JLSS-virtual/PlaceLive-Geofencing.git cd PlaceLive-Geofencing -
Configure database
# application.properties spring.datasource.url=jdbc:postgresql://localhost:5432/placelive_geofencing spring.datasource.username=your_username spring.datasource.password=your_password
-
Configure ElasticSearch
elasticsearch.host=localhost elasticsearch.port=9200
-
Run the application
./mvnw spring-boot:run
docker build -t placelive-geofencing .
docker run -p 8082:8082 placelive-geofencingPOST /api/v1/geofences
Content-Type: application/json
{
"placeId": "12345",
"centerLat": 40.7128,
"centerLng": -74.0060,
"radius": 250,
"isActive": true
}GET /api/v1/places/search-with-friends?query=coffee&userId=67890POST /api/v1/location/update
Content-Type: application/json
{
"userId": "67890",
"latitude": 40.7128,
"longitude": -74.0060,
"timestamp": "2024-01-01T12:00:00Z"
}{
"results": [
{
"place": {
"id": "12345",
"name": "Best Coffee Shop",
"latitude": 40.7128,
"longitude": -74.0060,
"category": "cafe"
},
"activeFriends": [
{
"userId": "friend1",
"username": "john_doe",
"lastSeen": "2024-01-01T11:45:00Z"
}
],
"sponsorshipMessage": "Great coffee, perfect for study sessions!"
}
]
}The service implements several techniques to minimize mobile resource usage:
- Smart Location Sharing: Only transmit data when user is moving rapidly
- Client-Side Analysis: Pre-process location data on device before transmission
- Adaptive Caching: Cache more data on high-performance devices
- Periodic Updates: Use compounding algorithms to reduce backend calls
- Intelligent Batching: Group location updates to minimize network overhead
Messages are crafted to provide positive hints without revealing sensitive information:
- "Price is low" - Budget-friendly without mentioning quality concerns
- "Price is low and quality is awesome" - When sellers are confident
- "Quality is high" - Premium without mentioning higher prices
- "Great for daily use" - Practical and affordable
The system analyzes store usage patterns to optimize sponsorship timing:
- Morning Traffic: Coffee shops, breakfast places
- Noon Traffic: Restaurants, lunch spots
- Night Traffic: Bars, entertainment venues
- Dynamic Pricing: Closer distance = higher bidding requirements
- Friend Circle Restrictions: Only visible to approved followers
- Place-Specific Visibility: Different privacy levels per location type
- Role-Based Access: Parents can monitor children's locations
- Opt-Out Options: Users control their visibility status
- Encrypted Communication: All API calls use HTTPS/TLS
- Minimal Data Retention: Location data cleaned up after sessions
- Anonymized Analytics: Business insights without personal identification
- GDPR Compliance: Full user data control and deletion rights
- Concurrent Users: 1M+ simultaneous active users
- Response Time: <200ms for geofence queries
- Throughput: 10K+ location updates per second
- Availability: 99.9% uptime SLA
- Database Indexing: Spatial indexes for fast proximity queries
- Caching Strategy: Redis for frequently accessed geofences
- Load Balancing: Horizontal scaling across multiple instances
- Circuit Breakers: Resilience4j for fault tolerance
src/
βββ main/java/com/placelive/geofencing/
β βββ controller/ # REST API endpoints
β βββ service/ # Business logic layer
β βββ repository/ # Data access layer
β βββ model/ # Entity definitions
β βββ dto/ # Data transfer objects
β βββ config/ # Configuration classes
β βββ util/ # Utility classes
βββ main/resources/
β βββ application.yml # Configuration
β βββ db/migration/ # Database scripts
βββ test/ # Unit and integration tests
- Main business logic for geofence operations
- Integration with ElasticSearch for place discovery
- Friend visibility and privacy enforcement
- Real-time location processing
- Battery optimization algorithms
- Entry/exit event detection
- Psychological message generation
- Sponsorship integration
- Traffic pattern analysis
@Autowired
private UserServiceClient userServiceClient;
public List<User> getActiveFriends(String userId) {
return userServiceClient.getFollowers(userId);
}@Autowired
private TrackerServiceClient trackerServiceClient;
public List<TrackerEntry> getActiveUsers(List<String> geofenceIds) {
return trackerServiceClient.findActiveInGeofences(geofenceIds);
}- Geofence Coverage: Percentage of places with active geofences
- User Engagement: Entry/exit events per day
- Sponsorship Performance: Click-through rates on sponsored messages
- System Performance: Response times, error rates, throughput
- Popular Places: Most visited locations by time of day
- User Movement Patterns: Common routes and destinations
- Sponsorship ROI: Revenue generated per sponsored location
- Engagement Analytics: Friend discovery success rates
- Emotion Detection: Analyze user mood for personalized messages
- Predictive Analytics: Forecast user movement patterns
- Smart Notifications: AI-driven optimal notification timing
- Indoor Geofencing: Support for mall and building-level tracking
- AR Integration: Augmented reality place discovery
- Voice Commands: Voice-activated place search and friend requests
- Multi-Region Support: Worldwide deployment architecture
- Language Localization: Support for multiple languages
- Cultural Adaptation: Region-specific messaging strategies
We welcome contributions to PlaceLive-Geofencing! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow Java naming conventions
- Write comprehensive unit tests
- Document all public APIs
- Use meaningful commit messages
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Wiki
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: jlss.virtual.0808@gmail.com
PlaceLive-Geofencing: Revolutionizing location-aware experiences through intelligent geofencing and social connectivity. πβ¨