Public Access
1
0

feat: migrate app to local Fastify and Postgres stack

Replace Supabase auth and search runtime with a local Fastify API, PostgreSQL/PostGIS schema, and local session handling. Scaffold the worker and deep-research foundations while keeping the existing research, dashboard, and map flows running on the new backend.
This commit is contained in:
pguerrerox
2026-03-27 13:56:54 +00:00
parent 0e4910805a
commit a1ba5ee093
44 changed files with 3756 additions and 1128 deletions
+30 -24
View File
@@ -1,35 +1,41 @@
# Leads4Less
Leads4Less is a React + Vite app for finding local business leads, saving them in Supabase, and browsing them in dashboard and map views.
Leads4Less is a React + Vite app for finding local business leads, saving them in Postgres, and browsing them in dashboard and map views.
## Stack
- React 19 + Vite
- Supabase Auth + Postgres + Edge Functions
- Google Maps Platform for maps, geocoding, and Places search
- Local Fastify API + pg-boss worker
- PostgreSQL + PostGIS
- Google Maps Platform for browser maps and Places search
## Local App Setup
1. Install dependencies:
`npm install`
2. Copy `.env.example` to `.env.local` and fill in:
- `VITE_SUPABASE_URL`
- `VITE_SUPABASE_ANON_KEY`
2. Copy `.env.example` to `.env.local` and fill in at least:
- `VITE_GOOGLE_MAPS_PLATFORM_KEY`
3. Run the app:
`npm run dev`
## Supabase Setup
1. Create a Supabase project.
2. Enable email/password auth in Supabase Auth.
3. Apply the SQL migration in `supabase/migrations/20260322120000_init.sql`.
4. Deploy the Edge Function in `supabase/functions/run-search/index.ts`.
5. Set these Edge Function secrets in Supabase:
- `SUPABASE_URL`
- `SUPABASE_ANON_KEY`
- `SUPABASE_SERVICE_ROLE_KEY`
- `DATABASE_URL`
- `COOKIE_SECRET`
- `GOOGLE_MAPS_SERVER_KEY`
3. Run the frontend:
`npm run dev:web`
## Local API Setup
1. Ensure PostgreSQL is running locally with PostGIS available.
2. Apply the local database migrations:
`npm run migrate`
3. Start the API:
`npm run dev:api`
4. Start the worker:
`npm run dev:worker`
## Database Layout
- `db/migrations/0001_local_core.sql` creates the local-first schema.
- `db/scripts/migrate.ts` applies migrations in order and records them in `schema_migrations`.
- `db/scripts/seed-postal-placeholder.ts` is a placeholder for ZIP/ZCTA and Canada FSA imports.
## Google Maps Requirements
@@ -41,9 +47,9 @@ Enable these Google Cloud APIs for the keys you use:
Use a browser-restricted key for `VITE_GOOGLE_MAPS_PLATFORM_KEY` and a server-side key for `GOOGLE_MAPS_SERVER_KEY`.
## Current Flow
## Current Runtime Flow
1. User signs in with Supabase email/password auth.
2. The app submits a search request to the `run-search` Edge Function.
3. The function geocodes the location, calls Google Places, upserts businesses, and stores job results in Supabase.
4. The dashboard and map load saved leads from Postgres.
1. The React app authenticates through the local Fastify API using cookie-backed sessions.
2. Search requests run through the local API and persist results in PostgreSQL.
3. The worker foundation is available for asynchronous job execution and deep research expansion.
4. The target architecture is fully local auth + Fastify routes + pg-boss workers + PostgreSQL/PostGIS.