Leads4Less
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
- Local Fastify API + pg-boss worker
- PostgreSQL + PostGIS
- Google Maps Platform for browser maps and Places search
Local App Setup
- Install dependencies:
npm install - Copy
.env.exampleto.env.localand fill in at least:VITE_GOOGLE_MAPS_PLATFORM_KEYDATABASE_URLCOOKIE_SECRETGOOGLE_MAPS_SERVER_KEY
- Run the frontend:
npm run dev:web
The local backend and scripts load both .env and .env.local, with .env.local taking precedence, so you can keep the full local setup in one file during development.
If you open the app from another machine on your LAN, set VITE_API_BASE_URL and APP_ORIGIN to that host instead of localhost. In development, the frontend also auto-rewrites a localhost API URL to the current browser hostname to make local-network testing easier.
Local API Setup
- Ensure PostgreSQL is running locally with PostGIS available.
- Apply the local database migrations:
npm run migrate - Start the API:
npm run dev:api - Start the worker:
npm run dev:worker
Docker Deployment
- Copy
.env.exampleto.envand set at least:DATABASE_URLto the Compose database host, for examplepostgres://postgres:YOUR_PASSWORD@db:5432/leads4lessPOSTGRES_DBPOSTGRES_USERPOSTGRES_PASSWORDCOOKIE_SECRETGOOGLE_MAPS_SERVER_KEYVITE_API_BASE_URLVITE_GOOGLE_MAPS_PLATFORM_KEY
- Build and start the full stack:
docker compose up --build
The Compose stack starts PostGIS, waits for the database to become healthy, runs migrations automatically, and then starts the API, worker, and web containers.
Database Layout
db/migrations/0001_local_core.sqlcreates the local-first schema.db/scripts/migrate.tsapplies migrations in order and records them inschema_migrations.db/scripts/import-postal-areas.tsimports US ZIP/ZCTA and Canada FSA polygons from local GeoJSON files.db/scripts/build-postal-neighbors.tsbuilds adjacency links for deep research propagation.db/datasets/README.mddocuments the expected postal dataset locations and property names.
Postal Dataset Setup
- Place your GeoJSON files in:
db/datasets/postal/us_zcta.geojsondb/datasets/postal/ca_fsa.geojson
- Or override them with:
POSTAL_US_DATASET_PATHPOSTAL_CA_DATASET_PATH
- Import and build adjacency:
npm run seed:postal
Notes:
- Raw postal source files and generated GeoJSON datasets under
db/rawdata/anddb/datasets/postal/*.geojsonare ignored by git. - The importer expects WGS84 lon/lat GeoJSON. If a source file is projected, re-export it to
EPSG:4326before importing.
Observability commands:
npm run import:postallogs progress every 500 features by default.npm run build:postal-neighborslogs per-country progress and final adjacency totals.npm run check:postalprints current postal area and neighbor counts from the database.
You can change the import log interval with POSTAL_IMPORT_LOG_EVERY, for example:
POSTAL_IMPORT_LOG_EVERY=1000 npm run import:postal
If you want to validate the current postal tables after an import or neighbor build, run:
npm run check:postal
Google Maps Requirements
Enable these Google Cloud APIs for the keys you use:
- Maps JavaScript API
- Places API
- Geocoding API
Use a browser-restricted key for VITE_GOOGLE_MAPS_PLATFORM_KEY and a server-side key for GOOGLE_MAPS_SERVER_KEY.
Current Runtime Flow
- The React app authenticates through the local Fastify API using cookie-backed sessions.
- Search requests run through the local API and persist results in PostgreSQL.
- The worker foundation is available for asynchronous job execution and deep research expansion.
- The target architecture is fully local auth + Fastify routes + pg-boss workers + PostgreSQL/PostGIS.