# Technical documentation — greenfields

Evidence date: 2026-10-13.

Source: `git@bitbucket.org:overdrive/greenfields.git`, revision `3918f17f956e7adb3655d65662eba8ef517ead93`.

Secrets are referenced by path only. Do not copy values from `supabase/.env` or the anon key string in `lib/backend/supabase/supabase.dart` into other systems without rotation review.

## Stack

| Layer | Technology | Evidence |
|---|---|---|
| Client | Flutter (Dart SDK `>=3.0.0 <4.0.0`), FlutterFlow-generated structure | `pubspec.yaml`, `lib/flutter_flow/` |
| Routing | `go_router` 12.1.3 | `lib/flutter_flow/nav/nav.dart` |
| State | `provider` 6.0.5 — `FFAppState`, `AppStateNotifier` | `lib/app_state.dart`, `main.dart` |
| Backend | Supabase (Auth, PostgREST, Edge Functions) via `supabase_flutter` 1.10.24 | `lib/backend/supabase/` |
| Edge runtime | Deno Supabase Functions | `supabase/supabase/functions/auto_email/index.ts` |
| Email | Resend HTTP API | same function |
| CI | Bitbucket Pipelines, image `fischerscode/flutter` | `bitbucket-pipelines.yml` |
| Deploy | `ncftpput` FTP upload of `build/web/**` | pipeline step 2 |

## Repository layout

```text
greenfields/
  lib/
    main.dart                 # bootstrap, MyApp, NavBarPage
    app_state.dart            # wizard field state
    index.dart                # page exports
    auth/                     # Supabase auth managers
    backend/
      api_requests/           # AutoSentEmailCall, AWSServicesListCall
      supabase/               # client + table row classes
    flutter_flow/             # FF theme, widgets, nav
    pages/
      wizzard/                # public business journey
      wizzard_startup/        # startup journey
      login/                  # portal login
      application/, posts/, profile/, support/, notifications/, dashboard/
      step1/                  # not exported in index.dart
  android/, ios/, web/
  assets/
  supabase/
    .env                      # secrets (committed) — do not reproduce
    readme.txt                # function setup notes
    supabase/
      config.toml
      seed.sql                # empty at inspection
      functions/auto_email/
  test/widget_test.dart
  bitbucket-pipelines.yml
  pubspec.yaml
  README.md
  qrcode.png
```

Issue OVER-141 also listed `sonar-project.properties` and `sonarqube_scan.bat` at discovery; they are absent from this clone.

## Application bootstrap

1. `main()` initialises Flutter bindings, path URL strategy, `SupaFlow.initialize()`, theme, `FFAppState`, then runs `MyApp` under `ChangeNotifierProvider`.
2. `MyApp` creates `GoRouter` from `AppStateNotifier` and listens to `cEIApplicationV2SupabaseUserStream()`.
3. Initial location `/`: `NavBarPage` if logged in, else `StepStartWidget`.

Evidence: `lib/main.dart`, `lib/flutter_flow/nav/nav.dart`.

## Routing

Routes are declared as `FFRoute` entries in `createRouter` (paths include `/appLogin`, `/list`, `/post`, `/dashboard`, `/applications`, `/startupApplication`, `/profile`, `/support`, `/notifications`, `/faq`, `/moreDetails`, `/passwordForget`, `/step1`–`/step6`, `/success`, `/startupStep1`–`4`, `/startupSuccess`, `/startupLogin`, `/stepStart`).

`requireAuth` is never set to `true` on those routes. Redirect helper exists but is inactive for auth.

## Data model (client table classes)

Defined under `lib/backend/supabase/database/tables/`:

| Table | Key columns (client) |
|---|---|
| `lead` | company_*, geo, contact, `source`, `otp`, `sent`, `xtwiter` |
| `startup` | aws_*, hosting, budgets (`montly_budget`), techStack, compliance, accelerator, maintenance, workload, contact_*, `sent`, `aws_services_list` |
| `user` | `id` (auth uid), names, email |
| `company` | `user_id`, name, year_register, contacts, website, description |
| `post` | title, body, `user_id` |
| `cities`, `countries`, `states`, `subregions` | geo reference fields |

No SQL migrations defining these tables were found in the repository. Production schema is **Unknown** beyond what the Dart row classes expect. `seed.sql` is empty.

## Supabase project

