# ClearBudget web app

This is the browser version of the Windows budget app. It is responsive for desktop and phone, defaults to the all-time overview, and stores the signed-in user's budget in a private Supabase Postgres row. Income, recurring and one-time expenses, discounts, unexpected flags, 50/40/10 allocations, and balance destinations are included.

## Connect a Supabase project

1. Create a Supabase project and open **SQL Editor**.
2. Run [`supabase/schema.sql`](supabase/schema.sql). The table has Row Level Security policies that limit the row to its signed-in owner.
3. From the Supabase project's API settings, copy the Project URL and **publishable** key.
4. Put those two values in [`config.js`](config.js):

   ```js
   window.CLEARBUDGET_CONFIG = {
     supabaseUrl: "https://YOUR_PROJECT.supabase.co",
     supabasePublishableKey: "YOUR_PUBLISHABLE_KEY"
   };
   ```

   Never place a Supabase secret or service-role key in `config.js` or any browser code. The browser key is public; the database policies provide the user-level protection.

5. In Supabase **Authentication → URL Configuration**, set the local Site URL to `http://localhost:8000` while developing, and add that URL to Redirect URLs. After deployment, set the deployed site URL and add it as a redirect URL too.
6. Start a local static server from the project folder:

   ```powershell
   py -m http.server 8000 --directory web
   ```

   Open `http://localhost:8000`. Create an account and confirm the email if Supabase requests it.

If this is only for your own use, disable new user sign-ups in Supabase Authentication after creating your account. Your data is isolated by user ID either way, but disabling public sign-ups avoids creating extra accounts on your project.

## Put it on the internet

This is a static browser app, so it can be deployed to a static host such as Cloudflare Pages. Upload the contents of the `web` folder using Pages' Direct Upload workflow. Cloudflare documents both static HTML deployment and direct upload in its [Pages docs](https://developers.cloudflare.com/pages/get-started/direct-upload/).

After the first deployment, add the live `https://…pages.dev` address to Supabase's Auth Redirect URLs and make it the Site URL. Use the same Supabase project on every device; each device signs into the same account and loads the shared row. While the page stays open, it checks for cloud changes periodically and when it regains focus.

## Import existing Windows data

In Windows Explorer, enter `%LOCALAPPDATA%\GastosClaro` in the address bar and locate `datos.json`. In the web app, choose **Import** and select that file. Import replaces the current cloud budget, so use **Export** first if the cloud account already contains information you want to keep. The importer recognizes the PascalCase JSON written by the existing Windows app, including its legacy monthly income format.

## Privacy and backups

- Every budget row is keyed to the Supabase Auth user ID and protected by Postgres Row Level Security. Signed-out users have no table grants. Review Supabase's current [Row Level Security guidance](https://supabase.com/docs/guides/database/postgres/row-level-security) before adding other tables or sharing accounts.
- The web app never needs a service-role key.
- Use **Export** regularly as an additional personal backup. Hosting-provider backup availability and retention depend on the Supabase plan; check the current [backup guide](https://supabase.com/docs/guides/platform/backups).
- The browser uses HTTPS after deployment and Supabase Auth for email/password sign-in.
