Skip to content

vivek-0509/Travel_Sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

103 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Travel Sync

Smart travel companion platform connecting students with compatible co-travelers through intelligent matching algorithms.


πŸ“– Overview

Travel Sync helps students find compatible travel companions by intelligently matching their journey details, schedules, and preferences. Post your travel plans, discover matching co-travelers, and coordinate journeys seamlessly.

✨ Key Features

  • πŸ” Secure Google OAuth 2.0 authentication with JWT sessions
  • 🎫 Travel Ticket Management - Create, update, and manage trip details
  • πŸ€– Smart Recommendation Engine - Implemented Greedy algorithm with scoring
  • πŸ›‘οΈ Multi-tier Rate Limiting - Protection against abuse
  • πŸ“± Real-time Status Updates - Open/closed ticket management
  • πŸ”’ Privacy-First Design - Redacted IDs, minimal data exposure

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Frontend (Client)                   β”‚
β”‚            HTTP + Cookies (JWT)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         Middleware Layer                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ CORS β”‚  β”‚   JWT   β”‚  β”‚  Rate Limiting   β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”˜  β”‚  Auth   β”‚  β”‚ (3-tier system)  β”‚   β”‚
β”‚            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Handlers β†’ Services β†’ Repositories            β”‚
β”‚                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚ Auth        β”‚  β”‚  Recommendation       β”‚    β”‚
β”‚  β”‚ Service     β”‚  β”‚  Engine (Scoring)     β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚           PostgreSQL (GORM)                      β”‚
β”‚     Users | Travel Tickets | Sessions           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Layered Design Benefits

  • Separation of Concerns - Each layer handles specific responsibilities
  • Testability - Mock dependencies for unit testing
  • Scalability - Easy to extend and modify
  • Maintainability - Clear code organization

πŸ’» Tech Stack

Category Technology
Backend Go, Gin Framework
Database PostgreSQL , GORM
Auth Google OAuth 2.0, JWT (golang-jwt)
Security HTTP-only Cookies, CORS, Rate Limiting
Rate Limiting ulule/limiter (in-memory)

πŸ”’ Security Implementation

OAuth 2.0 + JWT Flow

sequenceDiagram
    User->>+Server: GET /auth/google/login
    Server->>+Google: Redirect to OAuth
    Google->>+User: Authorization Page
    User->>+Google: Grant Permission
    Google->>+Server: Callback with code
    Server->>+Server: Verify State (CSRF)
    Server->>+Server: Generate JWT
    Server->>+User: Set HTTP-only Cookie
    User->>+Server: Authenticated Requests
Loading

Security Features

βœ… HTTP-only Cookies - Prevents XSS attacks
βœ… CSRF Protection - OAuth state parameter validation
βœ… JWT Validation - Signature verification on every request
βœ… Rate Limiting - Prevents brute force attacks
βœ… Ownership Checks - Users can only modify their own data
βœ… Input Sanitization - Validates all user inputs

JWT Details:

  • Algorithm: HS256
  • Expiration: 8 days
  • Claims: user_id, email, standard claims
  • Storage: HTTP-only cookie (jwt_token)

⚑ Rate Limiting Strategy

Three-tier protection system:

Tier Limit Burst Applied To
General 100/hour 200 All routes
Auth 5/minute 10 Login/Auth endpoints
Recommendations 20/minute 30 Recommendation engine

Key Strategy:

  • Authenticated: prefix:uid:<user_id>
  • Unauthenticated: prefix:<client_ip>

Response Headers:

X-RateLimit-Limit: 20
X-RateLimit-Remaining: 15
X-RateLimit-Reset: 1729684800

🎯 Recommendation Engine

Smart matching algorithm with multi-factor scoring:

Matching Logic

1. Route Matching

  • Exact source and destination match

2. Asymmetric Time Window

Target: 14:00, flexibility: Β±30 mins

Acceptable Range:
β”œβ”€ Before: 13:30 - 14:00 (configurable)
└─ After:  14:00 - 15:00 (fixed 60 mins)

3. Status Filtering

  • Only status: "open" tickets
  • Excludes user's own tickets

Scoring Algorithm

Score = (time_proximity Γ— 0.5) + 
        (seat_availability Γ— 0.3) + 
        (batch_similarity Γ— 0.2)

Result Tiers:

  • best_match - Highest scored recommendation
  • best_group - Optimal group formation
  • other_alternatives - Additional options

Privacy Protection: Redacts ticket.id and user_id in responses


πŸš€ Quick Start

Prerequisites

  • Go 1.21+
  • PostgreSQL
  • Google OAuth credentials