| Item | Value / location |
|---|---|
| Project ref | `zbocxsdglolhcijqyyuy` (in Dart URL, function docs) |
| Client init | `lib/backend/supabase/supabase.dart` |
| Local config `project_id` | `"supabase"` in `config.toml` (local default name) |
| Auth site_url (local config) | `http://127.0.0.1:3000` |
| Function deploy note | `npx supabase functions deploy auto_email --no-verify-jwt` |

RLS policies are not represented in this repo. Whether anon clients can read/write all rows is **Unknown / Requires Confirmation**.

## Edge Function `auto_email`

- Path: `supabase/supabase/functions/auto_email/index.ts`
- Uses service env: `SUPABASE_URL`, `SUPABASE_ANON_KEY`, `RESEND_API_KEY`
- Selects `lead`/`startup` where `sent = 0`, emails HTML tables, updates `sent` to `1`
- Invoked from the Flutter app via GET `…/functions/v1/auto_email` (`AutoSentEmailCall`) with empty headers

Operator setup notes: `supabase/readme.txt`.

## External HTTP

| Call | URL purpose |
|---|---|
| `AutoSentEmailCall` | Trigger notification function |
| `AWSServicesListCall` | `https://www.jsonkeeper.com/b/GO8J` AWS services JSON |

## Auth implementation

| Concern | Detail |
|---|---|
| Manager | `SupabaseAuthManager` |
| Email sign-in / sign-up / reset / update email / sign-out / delete | Implemented in supabase auth files |
| User stream | `cEIApplicationV2SupabaseUserStream` |
| Unused | Apple/Google/Facebook/Microsoft/GitHub/Phone manager mixins |

## Platforms

### Web

- Title Greenfields; description "Silicon Overdrive "
- Manifest name still CEI Application v2
- Primary CI artefact

### Android

- `applicationId` / namespace style `com.mycompany.ceiapplicationv2`
- `minSdkVersion` 21, `targetSdkVersion` / `compileSdkVersion` 34 (as in Gradle at inspection)
- Release signing uses debug config (TODO comment)

### iOS

- Standard Flutter/iOS tree present; Sign in with Apple package present but not wired in auth manager

## CI/CD

`bitbucket-pipelines.yml` on branch `main`:

1. Flutter stable upgrade, `pub get`, `flutter build web`, publish `build/web/**` artefacts.
2. Install `ncftp`, upload with `$FTP_USERNAME`, `$FTP_PASSWORD`, `$FTP_HOST`, `$FTP_SITE_ROOT`.

No test, lint, Sonar, or mobile build steps in the pipeline file.

## Development

| Task | Documented command |
|---|---|
| Resolve packages | `flutter pub get` |
| Build web | `flutter build web` |
| Local function serve | `npx supabase functions serve --no-verify-jwt` |
| Deploy function | `npx supabase functions deploy auto_email --no-verify-jwt` |
| Set secrets | `npx supabase secrets set --env-file .env` |

Evidence: `README.md`, `supabase/readme.txt`.

## Testing

`test/widget_test.dart` is a default Flutter counter-style smoke test pumping `MyApp`. No domain tests. Likely unsuitable without mocking Supabase.

## Security notes (evidence only)

1. Supabase anon key hardcoded in client source (normal for Supabase clients; protect with RLS).
2. `supabase/.env` committed — treat as compromised until rotated; contains Resend and related secrets.
3. Edge Function documented as `--no-verify-jwt`.
4. Batch update of all `sent = 0` rows after email.
5. Soft identity for startup wizard (email + phone match only).
6. No router-level `requireAuth` on portal pages.

## Monitoring

No APM, crash reporting, or analytics package configuration was identified in the inspected tree. Pipeline has no Sonar step; discovery-time Sonar files were not in the clone.

## Relationship to other systems

| System | Relationship |
|---|---|
| Image CDN `greenfields.overdrive.co.za` / `greenfields.medmin.co.za` | Loaded by wizard UI; hosting repo unknown |
| Silicon Ark `greenfields_web` | Separate CodeIgniter/Transactflow documentation set; not proven same backend |
| jsonkeeper.com | Third-party JSON host for AWS service list |
| Resend | Transactional email for operator notifications |

## Unknown technical items

1. Production FTP site URL and DNS mapping for Greenfields.
2. Whether FlutterFlow remains the edit source of truth.
3. Full Git history beyond shallow tip (only `deploy` tip inspected here).
4. Presence and content of Sonar files on scan hosts.
5. Supabase schema DDL, RLS, and auth email templates in the live project.
