Overview
GitaChat automatically tracks your search history, allowing you to revisit verses you’ve previously explored. This feature helps you keep track of your spiritual journey and easily return to verses that were meaningful to you.How History Works
Automatic Tracking
Every search query is automatically saved to your history
Chronological Order
View your searches in reverse chronological order (newest first)
Easy Access
Quickly revisit verses you’ve searched before
Clear History
Delete all history with a single action
API Endpoint
The history API is available at/api/history and supports two HTTP methods:
Get Search History
Retrieve all search queries for the authenticated user. Endpoint:GET /api/history
Authentication: Required (Clerk)
Rate Limit: 30 requests per minute per client
Response:
id: Unique identifier for the history entryuser_id: Clerk user identifierchapter: Chapter number of the verseverse: Verse numberquery: The original search query textcreated_at: Timestamp when the search was performed
Clear All History
Delete all search history for the authenticated user. Endpoint:DELETE /api/history
Authentication: Required (Clerk)
Rate Limit: 5 requests per minute per client (stricter for destructive operations)
Success Response (200):
Data Storage
Search history is stored in thequery_history table in Supabase:
| Column | Type | Description |
|---|---|---|
id | UUID | Primary key |
user_id | String | Clerk user identifier |
chapter | Integer | Chapter number (1-18) |
verse | Integer | Verse number |
query | Text | Original search query |
created_at | Timestamp | When the search was performed |
user_id and created_at for efficient querying.
Implementation Details
The history system is implemented in/app/api/history/route.ts:
Separate Rate Limits
GET: 30 req/min, DELETE: 5 req/min to prevent abuse
Automatic Recording
Searches are logged automatically by the main query endpoint
User Isolation
Each user can only access their own history
Ordered Results
Results always sorted by most recent first
How History is Recorded
When you search for a verse or topic in GitaChat, the query is automatically saved to your history through the main search API. This happens seamlessly in the background without any action required from you. The recording process:- User submits a search query
- GitaChat processes the query and returns relevant verses
- Query details (chapter, verse, query text) are saved to
query_history - History entry includes timestamp for chronological sorting
Daily Verse Integration
Your search history also plays a role in the daily verse feature. The daily verse selection algorithm:- Checks which verses you’ve already seen (from history)
- Prioritizes showing you new, unseen verses
- Falls back to random selection if all verses have been seen
User Interface
The history feature integrates into the GitaChat UI:- View History: Access a dedicated history page showing all past searches
- Click to Revisit: Click any history item to view that verse again
- Clear All: Button to delete entire history if desired
- Timestamp Display: See when each search was performed
Privacy and Data Management
Privacy Controls
- Only you can see your search history
- History is tied to your Clerk user ID
- Clear all history anytime with DELETE endpoint
- History data is stored securely in Supabase
Rate Limiting
Different rate limits apply to different operations:| Operation | Rate Limit | Purpose |
|---|---|---|
| GET (view history) | 30 requests/min | Normal browsing usage |
| DELETE (clear history) | 5 requests/min | Prevent accidental mass deletions |
Error Handling
Common error scenarios:| Error | Status | Description |
|---|---|---|
| Unauthorized | 401 | User not logged in |
| Too many requests | 429 | Rate limit exceeded |
| Database not configured | 503 | Supabase connection unavailable |
| Failed to fetch/clear | 500 | Server error occurred |
Use Cases
Personal Review
Review verses you’ve explored in your spiritual journey
Revisit Favorites
Quickly find verses that resonated with you before
Study Patterns
See which topics you search for most frequently
Daily Verse Optimization
History helps ensure you see new verses daily
Best Practices
- Regular Review: Periodically review your history to reinforce learning
- Bookmark Important Verses: Use bookmarks for verses you want to save permanently
- Clear Old History: Clear history periodically if you want a fresh start
- Combine with Notes: Add notes to verses in your history for deeper reflection