Installation

  1. Clone the repository
git clone https://github.com/yourusername/travel-sync.git
cd travel-sync
  1. Configure environment
cp .env.example .env
# Edit .env with your credentials

.env file:

PORT=8080
DATABASE_URL=postgres://user:pass@localhost:5432/travel_sync?sslmode=disable
JWT_SECRET=your_secret_key_min_32_chars
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
FRONTEND_URL=http://localhost:3000
  1. Install dependencies
go mod download
  1. Run the server
go run ./cmd
  1. Health check
curl http://localhost:8080/health
# Response: {"status":"healthy","message":"Travel Sync API is running"}

πŸ“š API Endpoints

Authentication

GET  /auth/google/login          # Initiate Google OAuth
GET  /auth/google/callback       # OAuth callback
GET  /auth/me                    # Get current user (protected)
POST /auth/logout                # Clear session

Travel Tickets

POST   /api/travel                    # Create ticket
GET    /api/travel                    # List all tickets
GET    /api/travel/my                 # Get my tickets
GET    /api/travel/:id                # Get ticket by ID
PUT    /api/travel/:id                # Update ticket
DELETE /api/travel/:id                # Delete ticket
GET    /api/travel/:id/recommendations # Get matches (rate limited)

Example: Create Ticket

curl -X POST http://localhost:8080/api/travel \
  -H "Content-Type: application/json" \
  -b "jwt_token=your_token" \
  -d '{
    "source": "BLR",
    "destination": "GOI",
    "departure_at": "2025-10-01T14:30:00Z",
    "time_diff_mins": 30,
    "empty_seats": 2,
    "phone_number": "9876543210"
  }'

Response:

{
  "success": true,
  "data": {
    "id": 10,
    "source": "BLR",
    "destination": "GOI",
    "status": "open",
    "departure_at": "2025-10-01T14:30:00Z"
  }
}

Complete API documentation: API_REFERENCE.md


πŸ“ Project Structure

travel-sync/
β”œβ”€β”€ cmd/                    # Application entry point
β”‚   └── main.go
β”œβ”€β”€ internal/               # Private application code
β”‚   β”œβ”€β”€ middleware/         # CORS, rate limiting
β”‚   β”œβ”€β”€ security/           # OAuth, JWT, auth handlers
β”‚   β”œβ”€β”€ travel/             # Travel domain logic
β”‚   β”‚   β”œβ”€β”€ handlers/       # HTTP handlers
β”‚   β”‚   β”œβ”€β”€ services/       # Business logic + recommendation engine
β”‚   β”‚   β”œβ”€β”€ repositories/   # Data access
β”‚   β”‚   └── models/         # Data models
β”‚   β”œβ”€β”€ user/               # User management
β”‚   └── server/             # Server configuration
β”œβ”€β”€ docs/                   # Documentation
β”œβ”€β”€ .env                    # Environment variables
β”œβ”€β”€ go.mod                  # Go dependencies
└── README.md

🎨 Architecture Visualization

Technology Stack

Frontend Backend Database Security
React Go PostgreSQL JWT
React Gin Framework PostgreSQL JWT Auth

Key Components

πŸ” Authentication System

  • Google OAuth 2.0 Integration
  • JWT Token Management
  • HTTP-only Cookie Storage
  • CSRF Protection

πŸ€– Recommendation Engine

  • Multi-factor Scoring Algorithm
  • Asymmetric Time Windows
  • Privacy-First Results
  • Real-time Matching

⚑ Rate Limiting

  • 3-Tier Protection System
  • Per-user & Per-IP Tracking
  • Burst Capacity Support
  • Header-based Feedback

🎫 Ticket Management

  • CRUD Operations
  • Ownership Validation
  • Status Tracking
  • Duplicate Prevention

Note: Add your application screenshots here by uploading them to your repository in a /docs/images/ folder


πŸ”§ Configuration Options

Variable Description Required
PORT Server port Yes
DATABASE_URL PostgreSQL connection Yes
JWT_SECRET JWT signing key (min 32 chars) Yes
GOOGLE_CLIENT_ID OAuth client ID Yes
GOOGLE_CLIENT_SECRET OAuth secret Yes
FRONTEND_URL Frontend URL for redirects Yes

πŸ“ˆ Performance & Scalability

  • In-memory Rate Limiting - Fast, per-instance tracking
  • GORM Query Optimization - Efficient database access
  • Layered Architecture - Easy horizontal scaling
  • Auto-migrations - Seamless schema updates

🀝 Contributing

Contributions welcome! Please:

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

About

Find your travel buddy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages