This guide will help you set up the Balance App for development.
Before you begin, ensure you have:
- Node.js v18 or higher (Download)
- npm (comes with Node.js)
- A Google account (for Firebase)
The Firebase CLI is needed for deploying and managing your Firebase project.
npm install -g firebase-toolsVerify installation:
firebase --version- Go to the Firebase Console
- Click "Add project"
- Enter a project name (e.g., "balance-app")
- Disable Google Analytics (optional, you can enable it later)
- Click "Create project"
- In your Firebase project, go to Authentication in the left sidebar
- Click "Get started"
- Click on the "Sign-in method" tab
- Enable "Email/Password"
- Click "Save"
- In your Firebase project, go to Firestore Database in the left sidebar
- Click "Create database"
- Select "Start in test mode" (we'll add security rules later)
- Choose a Cloud Firestore location (select one closest to you)
- Click "Enable"
- In Firebase Console, click the gear icon ⚙️ next to "Project Overview"
- Click "Project settings"
- Scroll down to "Your apps" section
- Click the "Web" icon (</>)
- Register your app with a nickname (e.g., "Balance Web App")
- Copy the Firebase configuration object
-
Navigate to the web-app directory:
cd web-app -
Create a
.envfile from the template:cp .env.example .env
-
Open
.envand paste your Firebase credentials:VITE_FIREBASE_API_KEY=your_api_key_here VITE_FIREBASE_AUTH_DOMAIN=your_project_id.firebaseapp.com VITE_FIREBASE_PROJECT_ID=your_project_id VITE_FIREBASE_STORAGE_BUCKET=your_project_id.appspot.com VITE_FIREBASE_MESSAGING_SENDER_ID=your_sender_id VITE_FIREBASE_APP_ID=your_app_id
Example:
VITE_FIREBASE_API_KEY=AIzaSyD... VITE_FIREBASE_AUTH_DOMAIN=balance-app-12345.firebaseapp.com VITE_FIREBASE_PROJECT_ID=balance-app-12345 VITE_FIREBASE_STORAGE_BUCKET=balance-app-12345.appspot.com VITE_FIREBASE_MESSAGING_SENDER_ID=123456789012 VITE_FIREBASE_APP_ID=1:123456789012:web:abc123def456
-
Login to Firebase:
firebase login
-
Initialize Firebase in the project root:
cd /Users/dingyi/Projects/BalanceAPP firebase init -
Select the following options:
- Services to set up:
- ☑ Firestore: Configure security rules and indexes files for Firestore
- ☑ Hosting: Configure files for Firebase Hosting
- Use an existing project: Select your project from the list
- Firestore rules file: Press Enter (use default:
firestore.rules) - Firestore indexes file: Press Enter (use default:
firestore.indexes.json) - Public directory: Enter
web-app/dist - Configure as a single-page app: Yes
- Set up automatic builds: No
- Overwrite files: No
- Services to set up:
After initialization, update the firestore.rules file in the project root:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Helper functions
function isSignedIn() {
return request.auth != null;
}
function isOwner(userId) {
return isSignedIn() && request.auth.uid == userId;
}
// User settings
match /userSettings/{userId} {
allow read, write: if isOwner(userId);
}
// Transactions
match /transactions/{transactionId} {
allow read: if isSignedIn() && resource.data.userId == request.auth.uid;
allow create: if isSignedIn() && request.resource.data.userId == request.auth.uid;
allow update, delete: if isSignedIn() && resource.data.userId == request.auth.uid;
}
// Categories
match /categories/{categoryId} {
allow read: if isSignedIn() && resource.data.userId == request.auth.uid;
allow create: if isSignedIn() && request.resource.data.userId == request.auth.uid;
allow update, delete: if isSignedIn() && resource.data.userId == request.auth.uid;
}
// Budgets
match /budgets/{budgetId} {
allow read: if isSignedIn() && resource.data.userId == request.auth.uid;
allow create: if isSignedIn() && request.resource.data.userId == request.auth.uid;
allow update, delete: if isSignedIn() && resource.data.userId == request.auth.uid;
}
}
}Deploy the rules:
firebase deploy --only firestore:rules-
Navigate to the web-app directory:
cd web-app -
Install dependencies (if not already done):
npm install
-
Start the development server:
npm run dev
-
Open your browser and navigate to:
http://localhost:5173
- Firebase CLI installed and logged in
- Firebase project created
- Email/Password authentication enabled
- Firestore database created
-
.envfile created with Firebase credentials - Firebase initialized in project
- Firestore rules deployed
- Development server running successfully
- Can sign up and log in to the app
Solution: Make sure your .env file is in the web-app directory and contains all required Firebase credentials.
Solution: Deploy your Firestore rules using firebase deploy --only firestore:rules
Solution:
- Delete
node_modulesandpackage-lock.json - Run
npm installagain - Try
npm run devagain
Once everything is set up and running:
- Test the authentication: Sign up with a test email
- Explore the dashboard: Navigate through the empty dashboard
- Ready for Phase 2: We can now implement transaction management and categories
If you're using Visual Studio Code, install these extensions for a better development experience:
- ESLint - JavaScript linting
- Prettier - Code formatting
- ES7+ React/Redux/React-Native snippets - React snippets
- Firebase - Firebase integration
- i18n Ally - Translation management
If you encounter any issues during setup, please check: