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

# Environment Configuration

> Configure your local development environment

# Environment Configuration

FindU currently uses a single production Supabase project. This guide explains how to configure your local development environment to connect to the production database.

## Current Architecture

```mermaid theme={null}
graph LR
    A[Local Development] --> B[Production Supabase]
    C[GitHub Main Branch] --> B
    B --> D[Production Railway]
```

<Warning>
  We're currently using a single production environment. Be extremely careful when developing locally as you'll be working with real user data.
</Warning>

## Environment Files

Each repository has its own environment configuration:

### Web App (.env)

```bash theme={null}
VITE_SUPABASE_URL=https://your-project.supabase.co
VITE_SUPABASE_ANON_KEY=<your-anon-key>
VITE_ENV=production
```

### iOS App (Secrets.xcconfig)

```bash theme={null}
SUPABASE_URL = https://your-project.supabase.co
SUPABASE_ANON_KEY = <your-anon-key>
```

### Matching Algorithm (.env)

```bash theme={null}
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=<your-service-key>
ENVIRONMENT=production
```

### Data Scraping (.env)

```bash theme={null}
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=<your-service-key>
COLLEGE_SCORECARD_API_KEY=<your-api-key>
FIRECRAWL_API_KEY=<your-firecrawl-key>  # For enhance-colleges
OPENAI_API_KEY=<your-openai-key>        # For crawl4ai-enhance
```

## Getting Credentials

### From Supabase Dashboard

1. Log into [Supabase Dashboard](https://app.supabase.com)
2. Select the FindU production project
3. Go to Settings → API
4. Copy:
   * **Project URL** → Use in all `SUPABASE_URL` fields
   * **Anon/Public Key** → Use for `SUPABASE_ANON_KEY`
   * **Service Role Key** → Use for `SUPABASE_SERVICE_KEY` (keep secret!)

### From GitHub Secrets

If you have access to GitHub organization secrets:

1. Go to Organization Settings → Secrets
2. View the production secrets
3. Use these exact values in your local environment files

## Working with Production

Since we're using production directly:

### Best Practices

1. **Always use test accounts** when developing features
2. **Never delete or modify** real user data
3. **Be careful with bulk operations** that could affect many users
4. **Test thoroughly** before deploying changes
5. **Monitor logs** for any issues

### Creating Test Data

```sql theme={null}
-- Create a test student account
INSERT INTO students (email, name, profile_data)
VALUES ('test@example.com', 'Test User', '{"test": true}');

-- Mark as test account to avoid confusion
UPDATE students 
SET profile_data = jsonb_set(profile_data, '{is_test}', 'true')
WHERE email LIKE '%test%';
```

## Service Configuration

### Railway Services

All services deploy automatically from the main branch:

* **Web App**: [https://findu-web-production.up.railway.app](https://findu-web-production.up.railway.app)
* **Matching API**: [https://findu-matching-production.up.railway.app](https://findu-matching-production.up.railway.app)
* **Data Scripts**: Scheduled jobs for data updates

### Supabase Features

* **Database**: PostgreSQL with RLS enabled
* **Auth**: Email, Apple, and Google sign-in
* **Storage**: Public bucket for school images
* **Edge Functions**: Serverless functions for specialized tasks

## CI/CD Integration

GitHub Actions use organization secrets:

### Standard Secret Names

* `SUPABASE_URL`
* `SUPABASE_ANON_KEY`
* `SUPABASE_SERVICE_KEY`
* `RAILWAY_TOKEN`
* `COLLEGE_SCORECARD_API_KEY`
* `FIRECRAWL_API_KEY`
* `OPENAI_API_KEY`

These are configured at the organization level and available to all repositories.

## Local Development Tips

### Using Supabase CLI

```bash theme={null}
# Install Supabase CLI
brew install supabase/tap/supabase

# Login to Supabase
supabase login

# Link to production project
supabase link --project-ref your-project-id

# Generate types for TypeScript
supabase gen types typescript --linked > types/supabase.ts
```

### Database Migrations

```bash theme={null}
# Create a new migration
supabase migration new your_migration_name

# Apply migrations locally first
supabase db push

# Then push to production (be careful!)
supabase db push --linked
```

## Safety Guidelines

<Steps>
  <Step title="Use test accounts">
    Create dedicated test accounts:

    ```sql theme={null}
    -- Always use emails with 'test' in them
    INSERT INTO auth.users (email) 
    VALUES ('test-feature-x@example.com');
    ```
  </Step>

  <Step title="Backup before major changes">
    ```bash theme={null}
    # Export data before risky operations
    supabase db dump -f backup.sql --linked
    ```
  </Step>

  <Step title="Test migrations locally">
    ```bash theme={null}
    # Reset local database and test
    supabase db reset
    supabase migration up
    ```
  </Step>

  <Step title="Monitor after deployment">
    * Check Supabase logs
    * Monitor Railway deployments
    * Watch for user reports
  </Step>
</Steps>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Connection refused errors">
    Check that:

    * Your Supabase project is active (not paused)
    * Credentials are correct
    * You're using the right key type (anon vs service)
  </Accordion>

  <Accordion title="RLS policy errors">
    Some operations require service role key:

    * Bulk updates
    * Admin operations
    * Data migrations
  </Accordion>

  <Accordion title="Environment variable not found">
    Make sure:

    * File is named correctly (.env, not .env.local)
    * You've restarted the development server
    * Variables use correct naming convention
  </Accordion>
</AccordionGroup>

## Security Notes

* **Never commit environment files** - They're gitignored for a reason
* **Rotate credentials regularly** - Especially if exposed
* **Use service keys sparingly** - Only for admin operations
* **Monitor access logs** - Watch for suspicious activity

***

Next, learn about [database operations](/database/overview) to understand the schema, or check out the [architecture overview](/architecture) to see how all components work together.
