Overview
Your Bible is built with TanStack Start, a full-stack React framework. The project follows a modular structure with clear separation of concerns.Root Directory Files
Project metadata, dependencies, and npm scripts.Key Dependencies:
@tanstack/react-start- Full-stack React frameworkconvex- Real-time backend and databasebetter-auth- Authentication solutiondrizzle-orm- Type-safe database queries@google/genai- Google Gemini AI integrationplatejs- Rich text editortailwindcss- Utility-first CSS framework
TypeScript compiler configuration with path aliases:
@/*→./src/*- Strict type checking enabled
- React 19 JSX transform
Vite build configuration:
- TanStack Start plugin
- Path resolution
- Development server settings
- Build optimizations
Drizzle ORM configuration:
- Database connection
- Migration settings
- Schema location
Template for environment variables. Copy to
.env and fill in your values.
See Environment Variables for details.Source Directory (src/)
Main Entry Points
The root React component that:
- Sets up providers (Query, Convex, Theme)
- Configures global layout
- Initializes authentication
- Includes Toast notifications
Core Directories
Actions (src/actions/)
TanStack Start server actions - backend functions that run on the server.
- Fetching data from external APIs
- Rate limiting
- Authentication checks
- Data validation
bible.ts:10 - Fetches chapter content from API.Bible
Components (src/components/)
Component Organization Guidelines
Component Organization Guidelines
Feature Components (
bible/, collections/, stories/, search/):- Domain-specific components
- Can import from
ui/but not from other feature directories - May have local state and business logic
ui/):- Generic, reusable components
- Based on shadcn/ui
- No business logic
- Fully typed with TypeScript
- Can be used across all features
skeletons/):- Loading state placeholders
- Match the layout of actual content
- Improve perceived performance
Routes (src/routes/)
TanStack Router uses file-based routing. Each file becomes a route.
Route Naming Conventions
Route Naming Conventions
- Static routes:
about.tsx→/about - Dynamic routes:
$id.tsx→/:id - Nested routes:
blog/$slug.tsx→/blog/:slug - Layout routes:
_layout.tsx→ No URL segment, provides layout - Protected routes:
_authed/prefix requires authentication - Catch-all routes:
$.tsx→ Matches any remaining path
Hooks (src/hooks/)
- Data fetching with TanStack Query
- Convex real-time subscriptions
- Shared stateful logic
- Side effects
Library (src/lib/)
utils.ts
utils.ts
Common utility functions:
cn()- Tailwind class name merger usingclsxandtailwind-merge- Date formatting helpers
- String manipulation
axios.ts
axios.ts
Pre-configured Axios instance for API.Bible:
- Base URL set to
https://api.scripture.api.bible/v1 - API key authentication header
- Request/response interceptors
auth.ts
auth.ts
Better Auth server configuration:
- Drizzle adapter for PostgreSQL
- Email/password authentication
- GitHub OAuth provider
- Session management
gemini.ts
gemini.ts
Google Gemini AI client:
- Model:
gemini-1.5-flash - API key configuration
- Error handling
redis.ts
redis.ts
Upstash Redis rate limiting:
- Fixed window: 5 requests per 24 hours
- Used for story generation
- Analytics enabled
Queries (src/queries/)
- Query keys
- Query functions
- Caching strategies
- Refetch policies
Schemas (src/schemas/)
- Form validation
- API request/response validation
- Type inference
Server (src/server/)
Types (src/types/)
- API response types
- Domain models
- Utility types
- Type guards
Styles (src/styles/)
Database (src/db/)
Convex Directory
Convex automatically generates TypeScript types from your schema.
Defines database tables and indexes:
collections- User verse collectionscollectionVerses- Verses within collectionsnotes- Chapter notesstories- AI-generated stories
Convex functions for collection operations:
create- Create new collectionupdate- Update collection namedelete- Delete collectionlist- Get user’s collectionsget- Get single collection
File Naming Conventions
Components
- PascalCase for component files:
BibleReader.tsx - Or kebab-case:
bible-reader.tsx - Export component with same name as file
Utilities
- kebab-case:
use-bible.ts - camelCase for hook files:
useBible.ts - Descriptive names
Routes
- kebab-case:
search.tsx $prefix for params:$id.tsx_prefix for layout routes:_layout.tsx
Types
- kebab-case:
bible-types.ts - Or domain-based:
bible.tsintypes/ - Export types, not default exports
Where to Add New Features
Identify Feature Category
Determine where your feature belongs:
- Bible reading →
src/components/bible/ - Collections →
src/components/collections/ - Stories →
src/components/stories/ - Search →
src/components/search/ - New category → Create new directory in
src/components/
Import Aliases
The project uses path aliases configured intsconfig.json:
@/components→src/components@/lib→src/lib@/hooks→src/hooks@/types→src/types@/actions→src/actions@/schemas→src/schemas
Code Organization Best Practices
Keep Components Small
Keep Components Small
- Single Responsibility Principle
- Extract complex logic into hooks
- Break large components into smaller ones
- Maximum ~200 lines per component
Co-locate Related Files
Co-locate Related Files
Separate Business Logic
Separate Business Logic
- Components for UI
- Hooks for data and state
- Actions for server operations
- Utils for pure functions
Use Barrel Exports
Use Barrel Exports
Create
index.ts files for cleaner imports:Additional Resources
Environment Variables
Complete reference for all environment variables
Database Schema
Convex schema documentation
Integrations
External API and service integrations
Contributing Guide
How to contribute to the project