This guide walks you through connecting Altruist to a real Firebase project.
- A Google account
- Node.js 18+ installed
- Firebase CLI (
npm install -g firebase-tools)
- Go to Firebase Console
- Click "Create a project"
- Name it
altruist(or any name you prefer) - Enable/disable Google Analytics as desired
- Click "Create project"
- In the Firebase Console, go to Build → Authentication
- Click "Get started"
- Enable Email/Password provider
- (Optional) Enable Google sign-in provider
- Go to Build → Firestore Database
- Click "Create database"
- Choose Start in production mode
- Select your preferred region (e.g.,
europe-west2for London) - Click "Enable"
After creating the database, deploy the security rules:
firebase login
firebase init firestore
# When prompted, use the existing firestore.rules file
firebase deploy --only firestore:rules- In the Firebase Console, click the gear icon → Project settings
- Under "Your apps", click the web icon (
</>) - Register your app with nickname
altruist-web - Copy the
firebaseConfigobject
Create a .env.local file in the project root:
VITE_FIREBASE_API_KEY=your-api-key
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your-sender-id
VITE_FIREBASE_APP_ID=your-app-idImportant: Never commit
.env.localto version control. It is already in.gitignore.
To populate your database with the mock charity data for development:
// Run this from a Node.js script or Firebase Cloud Function
import { db } from './src/lib/firebase';
import { MOCK_CHARITIES, MOCK_ONS_DATA, MOCK_SURVEYS } from './src/data/mock-data';
import { collection, doc, setDoc } from 'firebase/firestore';
async function seedData() {
// Seed charities
for (const charity of MOCK_CHARITIES) {
await setDoc(doc(db, 'charities', charity.id), charity);
}
// Seed ONS data
for (const ons of MOCK_ONS_DATA) {
await setDoc(doc(db, 'ons_regional_data', ons.lsoaCode), ons);
}
// Seed surveys
for (const survey of MOCK_SURVEYS) {
await setDoc(doc(db, 'surveys', survey.id), survey);
}
console.log('✅ Data seeded successfully');
}
seedData();For production features like ONS data sync and vector search:
firebase init functions
cd functions
npm installimport { onSchedule } from 'firebase-functions/v2/scheduler';
import { getFirestore } from 'firebase-admin/firestore';
const db = getFirestore();
const ONS_IMD_ENDPOINT =
'https://services1.arcgis.com/ESMARspQHYMw9BZ9/arcgis/rest/services/IMD_2019/FeatureServer/0/query?where=1%3D1&outFields=lsoa11cd,lsoa11nm,IMDScore,IMDDecil&f=json&resultRecordCount=1000';
export const syncONSData = onSchedule('every 30 days', async () => {
const response = await fetch(ONS_IMD_ENDPOINT);
const { features } = await response.json();
const batch = db.batch();
for (const feature of features) {
const ref = db.collection('ons_regional_data').doc(feature.attributes.lsoa11cd);
batch.set(ref, {
lsoaCode: feature.attributes.lsoa11cd,
lsoaName: feature.attributes.lsoa11nm,
imdScore: feature.attributes.IMDScore,
imdDecile: feature.attributes.IMDDecil,
lastUpdated: new Date().toISOString(),
});
}
await batch.commit();
});For semantic charity search using Vertex AI:
- Enable the Vertex AI API in Google Cloud Console
- Install the Firebase Vector Search extension:
firebase ext:install googlecloud/firestore-vector-search
- Configure the extension to use the
charitiescollection - Set the text field to a combination of
missionStatement + tags + operatingRegions - The extension will automatically generate embeddings when charity documents are created/updated
If you prefer Pinecone for vector search:
npm install @pinecone-database/pineconeimport { Pinecone } from '@pinecone-database/pinecone';
const pc = new Pinecone({ apiKey: process.env.PINECONE_API_KEY });
const index = pc.index('altruist-charities');
// Query example
const results = await index.query({
vector: await generateEmbedding(userQuery),
topK: 10,
includeMetadata: true,
});For AI-generated impact narratives:
npm install @genkit-ai/core @genkit-ai/firebase @genkit-ai/vertexaiimport { genkit } from 'genkit';
import { vertexAI } from '@genkit-ai/vertexai';
const ai = genkit({ plugins: [vertexAI({ location: 'europe-west2' })] });
export const generateNarrative = ai.defineFlow(
'generateImpactNarrative',
async (input: { metrics: any; donationAmount: number }) => {
const response = await ai.generate({
model: 'gemini-2.0-flash',
prompt: `Generate a compelling impact narrative for a £${input.donationAmount} donation.
Metrics: ${JSON.stringify(input.metrics)}.
Make it personal, specific, and quantitative.`,
});
return response.text();
}
);- Ensure your user document in Firestore has the correct
rolefield - Check that security rules are deployed:
firebase deploy --only firestore:rules
- Verify
.env.localfile exists and contains correct values - Restart the dev server after changing environment variables
- Ensure variable names start with
VITE_
- Run
npm installto ensure all dependencies are installed - Check Node.js version is 18+:
node --version