This repository demonstrates how to integrate Samsara's Connected Operations Platform with a Transportation Management System (TMS). It showcases key integration patterns and best practices for building a modern TMS that leverages Samsara's real-time location tracking, driver safety features, and form management capabilities.
- Real-time Location Tracking: Live tracking of vehicles and drivers using Samsara's live sharing URLs
- Driver Safety: Integration with Samsara's driver safety features and alerts
- Form Management: Dynamic form templates that sync with Samsara's form system
- Webhook Integration: Real-time event processing from Samsara's webhook system
- OAuth Authentication: Secure authentication with Samsara's OAuth system
- Ruby 3.2.0 or higher
- PostgreSQL 14 or higher
- Redis (for background jobs)
- Samsara Marketplace app OAuth credentials (Client ID and Secret)
-
Clone the repository:
git clone https://github.com/samsarahq/tms-sample.git cd tms-sample
-
Install dependencies:
bundle install
-
Set up the database:
bin/rails db:create db:migrate
-
Configure environment variables:
rails credentials:edit
Update these credentials
secret_key_base:
samsara:
client_id:
client_secret:
confluent:
bootstrap_servers: ""
key:
secret:
- Start the development server:
bin/dev
The application will be available at http://localhost:3000
.
- Auth Controller: Handles Samsara OAuth flow
- Routes: OAuth callback endpoints
- User Model: Stores Samsara access tokens
- Stop Model: Stores Samsara live sharing URLs
- Stop Show View: Displays live tracking iframe
- Location Fetching: Background job for location updates
- Form Template Model: Syncs with Samsara forms
- Form Templates Controller: CRUD operations
- Form Submissions: Stores driver form responses
- Webhooks Controller: Processes Samsara events
- Kafka Messages: Stores webhook events
- Event Processing: Handles different event types
-
Authentication:
- Visit
/auth/samsara
to start OAuth flow - Complete Samsara authentication
- Access token is stored in the user record
- Visit
-
Form Templates:
- Create form templates at
/form_templates
- Templates sync with Samsara's form system
- Assign templates to stops for driver completion
- Create form templates at
-
Live Tracking:
- View live tracking at
/routes/:id/stops/:id
- Real-time updates via Samsara's live sharing URLs
- Background job fetches location updates
- View live tracking at
-
Webhook Events:
- View webhook events at
/webhooks
- Monitor Kafka messages at
/kafka_messages
- Events are processed asynchronously
- View webhook events at
Run the test suite:
bin/rails test
This repository is a snapshot sample and is not accepting contributions. It is purely for reference while building your integration.