System Architecture
Your Bible is built as a modern full-stack web application with a clear separation between frontend presentation, backend services, and external integrations.Frontend Architecture
The frontend is built with modern React patterns and TanStack ecosystem:TanStack Start
Full-stack React framework providing SSR, file-based routing, and server actions. Configured to deploy on Vercel.
React 19
Latest React with concurrent features, improved hooks, and enhanced performance.
TanStack Router
File-based routing with type safety. Routes are defined in
src/routes/ with automatic route tree generation.TanStack Query
Server state management with caching, background refetching, and optimistic updates. Integrated with Convex via
@convex-dev/react-query.Rendering Strategy
- Server-Side Rendering (SSR): Initial page loads are server-rendered for optimal performance and SEO
- Client-Side Hydration: React takes over after initial load for interactive UI
- Loading States: Uses
useRouterStateto show skeleton screens during navigation - Session Management: Sessions are fetched in root route’s
beforeLoadand cached in QueryClient
Backend Architecture
The backend leverages multiple specialized services:Convex - Real-time Backend
Convex - Real-time Backend
Convex provides the primary backend infrastructure:
- Real-time synchronization: Automatic updates across clients
- Serverless functions: Backend logic runs on Convex infrastructure
- TypeScript-first: Type-safe database queries and mutations
- Schema-based: Defined schemas for collections, notes, and stories
ConvexProvider to the entire application tree.Server Actions (TanStack Start)
Server Actions (TanStack Start)
Server actions handle operations that require server-side execution:
- Authentication flows (Better Auth integration)
- Bible API requests (API.Bible)
- AI story generation (Google Gemini)
- Rate limiting checks (Redis)
src/actions/, these functions run exclusively on the server and can access environment variables and backend services securely.Better Auth + PostgreSQL
Better Auth + PostgreSQL
Authentication is managed by Better Auth with Drizzle ORM:
- Email-based authentication
- Session persistence
- User management
- PostgreSQL database via Neon for auth data storage
Data Flow
Reading Bible Content
Managing Collections
Generating Stories
Integration Points
API.Bible
Purpose: Bible content and translationsFeatures:
- Multiple translations
- Chapter and verse retrieval
- Search functionality
- Metadata and references
Google Gemini AI
Purpose: AI-powered story generationFeatures:
- Creative narrative generation
- Customizable parameters (tone, perspective, length)
- Theological guidelines enforcement
@google/genai SDK in server actionsRedis (Upstash)
Purpose: Rate limiting and cachingFeatures:
- Story generation rate limits
- API cost management
- Prevent abuse
@upstash/ratelimit with Redis clientSecurity Architecture
Authentication & Authorization
Authentication & Authorization
API Key Management
API Key Management
- All API keys stored in environment variables
- Server actions ensure keys never exposed to client
- Rate limiting prevents API abuse
Data Privacy
Data Privacy
- User data (collections, notes, stories) scoped to authenticated user
- Convex queries automatically filter by user session
- No cross-user data access
Performance Considerations
- Code Splitting: Automatic route-based code splitting via TanStack Start
- Caching: TanStack Query caches API responses to reduce network requests
- Real-time Sync: Convex efficiently syncs only changed data
- SSR: Server-side rendering for fast initial page loads
- Lazy Loading: Components and routes loaded on demand
- Optimistic Updates: UI updates immediately with rollback on error
Deployment Architecture
The application is configured for deployment on Vercel:- Frontend & Server Actions: Deployed as Vercel serverless functions
- Convex Backend: Runs on Convex infrastructure (separate deployment)
- Database: PostgreSQL on Neon (managed service)
- Redis: Upstash Redis (serverless)
- CDN: Static assets served via Vercel Edge Network
vite.config.ts specifies target: 'vercel' for the TanStack Start plugin, optimizing the build for Vercel’s deployment platform.