# Project plan — intersect_backend

Evidence date: 2026-10-12.

Source repository: `git@bitbucket.org:overdrive/intersect_backend.git`.

Inspected revision: `main` at `86347d4` (2024-09-26, Jaco Brits, "Update new code"). The scan-host path `~/projects/sonar_scan/repos/intersect_backend` was not on this machine. The tree below was read from that git revision. AWS access key identifiers, SMTP passwords, and other secret values that are committed in source are omitted here.

This plan describes what the repository contains. It does not decide what the product should become.

There is no README, issue export, or prior Silicon Ark set for this repository. Related Silicon Ark sets that name the same queue table are listed under [Related documentation](#related-documentation). They are not evidence of what this repository does.

## Product

**Inferred.** A Supabase Edge Functions project that sends mail for a product whose sender address in code is `no-reply@simpleflowhub.app`. The function that sits next to the active local config reads rows from a Supabase table `send_que` and sends them through Amazon SES SMTP in `eu-west-1`. Two earlier functions under a nested Supabase folder send one message per HTTP call, or only echo a name.

No document in the repository states a product name, a customer, or a goal. The directory name `intersect_backend` comes from the onboarding task and from `project_id` in `supabase/config.toml`. The lockfile also names the package `intersect_backend`. The sender domain is `simpleflowhub.app`.

**Unknown / Requires Confirmation:** whether this repository is still deployed, which Supabase project it targets, and whether `intersect_lambda` replaced it as the worker that drains `send_que`.

## Branch reality

| Line | Tip | Date | What it is |
|---|---|---|---|
| `main` (default; `origin/HEAD`) | `86347d4` | 2024-09-26 | Only branch. 6 commits, 2024-09-11 through 2024-09-26 |

No other local or remote branches were present at inspection. Nothing in git is dated after 2024-09-26.

Authors: Jaco Brits (`jaco@overdrive.co.za`) and Dirk (`dirk@overdrive.co.za`).

## Objectives

No objectives file exists. The behaviour the commits actually introduced:

1. `bcb3d36` (2024-09-11, Jaco Brits, "Initial commit") — root `.gitignore` only. No application code.
2. `4149aa4` (2024-09-11, Jaco Brits) — `sonar-project.properties` with project key `overdrive_intersect_backend_574dd118-0a6f-46b5-ae71-3d99f677206c`.
3. `489ad2b` (2024-09-11, Jaco Brits) — `bitbucket-pipelines.yml`. SonarQube scan on `main`. No deploy step.
4. `33d1524` (2024-09-11, Dirk, "Adding edge functions") — nested tree `supabase/supabase/`: local CLI config, CLI temp files, empty `seed.sql`, and three functions (`hello-world`, `send-email`, `send-aws-ses-email`) plus two `.env` files.
5. `2e16d69` (2024-09-11, Dirk) — merge of `main` into that work. No file content of its own beyond the merge.
6. `86347d4` (2024-09-26, Jaco Brits, "Update new code") — outer `supabase/config.toml` with `project_id = "intersect_backend"`, function `supabase/functions/sent_que/` (`index.ts` and `index_old.ts`), root `package.json` depending on `nodemailer`, editor Deno settings, and an empty `supabase/seed.sql`.

## Scope

### In scope of `main` at `86347d4`

28 tracked files.

1. `supabase/functions/sent_que/index.ts` — Deno HTTP handler that loads `send_que` rows with `status` 0 and sends them with nodemailer over SES SMTP.
2. `supabase/functions/sent_que/index_old.ts` — earlier handler kept beside the current file. Not the Supabase entry file (`index.ts` is).
3. `supabase/config.toml` — Supabase CLI local config. `project_id` is `intersect_backend`.
4. `supabase/supabase/functions/send-aws-ses-email/index.ts` — POST handler that sends one HTML message with `@aws-sdk/client-ses`.
5. `supabase/supabase/functions/send-email/index.ts` — CLI hello-world template. The folder name is `send-email`. The code does not send mail.
6. `supabase/supabase/functions/hello-world/index.ts` — the same template, aimed at a function named `hello-world`.
7. `supabase/supabase/config.toml` — second CLI config. `project_id` is `supabase`.
8. `supabase/supabase/.temp/` and `supabase/supabase/.branches/_current_branch` — Supabase CLI local metadata, committed.
9. Two function `.env` files under `supabase/supabase/functions/`. They contain credentials. Values are omitted.
10. `package.json` and `package-lock.json` — `nodemailer` `^6.9.15`, locked at `6.9.15`. No scripts.
11. `bitbucket-pipelines.yml` and `sonar-project.properties` — SonarQube analysis on `main`.
12. Root and `supabase/` `.gitignore`, and two `.vscode` folders recommending the Deno extension.
13. `supabase/seed.sql` and `supabase/supabase/seed.sql` — both the empty git blob.

### Out of scope / not in this repository

- README, SQL migrations, table DDL, RLS policies, triggers, or a non-empty seed.
- A Supabase cron, scheduled function, or any other trigger definition for `sent_que`.
- Tests, a Deno config (`deno.json` / `import_map.json`), or a Dockerfile.
- A pipeline step that deploys functions. The only pipeline step is a SonarQube scan.
- `sonarqube_scan.bat`. The onboarding scan listed it beside the git files. It is not in git history.
- The application that inserts `send_que` rows. This repository only selects and updates that table.
- `intersect_cloud`, `intersect_cloud_prod`, and `intersect_lambda`. Those are separate repositories. See [Related documentation](#related-documentation).

## System architecture

What the current entry file does when it is invoked. Deployment is not in git, so the box around "caller" is unknown.

```text
Caller (unknown)
  → HTTP request to the Edge Function whose folder is sent_que
      → Supabase client (SUPABASE_URL + SUPABASE_SERVICE_ROLE_KEY)
          → table send_que where status = 0
      → nodemailer SMTP
          → email-smtp.eu-west-1.amazonaws.com:587
          → from no-reply@simpleflowhub.app
      → update that row: status 1 or 2, and result
```

The nested `send-aws-ses-email` function is a different path: one POST body (`to`, `subject`, `htmlContent`) goes to the SES API (`SendEmailCommand`). It does not read `send_que`.

`send-email` and `hello-world` do not call SES. They parse JSON `{ name }` and return `{ message: "Hello <name>!" }`.

There is no queue broker, cache, or object store in this repository. An attachment is the string already stored on the row, passed to nodemailer as `path`.

## Major components

| Component | Path | Role |
|---|---|---|
| Queue sender | `supabase/functions/sent_que/index.ts` | Drain `send_que` over SES SMTP |
| Previous queue sender | `supabase/functions/sent_que/index_old.ts` | Same table, Deno SMTP client, credentials in source |
| Direct SES send | `supabase/supabase/functions/send-aws-ses-email/index.ts` | One HTML email per POST |
| Template functions | `hello-world/index.ts`, `send-email/index.ts` | Echo `name` |
| Local Supabase config | `supabase/config.toml` | CLI project `intersect_backend` |
| Nested CLI config and link metadata | `supabase/supabase/` | CLI project id `supabase`, plus a committed project ref |
| CI | `bitbucket-pipelines.yml` | SonarQube scan on `main` |

## Milestones

The repository has no milestone document. The only sequence in evidence is the commit list under [Objectives](#objectives). Work stops at 2024-09-26.

## Implementation plan

No plan document exists in the repository or in Silicon Ark for this directory. Nothing in git describes a next milestone.

**Inferred** from the file layout, not from a plan: `index.ts` replaced `index_old.ts` as the function entry while leaving the old file in the tree, and the nested functions were not removed when `sent_que` was added.

## Known dependencies

| Dependency | Where | Notes |
|---|---|---|
| Supabase Edge Runtime / Deno | Function files use `Deno.serve` and `Deno.env` | No `deno.json`. Runtime version is not pinned |
| `@supabase/supabase-js` 2 | `sent_que/index.ts` imports `https://esm.sh/@supabase/supabase-js@2` | `index_old.ts` imports the unpinned `npm:@supabase/supabase-js` |
| `nodemailer` | `npm:nodemailer` inside `index.ts`. Root package locks `6.9.15` | The Deno import has no version. Whether the function resolves `6.9.15` is **Unknown** |
| Amazon SES SMTP | Host `email-smtp.eu-west-1.amazonaws.com`, port `587` | Username and password from `SES_SMTP_USERNAME` and `SES_SMTP_PASSWORD` in the current function |
| Amazon SES API | `npm:@aws-sdk/client-ses` in `send-aws-ses-email` | Region, access key id, and secret from `AWS_REGION`, `AWS_SES_KEY_ID`, `AWS_SES_SECRET_KEY` |
| Deno SMTP module | `https://deno.land/x/smtp@v0.7.0/mod.ts` in `index_old.ts` | Used only by the old file |
| SonarQube scan pipe `sonarsource/sonarqube-scan:2.0.1` | `bitbucket-pipelines.yml` | Host and token are pipeline variables `SONAR_HOST_URL` and `SONAR_TOKEN` |
| Pipeline image `maven:3.3.9` | `bitbucket-pipelines.yml` | No Maven project is in the tree |

Supabase CLI versions recorded in the committed temp files (nested folder only): CLI `v1.192.5`, GoTrue `v2.160.0`, PostgREST `v12.2.1`, Storage `v1.11.0`, Postgres `15.1.1.73`. `supabase/config.toml` sets `major_version = 15`.

## Current project status

**Implemented** in git, as of `86347d4`:

- One queue-drain function and one direct-send function, plus two template functions.
- Local Supabase CLI configuration, with no migrations.
- A Bitbucket Pipeline that analyses `main` with SonarQube and does not deploy.

**Not established:**

- Whether any function is deployed.
- The Supabase project the 2024-09-26 function was linked to. The only project ref in git is in `supabase/supabase/.temp/project-ref`, written on 2024-09-11 before `sent_que` existed. The pooler URL in the same folder uses host `aws-0-eu-central-1.pooler.supabase.com`, port `6543`, and the password placeholder `[YOUR-PASSWORD]`.
- Whether the committed credentials are still valid. They are in git history. Rotation is a human action. This document does not copy the values.

## Related documentation

These Silicon Ark documents talk about a table named `send_que` and the sender `no-reply@simpleflowhub.app`. This repository does not reference them, and they do not reference `intersect_backend`.

| Silicon Ark directory | What it says that touches this repo's subject | Provenance of that statement |
|---|---|---|
| `intersect_cloud/` | The Flutter client has a generated `send_que` row (recipient, subject, body, attachment, status, result). No worker in that repo drains it. The documented candidates for the sender are a database trigger, `intersect_lambda`, or something else. | Documented in that set from the Flutter tree. Not evidence about this repo |
| `intersect_cloud_prod/` | Same gap: `send_que` exists on the client, and the drainer is outside that repo | Documented in that set |
| `intersect_lambda/` | A Lambda drains `send_que` where `status` is 0, at most 15 rows, over the same SES SMTP host, and a second function sends one HTML email. Last inspected revision there is 2024-12-13, after this repo's last commit | Documented from that repo |

Behaviour that differs, if both were ever pointed at the same table:

| Behaviour | This repository (`sent_que/index.ts`) | `intersect_lambda` queue handler, as documented in Silicon Ark |
|---|---|---|
| Batch size | Every `status` 0 row. No `limit` | At most 15 |
| Success | `sendMail` did not throw | nodemailer `accepted.length > 0` |
| Stored `result` | `{"success":true,"message":"Email sent successfully"}` or the failure equivalent | The nodemailer result, or a stringified error message |
| Text body | The raw `body` column | `body` with closing tags removed |
| From address | Literal `no-reply@simpleflowhub.app` | SSM parameter `/intersectcloud-ses/no-reply-email` |
| Trigger | None in git | CloudFormation schedule `rate(1 minute)` on the Lambda stacks |

**Unknown / Requires Confirmation:** whether these are two generations of one mailer or two unrelated codebases that happen to share names.

## Human confirmation

1. Is `sent_que` deployed, and to which Supabase project?
2. Did `intersect_lambda` replace this repository? If both run, which one is allowed to update `send_que`?
3. Which system inserts `send_que` rows, and which status values does that system understand?
4. The AWS credentials committed in `index_old.ts` and in the two nested `.env` files are exposed in git. Have they been revoked?
5. Were `hello-world`, `send-email`, and `send-aws-ses-email` ever deployed from the nested directory?
6. What invokes `sent_que` (HTTP call, Supabase cron, or a manual invoke)? Nothing in git schedules it.
7. Is `sonarqube_scan.bat` an untracked local file that should be ignored, or a missing project file?
