# ExpenseDesk – Setup Guide

## Prerequisites
- A Google account (for Firebase)
- A modern web browser

---

## Step 1: Create a Firebase Project

1. Go to [https://console.firebase.google.com](https://console.firebase.google.com)
2. Click **"Add project"**
3. Enter project name: `expensedesk` (or any name you like)
4. Disable Google Analytics (not needed) → Click **"Create project"**

---

## Step 2: Enable Authentication

1. In your Firebase project, click **"Authentication"** in the left sidebar
2. Click **"Get started"**
3. Click **"Email/Password"**
4. Toggle **"Email/Password"** to **Enabled**
5. Click **"Save"**

---

## Step 3: Create Firestore Database

1. Click **"Firestore Database"** in the left sidebar
2. Click **"Create database"**
3. Choose **"Start in test mode"** (allows read/write for 30 days; secure later)
4. Select a location (e.g., `asia-south1` for India)
5. Click **"Enable"**

---

## Step 4: Enable Firebase Storage (for screenshots)

1. Click **"Storage"** in the left sidebar
2. Click **"Get started"**
3. Choose **"Start in test mode"**
4. Click **"Next"** then **"Done"**

---

## Step 5: Get Your Firebase Config

1. In Firebase console, click the **gear icon** → **"Project settings"**
2. Scroll down to **"Your apps"**
3. Click **"Web"** icon (`</>`)
4. Register the app (name: `ExpenseDesk Web`)
5. Copy the `firebaseConfig` object

---

## Step 6: Update config.js

Open `js/config.js` and replace the placeholder values:

```javascript
const firebaseConfig = {
  apiKey: "AIza...",                    // ← paste your values
  authDomain: "expensedesk.firebaseapp.com",
  projectId: "expensedesk",
  storageBucket: "expensedesk.appspot.com",
  messagingSenderId: "123456789",
  appId: "1:123456789:web:abc123"
};
```

---

## Step 7 (Optional): Enable AI Receipt Parsing

1. Go to [https://aistudio.google.com/app/apikey](https://aistudio.google.com/app/apikey)
2. Click **"Create API key"**
3. Copy the key
4. In `js/config.js`, set:

```javascript
const GEMINI_API_KEY = "AIza...your-key-here";
```

---

## Step 8: Run the App

Open `index.html` in a browser. For best results, use a local server:

```bash
# Using Python (built-in)
cd /Users/mathavans/Downloads/reimbusment
python3 -m http.server 8080

# Then open: http://localhost:8080
```

Or use VS Code's **Live Server** extension.

---

## Firestore Security Rules (for production)

After testing, update Firestore rules to require authentication:

```
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read: if request.auth != null;
      allow write: if request.auth != null && request.auth.uid == userId;
    }
    match /expenses/{expenseId} {
      allow read: if request.auth != null;
      allow create: if request.auth != null;
      allow delete: if request.auth != null 
        && request.auth.uid == resource.data.userId;
    }
  }
}
```

---

## File Structure

```
reimbusment/
├── index.html          ← Login / Register page
├── dashboard.html      ← Main dashboard
├── SETUP.md            ← This file
├── css/
│   ├── style.css       ← Design system
│   ├── login.css       ← Login page styles
│   └── dashboard.css   ← Dashboard layout
└── js/
    ├── config.js       ← Firebase config + constants ⬅ EDIT THIS
    ├── auth.js         ← Authentication
    ├── db.js           ← Firestore operations
    ├── app.js          ← Main dashboard logic
    ├── ai.js           ← Gemini AI parser
    └── export.js       ← Excel export
```

---

## Need Help?

- Firebase Docs: https://firebase.google.com/docs
- Gemini API: https://ai.google.dev
