Skip to content

Development & Environment Setup Guide

TIP

Interactive Architecture Tour: Open Live Tour (App Bootstrapping & Routing)

Welcome to the Scripture Habit development guide. This document outlines everything you need to set up a local development environment, run tests, and contribute to the project.


Quick Start (Local Setup)

You do not need a paid Firebase project or production API keys to develop locally. Scripture Habit runs entirely within local Firebase Emulators.

Prerequisites

  • Node.js: >= 22.0.0 (Check with node -v)
  • npm: >= 10.0.0
  • Java JRE / JDK: Required for running the Firebase Emulator Suite (Check with java -version)

Step-by-Step Setup

1. Clone the Repository

bash
git clone https://github.com/your-username/scripture-habit.git
cd scripture-habit

2. Install Dependencies

bash
npm install

3. Set Up Environment Variables

Copy the template environment file:

bash
# On Linux / macOS / Git Bash:
cp .env.example .env.local

# On Windows (PowerShell):
Copy-Item .env.example .env.local

NOTE

The default placeholder values in .env.example are pre-configured to work out-of-the-box with local emulators.

4. Launch Local Development Environment

Start Firebase Emulators, wait for initialization, and start both the Express backend and Vite frontend within a single terminal (starts with a clean database):

bash
npm run dev:all

Logs from all services will be streamed with color-coded prefixes ([SYS], [EMU], [API], [WEB]). Press Ctrl+C to stop all services simultaneously.

TIP

Seeding Test Data:

  • Once services are running, execute npm run db:seed:existing (existing user, group members, streak) or npm run db:seed:new (fresh new user, 0 streaks, uncompleted onboarding) in a separate terminal tab whenever you need fresh test data.
  • To start all services and automatically seed existing user test data in one command, use npm run dev:all:seed.
Option B: Individual Service Commands

If you prefer running services in separate terminal tabs:

bash
# 1. Start Firebase Emulators
npm run emulators

# 2. Seed test data into local Firestore & Auth emulators
npm run db:seed

# 3. Start local Express backend server (localhost:5000)
npm run server

# 4. Start frontend Vite dev server (localhost:5173)
npm run dev

Once started, the emulator and application endpoints will be available:


Environment Variables Reference

VariableScopeRequired in Local Dev?Description
VITE_FIREBASE_API_KEYFrontendNo (Placeholder OK)Firebase Web API Key
VITE_FIREBASE_AUTH_DOMAINFrontendNo (Placeholder OK)Firebase Auth Domain
VITE_FIREBASE_PROJECT_IDFrontendNo (Placeholder OK)Firebase Project ID
VITE_FIREBASE_STORAGE_BUCKETFrontendNo (Placeholder OK)Firebase Storage Bucket
VITE_FIREBASE_MESSAGING_SENDER_IDFrontendNo (Placeholder OK)FCM Sender ID
VITE_FIREBASE_APP_IDFrontendNo (Placeholder OK)Firebase App ID
VITE_APPCHECK_SITE_KEYFrontendNo (Leave empty)reCAPTCHA v3 key (disabled locally)
VITE_SENTRY_DSNFrontendNo (Leave empty)Sentry error logging endpoint
GEMINI_API_KEYBackendOptionalGoogle Gemini API key for AI features
CRON_SECRETBackendOptionalShared secret for maintenance cron triggers
DISCORD_WEBHOOK_URLBackendOptionalWebhook for internal monitoring alerts

Available npm Scripts

CommandDescription
npm run dev:allStarts all development services (Emulators, Backend, Frontend) with a clean database in a single terminal
npm run dev:all:seedStarts all development services and automatically seeds initial test data (db:seed)
npm run devStarts Vite frontend dev server at localhost:5173
npm run serverStarts local Express backend server at localhost:5000
npm run emulatorsStarts local Firebase Emulator Suite (Firestore, Auth, Functions)
npm run buildBuilds frontend production bundle and runs meta-localization
npm run lintRuns ESLint across the codebase
npm run check:allRuns full type checks, i18n checks, and backend integrity checks
npm run check:i18nVerifies translation key coverage across all locales
npm run sort:localesAutomatically sorts and formats translation files
npm run testRuns frontend unit tests with Vitest
npm run test:internalRuns backend/integration tests with emulated Firebase
npm run test:rulesRuns dedicated Firestore security rules unit tests
npm run test:e2eRuns Playwright End-to-End tests against emulated sandbox
npm run db:seedSeeds existing user test environment (alias for db:seed:existing)
npm run db:seed:existingSeeds existing user test environment (existing-user@example.com, Daily Bread group, 8-day streak, notes)
npm run db:seed:newSeeds fresh new user test environment (new-user@example.com, no groups, uncompleted onboarding)
npm run docs:devStarts local VitePress documentation dev server
npm run docs:buildGenerates TypeDoc references and builds production docs site

Interactive Code Tours (VS Code)

To help developers quickly navigate the codebase, this repository includes guided CodeTours (64 tours in total) that walk through key files and architectural data flows directly inside VS Code.

Installation & Prerequisites

Install the CodeTour extension from the Visual Studio Code Marketplace.

Starting a Tour

  1. Open the CodeTour panel in the VS Code Primary Side Bar (or run CodeTour: Start Tour from the Command Palette via Ctrl+Shift+P / Cmd+Shift+P).
  2. Select any tour from the available categories:
    • Fundamentals & Frameworks (40 tours):
      • chat-01 to chat-08: Group chat architecture, real-time sync, scroll anchor, message translation, security.
      • firebase-01 to firebase-04: onSnapshot, query optimization, server timestamps, Firestore security rules.
      • react-01 to react-09: useReducer, Context API, custom hooks, ref synchronization, optimistic UI.
      • ts-01 to ts-06: Discriminated unions, generics, type guards, as const, asynchronous types.
      • test-01 to test-04: Vitest unit tests, mocking strategies, Firebase Emulator integration, Playwright E2E.
      • node-01 to node-06: Express middleware, environment variables, centralized error handling, rate limiting.
    • Architecture & End-to-End Data Flow (24 tours):
      • arch-01 to arch-24: Full data relay from UI components through custom hooks, context state, and backend services to Firestore persistence for each core feature (Authentication, New Note, Habit Dashboard, Group Chat, Time Capsule, PWA, etc.).

TIP

To visualize component wiring and node data relays as an interactive graph in your browser, open docs/architecture-tour.html locally or explore the Live Architecture Tour.


Testing & Quality Verification

Before submitting a Pull Request, verify that all checks pass:

bash
# 1. Type check & static analysis
npm run check:all

# 2. Run unit tests
npm run test

# 3. (Optional) Run E2E tests
npm run test:e2e

Troubleshooting

Port Conflicts (8080, 9099, 4000)

If the emulator fails to start because a port is occupied:

  • Windows (PowerShell):
    powershell
    Stop-Process -Id (Get-NetTCPConnection -LocalPort 8080).OwningProcess -Force
  • macOS / Linux:
    bash
    kill -9 $(lsof -t -i:8080)

Java Missing for Emulators

The Firebase Emulator Suite requires Java runtime. If you see Java not found:

  • Install OpenJDK (e.g., via winget install Microsoft.OpenJDK.21 on Windows, or brew install openjdk on macOS).

Contribution Workflow

Once you have made and verified your changes locally:

  1. Branching: Create a feature branch from main (e.g., git checkout -b feat/your-feature-name).
  2. Atomic Commits: Follow Conventional Commits format with clear messages.
  3. Quality Checks: Ensure npm run check:all and npm test pass with 0 errors.
  4. Create a Pull Request: Submit a PR with a description of what was changed and attach screenshots/GIFs for UI modifications.

For full branch naming conventions, commit formats, translation contribution steps, and our Code of Conduct, please refer to the Contributing Guide (CONTRIBUTING.md).

Released under the MIT License.