> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mypopup.shop/llms.txt
> Use this file to discover all available pages before exploring further.

# Local Development Setup

> Set up your local development environment for Popup Store

## Prerequisites

Before you begin, ensure you have the following installed:

<CardGroup cols={2}>
  <Card title="Node.js" icon="node-js">
    Version 18.x or higher

    ```bash theme={null}
    node --version
    ```
  </Card>

  <Card title="pnpm" icon="box">
    Preferred package manager

    ```bash theme={null}
    npm install -g pnpm
    ```
  </Card>

  <Card title="Supabase CLI" icon="database">
    For local database

    ```bash theme={null}
    brew install supabase/tap/supabase
    ```
  </Card>

  <Card title="Xcode" icon="apple">
    For iOS development (Mac only)

    * Xcode 15+
    * iOS Simulator
  </Card>
</CardGroup>

## 1. Clone the Repositories

```bash theme={null}
mkdir popup && cd popup

# Clone all three repos
gh repo clone unfinished-bizness/getpopup-store
gh repo clone unfinished-bizness/popup-supabase
gh repo clone unfinished-bizness/popupstore.ios
```

## 2. Setup Supabase Backend

<Steps>
  <Step title="Start Supabase locally">
    ```bash theme={null}
    cd popup-supabase
    supabase start
    ```

    This will output your local Supabase credentials. **Save these!**
  </Step>

  <Step title="Note the credentials">
    ```
    API URL: http://127.0.0.1:54321
    anon key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
    service_role key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
    ```
  </Step>

  <Step title="Run migrations">
    ```bash theme={null}
    supabase db reset
    ```
  </Step>
</Steps>

## 3. Setup Web Store

<Steps>
  <Step title="Install dependencies">
    ```bash theme={null}
    cd ../getpopup-store
    pnpm install
    ```
  </Step>

  <Step title="Create .env.local">
    ```bash .env.local theme={null}
    # Supabase
    NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321
    NEXT_PUBLIC_SUPABASE_ANON_KEY=your_anon_key_here
    SUPABASE_SERVICE_ROLE_KEY=your_service_role_key_here

    # Razorpay (test mode)
    NEXT_PUBLIC_RAZORPAY_KEY_ID=rzp_test_xxxxx
    RAZORPAY_KEY_SECRET=xxxxx

    # PostHog (optional)
    NEXT_PUBLIC_POSTHOG_KEY=phc_xxxxx
    NEXT_PUBLIC_POSTHOG_HOST=https://app.posthog.com

    # Resend (for emails)
    RESEND_API_KEY=re_xxxxx
    ```
  </Step>

  <Step title="Update hosts file">
    Add test subdomains to `/etc/hosts`:

    ```bash theme={null}
    sudo nano /etc/hosts
    ```

    Add these lines:

    ```
    127.0.0.1   teststore.localhost
    127.0.0.1   myshop.localhost
    ```
  </Step>

  <Step title="Run dev server">
    ```bash theme={null}
    pnpm dev
    ```

    Open [http://teststore.localhost:3000](http://teststore.localhost:3000)
  </Step>
</Steps>

## 4. Setup iOS App (Mac only)

<Steps>
  <Step title="Install dependencies">
    ```bash theme={null}
    cd ../popupstore.ios
    pod install  # If using CocoaPods
    ```
  </Step>

  <Step title="Configure Supabase">
    Update `Configuration/Development.xcconfig`:

    ```swift theme={null}
    SUPABASE_URL = http://127.0.0.1:54321
    SUPABASE_ANON_KEY = your_anon_key_here
    ```
  </Step>

  <Step title="Open in Xcode">
    ```bash theme={null}
    open popupstore.xcworkspace
    ```
  </Step>

  <Step title="Run on simulator">
    1. Select a simulator (iPhone 15 Pro)
    2. Press `Cmd + R` to build and run
  </Step>
</Steps>

## Test Data

The local Supabase instance comes with seed data:

<Accordion title="Test Users">
  ```
  Email: seller@test.com
  Password: password123
  Store: teststore
  ```
</Accordion>

<Accordion title="Test Products">
  * 5 sample products with images
  * 2 categories (Electronics, Clothing)
  * Various price points
</Accordion>

<Accordion title="Test Orders">
  * 3 pending orders
  * 2 completed orders
  * Mix of UPI and Razorpay payments
</Accordion>

## Verify Setup

<Tabs>
  <Tab title="Web Store">
    Visit [http://teststore.localhost:3000](http://teststore.localhost:3000)

    You should see:

    * ✅ Store homepage with products
    * ✅ Working cart functionality
    * ✅ Checkout flow
  </Tab>

  <Tab title="iOS App">
    In the iOS simulator:

    * ✅ Login with test credentials
    * ✅ View dashboard with analytics
    * ✅ See products list
    * ✅ View pending orders
  </Tab>

  <Tab title="Supabase">
    Open [http://127.0.0.1:54323](http://127.0.0.1:54323)

    * ✅ Database with tables
    * ✅ Auth users
    * ✅ Storage buckets (product-images)
  </Tab>
</Tabs>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Subdomain routing not working">
    Make sure you:

    1. Updated `/etc/hosts` with test domains
    2. Using `.localhost:3000` (not `localhost:3000`)
    3. Middleware is detecting subdomains correctly

    Check middleware logs:

    ```bash theme={null}
    # In getpopup-store/src/middleware.ts
    console.log('Host:', req.headers.get('host'))
    ```
  </Accordion>

  <Accordion title="Supabase connection errors">
    Verify Supabase is running:

    ```bash theme={null}
    supabase status
    ```

    Check .env.local has correct credentials:

    ```bash theme={null}
    cat .env.local | grep SUPABASE
    ```
  </Accordion>

  <Accordion title="iOS build fails">
    Common fixes:

    1. Clean build folder: `Cmd + Shift + K`
    2. Delete derived data
    3. Update Swift package dependencies
    4. Restart Xcode
  </Accordion>
</AccordionGroup>

<Info>
  **Stuck?** Join our Discord or create an issue on GitHub
</Info>
