Overview
Your Bible integrates with multiple external services to provide its full functionality. This page documents each integration, including setup, configuration, API usage, and best practices.API.Bible
Bible content, translations, and search
Google Gemini AI
AI-powered story generation
Convex
Real-time backend and database
Better Auth
Authentication and user management
Upstash Redis
Rate limiting and caching
PostgreSQL (Neon)
User and session data storage
API.Bible
API.Bible provides access to multiple Bible translations, chapters, verses, and search functionality.
Configuration
Configured insrc/lib/axios.ts:1:
Environment Variables
Value:
https://api.scripture.api.bible/v1Base URL for all API.Bible requests.Your API.Bible API key from scripture.api.bible.How to get:
- Sign up at API.Bible
- Create an API key
- Add to
.envfile
Key Features
Bible Translations
Bible Translations
Endpoint: Usage: Translation selector dropdown
GET /biblesRetrieves list of available Bible translations.Response:Chapter Content
Chapter Content
Endpoint: Usage: Bible reader component
GET /bibles/{bibleId}/chapters/{chapterId}Retrieves full chapter content with verses.Parameters:bibleId: Translation ID (e.g.,"de4e12af7f28f599-02")chapterId: Chapter ID (e.g.,"GEN.1","JHN.3")include-verse-numbers:true(optional)
Search
Search
Endpoint: Usage: Search functionality
GET /bibles/{bibleId}/searchSearch Bible text for keywords.Parameters:query: Search term (e.g.,"love","faith")limit: Results per page (default: 10)offset: Pagination offset
Books and Chapters
Books and Chapters
Endpoint:
GET /bibles/{bibleId}/books/{bookId}/chaptersList all chapters in a book.Usage: Chapter navigationRate Limits
Best Practices
- Cache translation lists (rarely change)
- Cache chapter content (use TanStack Query)
- Implement exponential backoff for retries
- Handle rate limit errors gracefully
- Use
include-verse-numbersparameter for better verse identification
Error Handling
Google Gemini AI
Google Gemini AI generates creative stories based on biblical passages.
Configuration
Configured insrc/lib/gemini.ts:1:
Environment Variables
Recommended:
gemini-1.5-flashAlternatives:gemini-1.5-pro- Higher quality, slower, more expensivegemini-1.5-flash- Balanced speed and quality
- Flash: ~0.1s response time, lower cost
- Pro: ~1-2s response time, better quality, higher cost
Your Google AI API key from Google AI Studio.How to get:
- Visit Google AI Studio
- Sign in with Google account
- Create API key
- Add to
.envfile
Story Generation
Usage Example:Story Parameters
Narrative viewpoint for the story.Examples:
- “first-person from David’s perspective”
- “third-person omniscient”
- “second-person narrative”
Context or world for the story.Examples:
- “ancient Israel”
- “modern day”
- “alternate historical timeline”
Emotional quality of the story.Examples:
- “contemplative and reflective”
- “adventurous and exciting”
- “solemn and reverent”
Desired story length.Options:
short- 200-400 wordsmedium- 400-800 wordslong- 800-1500 words
Rate Limits
Free Tier:- 60 requests per minute
- 1,500 requests per day
- 5 stories per user per day (enforced via Redis)
- Prevents excessive API costs
Best Practices
Prompt Engineering
Prompt Engineering
- Provide clear context from the biblical passage
- Specify all parameters explicitly
- Include theological guidelines
- Request specific tone and style
- Set word count expectations
Error Handling
Error Handling
Content Filtering
Content Filtering
- Gemini has built-in safety filters
- Handles inappropriate requests automatically
- Returns filtered responses for sensitive topics
- May refuse to generate certain content
Convex
Convex provides real-time database and backend functionality.
Configuration
Schema:convex/schema.ts
Functions: convex/*.ts files
Client: Initialized in app
Environment Variables
Convex deployment identifier (auto-generated).
Convex backend URL for client connections.Example:
https://your-project.convex.cloudKey Features
Real-time Queries
Real-time Queries
Queries automatically update when data changes:
Mutations
Mutations
Write operations with optimistic updates:
Server Functions
Server Functions
Backend logic runs on Convex servers:
Best Practices
- Use indexes for frequently queried fields
- Validate all inputs in mutations
- Implement proper access control
- Keep functions small and focused
- Use TypeScript types generated by Convex
Better Auth
Better Auth handles user authentication with email/password and OAuth providers.
Configuration
Configured insrc/lib/auth.ts:1:
Environment Variables
Secret key for encrypting sessions and tokens.Generate:
openssl rand -base64 32Application base URL for auth callbacks.Development:
http://localhost:5173Production: Your domain URLPostgreSQL connection string for user data.
GitHub OAuth client ID (optional).
GitHub OAuth client secret (optional).
Features
Email/Password Authentication
Email/Password Authentication
- User registration with email and password
- Secure password hashing
- Automatic sign-in after registration
- No email verification required (configurable)
OAuth (GitHub)
OAuth (GitHub)
- Sign in with GitHub
- Automatic account linking
- Profile data import
- Create GitHub OAuth App
- Set callback URL:
{BETTER_AUTH_URL}/api/auth/callback/github - Add client ID and secret to
.env
Session Management
Session Management
- Cookie-based sessions
- Automatic session refresh
- Secure, httpOnly cookies
- Cross-tab session sync
Best Practices
- Use strong, unique
BETTER_AUTH_SECRET - Enable email verification in production
- Implement password strength requirements
- Use HTTPS in production
- Regularly rotate secrets
Upstash Redis
Redis provides rate limiting for story generation to manage API costs.
Configuration
Configured insrc/lib/redis.ts:1:
Environment Variables
Redis connection URL.
Upstash KV connection URL.
REST API URL for Redis operations.
Authentication token for REST API.
Read-only token for security.
Rate Limiting
Configuration:- Algorithm: Fixed window
- Limit: 5 requests per window
- Window: 86,400 seconds (24 hours)
- Per: User ID
Best Practices
- Use user ID as rate limit key
- Provide clear error messages with reset time
- Display remaining attempts to users
- Consider different limits for paid tiers
- Monitor analytics in Upstash dashboard
PostgreSQL (Neon)
PostgreSQL stores user accounts, sessions, and authentication data via Better Auth.
Environment Variables
PostgreSQL connection string.Format:
postgresql://user:password@host:port/database?sslmode=requireNeon: Automatically includes SSLLocal: postgresql://localhost/yourbibleSchema
Managed by Better Auth via Drizzle ORM:users- User accountssessions- Active sessionsaccounts- OAuth account linksverificationTokens- Email verification (if enabled)
Best Practices
- Use SSL in production (
?sslmode=require) - Regular backups (automatic with Neon)
- Monitor connection pool usage
- Use connection pooling for serverless
- Keep schema migrations tracked
Integration Testing
Testing Each Service
Monitoring and Analytics
API.Bible
API.Bible
- Monitor usage in API.Bible dashboard
- Track rate limit usage
- Set up alerts for quota warnings
Gemini AI
Gemini AI
- Monitor usage in Google Cloud Console
- Track token usage and costs
- Set up billing alerts
Convex
Convex
- View function logs in Convex dashboard
- Monitor query performance
- Track database size
Upstash
Upstash
- View rate limit analytics
- Monitor Redis operations
- Track API usage
Cost Optimization
API.Bible
Free Tier: 500 requests/dayOptimization:
- Cache translation lists
- Cache chapter content
- Use CDN for static content
Gemini AI
Free Tier: 60 RPM, 1.5K RPDOptimization:
- Rate limit (5/day per user)
- Use Flash model over Pro
- Optimize prompt length
Convex
Free Tier: Generous limitsOptimization:
- Use indexes efficiently
- Paginate large queries
- Clean up old data
Neon
Free Tier: 0.5 GB storageOptimization:
- Archive old sessions
- Monitor database size
- Use appropriate data types
Related Documentation
Environment Variables
Complete environment variable reference
Local Setup
Setting up all integrations locally
Database Schema
Convex database schema documentation
Deployment
Deploying with all integrations