Skip to content

JLSS-virtual/PlaceLive-Geofencing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

PlaceLive-Geofencing

🌍 Real-time Location Intelligence & Geofencing Microservice

Overview

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.

πŸš€ Key Features

Core Geofencing Capabilities

  • 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

Business Intelligence

  • 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

Technical Excellence

  • 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

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Mobile Apps   │────│  API Gateway     │────│  Geofencing     β”‚
β”‚  (Android/iOS)  β”‚    β”‚                  β”‚    β”‚   Service       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                         β”‚
                                                         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  ElasticSearch  │────│   MySql     │────│  Common Library β”‚
β”‚  (Place Search) β”‚    β”‚ (Geofence Data)  β”‚    β”‚  (Generic CRUD) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Technology Stack

  • 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

πŸ“Š Data Flow Architecture

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)

πŸ”§ Quick Start

Prerequisites

  • Java 11 or higher
  • Maven 3.6+
  • MySql 8+
  • ElasticSearch 7.x
  • Docker (optional)

Installation

  1. Clone the repository

    git clone https://github.com/JLSS-virtual/PlaceLive-Geofencing.git
    cd PlaceLive-Geofencing
  2. Configure database

    # application.properties
    spring.datasource.url=jdbc:postgresql://localhost:5432/placelive_geofencing
    spring.datasource.username=your_username
    spring.datasource.password=your_password
  3. Configure ElasticSearch

    elasticsearch.host=localhost
    elasticsearch.port=9200
  4. Run the application

    ./mvnw spring-boot:run

Docker Deployment

docker build -t placelive-geofencing .
docker run -p 8082:8082 placelive-geofencing

🌐 API Documentation

Core Endpoints

Geofence Management

POST /api/v1/geofences
Content-Type: application/json

{
  "placeId": "12345",
  "centerLat": 40.7128,
  "centerLng": -74.0060,
  "radius": 250,
  "isActive": true
}

Place Search with Friends

GET /api/v1/places/search-with-friends?query=coffee&userId=67890

Real-time Location Updates

POST /api/v1/location/update
Content-Type: application/json

{
  "userId": "67890",
  "latitude": 40.7128,
  "longitude": -74.0060,
  "timestamp": "2024-01-01T12:00:00Z"
}

Response Examples

Enhanced Place Results

{
  "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!"
    }
  ]
}

πŸš€ Advanced Features

Battery & Data Optimization

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

Psychological Messaging System

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

Traffic-Based Bidding

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

πŸ”’ Security & Privacy

Privacy Controls

  • 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

Data Protection

  • 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

πŸ“ˆ Performance Metrics

Scalability Targets

  • Concurrent Users: 1M+ simultaneous active users
  • Response Time: <200ms for geofence queries
  • Throughput: 10K+ location updates per second
  • Availability: 99.9% uptime SLA

Optimization Features

  • 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

πŸ› οΈ Development

Code Structure

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

Key Components

GeofenceService

  • Main business logic for geofence operations
  • Integration with ElasticSearch for place discovery
  • Friend visibility and privacy enforcement

LocationTrackingService

  • Real-time location processing
  • Battery optimization algorithms
  • Entry/exit event detection

MessagingService

  • Psychological message generation
  • Sponsorship integration
  • Traffic pattern analysis

πŸ”„ Integration

With Other PlaceLive Services

User Service Integration

@Autowired
private UserServiceClient userServiceClient;

public List<User> getActiveFriends(String userId) {
    return userServiceClient.getFollowers(userId);
}

Tracker Service Integration

@Autowired
private TrackerServiceClient trackerServiceClient;

public List<TrackerEntry> getActiveUsers(List<String> geofenceIds) {
    return trackerServiceClient.findActiveInGeofences(geofenceIds);
}

πŸ“Š Monitoring & Analytics

Health Metrics

  • 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

Business Intelligence

  • 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

πŸš€ Future Roadmap

Phase 1: Enhanced AI

  • Emotion Detection: Analyze user mood for personalized messages
  • Predictive Analytics: Forecast user movement patterns
  • Smart Notifications: AI-driven optimal notification timing

Phase 2: Advanced Features

  • Indoor Geofencing: Support for mall and building-level tracking
  • AR Integration: Augmented reality place discovery
  • Voice Commands: Voice-activated place search and friend requests

Phase 3: Global Scale

  • Multi-Region Support: Worldwide deployment architecture
  • Language Localization: Support for multiple languages
  • Cultural Adaptation: Region-specific messaging strategies

🀝 Contributing

We welcome contributions to PlaceLive-Geofencing! Please see our Contributing Guidelines for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Coding Standards

  • Follow Java naming conventions
  • Write comprehensive unit tests
  • Document all public APIs
  • Use meaningful commit messages

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support


PlaceLive-Geofencing: Revolutionizing location-aware experiences through intelligent geofencing and social connectivity. 🌍✨

About

A Live location tracker, less battery usage, accurate location and co-ordinate data. Aim to compete Google.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors