A lawyer sends a contract version to one of its parties with a link. On it the other side marks the text up in an editor that keeps every change visible, as tracked changes do: deleting our text crosses it out in red, typing is marked as added in green, and the highlighter marks a passage in yellow with a comment. Restore and Undo take marks back. They send it back once a round; each later version comes on the same link. - Migration 0014: review_links (token kept as a SHA-256, one open link a party) and review_rounds (the reply written once: their pieces, text, SHA-256, name, message; a trigger refuses any other change and every delete). Journal entries "sent for review", "review returned" (with the fingerprint of their text) and "review link closed"; audit entity "review". - The reply is a list of pieces (same, ins, del, mark). The server checks that the pieces without the added ones are exactly the version sent, so nothing changes unseen (reviews::check). - Our review page: their message, the changes numbered with the words around them and a box each, the highlights with comments, a git-style diff (line numbers, - and + lines, the changed words marked, three lines of context per hunk) and their markup. "Take the ticked changes" opens the contract page with the version form filled with our text plus those changes. - static/review-editor.js: edits work on the pieces and redraw, so our text cannot vanish; keyboard compositions and edits the browser will not cancel are compared with the text and taken as edits. - Property tests (any markup is accepted and taken back exactly; markup that changes our text unseen is refused), the fuzz text target runs reviews::check, integration tests, and the demo has the label's review of the recording agreement. - PLAN: phase 13.
891 lines
58 KiB
Markdown
891 lines
58 KiB
Markdown
# Lanna Desk (lannadesk.com, the app visa): plan
|
|
|
|
> Phases 1 to 3 built on November 17, 2026, phases 4 and 5 on November 18,
|
|
> 2026, all live at https://visa.buildfor.life. On November 19, 2026 the move
|
|
> of the documents from a directory on cnx01 into a bucket of cnx01's Garage
|
|
> was built (task 4.8) and checked in the fleet (task 4.9, cnx-network-clan
|
|
> PR #150); the documents move once that PR is deployed. Phase 6, the Non-B
|
|
> extension pack, and phase 7, the client link, were built on November 20,
|
|
> 2026, the same day every push to main became a signed release that cnx01
|
|
> installs by itself. Task 7.6, the agreements the client signs, followed the
|
|
> same day; Lanna Desk's real text goes in under Agreements once the lawyers send
|
|
> it. On November 21, 2026 the app took the name Lanna Desk and moved to
|
|
> https://lannadesk.com, the legal side of buildfor.life (B4L), an agency that also takes on legal
|
|
> work and artists' contracts; visa.buildfor.life redirects there with the
|
|
> path. The same day `/` became the public page with the logo, the back
|
|
> office moved to `/desk`, and signing out ends the id.cnx.network session
|
|
> too. Later that day lannadesk.com became Lanna Desk's own static website
|
|
> (B4L/lannadesk-web, Astro), and the app moved to https://app.lannadesk.com;
|
|
> its `/` now leads to the back office, and the texts clients read name Lanna
|
|
> Desk rather than B4L. Phase 9, the legal practice
|
|
> (clients, lawyers, contracts with versions, paper copies, the journal),
|
|
> followed that night, and phase 10, one client list, was planned. **Resume
|
|
> here: phase 8, reminders, or phase 10, whose questions are decided.**
|
|
|
|
Lanna Desk keeps the immigration records of the foreigners that it
|
|
looks after: their passports, addresses in Thailand, arrivals with the Thailand
|
|
Digital Arrival Card (TDAC), visas, extensions of stay, re-entry permits,
|
|
90-day reports and work permits. From those records it works out every
|
|
deadline, such as the next 90-day report with its filing windows or the day the
|
|
window for the next extension opens, and it prepares the documents for the
|
|
next extension of stay with the forms filled in from the records.
|
|
|
|
B4L's own foreign staff use it first. It is meant to grow into the internal
|
|
tool of a visa agency in Chiang Mai, the one planned in the business plan in
|
|
`grabowski/julia` (`C:\dev\visa_service_plan`), so the data model treats
|
|
everyone as a client of an agency whose staff see all records.
|
|
|
|
## Decisions
|
|
|
|
The first round of questions was answered on November 17, 2026.
|
|
|
|
| Question | Decision |
|
|
| ------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
| Where it runs | cnx01, installed on the host like proplan and lampbench: database `visa` on cnx01's PostgreSQL, documents in its Garage, encrypted by the app, borg backups to juliet |
|
|
| Releases (Nov 20) | as thukthuk and lampbench-web: every push to main that passes CI becomes a signed release (CalVer), which cnx01 fetches and restarts on at once (the release webhook, since Nov 23; the 15-minute timer as backstop); no fleet PR per release |
|
|
| Documents in Garage | bucket `visa-documents` on cnx01's Garage, 10 GB (Nov 19, 2026); the app encrypts each file before it leaves the app, so Garage holds no key; Garage's SSE-C is off |
|
|
| How it is published | bkk01 publishes `app.lannadesk.com` through a `modules/web-sites` app entry; `visa.buildfor.life` and the app's paths on `lannadesk.com` redirect there |
|
|
| Login | Kanidm at id.cnx.network, OAuth2 client `visa-web`, group `visa` with grabowski and oltmanns |
|
|
| Who sees what | every member of `visa` sees and edits every record, as agency staff would; a view for clients comes later |
|
|
| First extension pack | Non-B with a work permit, employer B4L, at Chiang Mai Immigration |
|
|
| Reminders | the dashboard first; later a Matrix room message and an email to the person concerned |
|
|
| Repository | public `B4L/visa` since Nov 17, 2026: it holds code and invented demo data only, so the fleet fetches it like proplan |
|
|
| Employers | companies are records of their own under Companies; a person's employer and a work permit's employer are chosen from them, and a company's page adds people to it |
|
|
| Which office (Nov 20) | part of each application: the field "Office" on the Pack and Forms tabs, Chiang Mai Immigration unless changed, so the pack's cover sheet names whichever office it goes to |
|
|
| Client link (Nov 20) | staff make a link for a person, often a new and empty record; the client fills in personal details, the passport (with the MRZ reader, also from a photo taken on the phone), the address in Thailand and contact, and uploads scans (passport pages, photo, TDAC) |
|
|
| Client input (Nov 20) | goes straight into the person's record, logged as coming from the link; staff check it |
|
|
| Link lifetime (Nov 20) | 14 days, or until the client presses Send or staff close the link |
|
|
| Passport photo (Nov 20) | read in the browser with Tesseract.js and an MRZ model served by the app; the photo never leaves the device, only the lines it finds are sent, and the server checks them like typed ones |
|
|
| Client agreements (Nov 20) | built into the app rather than run as a separate signing service (DocuSeal was weighed: its embedding, single sign-on and branding are paid, and it would be a second store of client identities): any number of agreements in versions whose text never changes, each signed on the client link with the typed name and a drawing; the data processing agreement first, legal services and consultations later. The texts come from Lanna Desk's lawyers. Since Nov 21 the texts clients read name Lanna Desk, not B4L (Alex) |
|
|
|
|
Kanidm keeps persons, groups and OAuth2 clients in one namespace, so the
|
|
client cannot be called `visa` like the group. It is `visa-web`, as
|
|
lampbench's client is `lampbench-web`.
|
|
|
|
## How it is built
|
|
|
|
The stack is the one of proplan, the fleet overview and lampbench-web: one
|
|
Rust binary (axum 0.8, minijinja templates, sqlx on PostgreSQL) with its
|
|
templates, static files and migrations compiled in. Pages are rendered on the
|
|
server and work without JavaScript; `static/app.js` only switches the theme,
|
|
filters lists and asks before a delete. The Content Security Policy allows no
|
|
inline script or style.
|
|
|
|
- **Login.** OpenID Connect with PKCE and a nonce against Kanidm, ported from
|
|
the fleet overview (`src/oidc.rs`). Only members of `visa` get a session.
|
|
Without a login provider the app starts only with `VISA_INSECURE_NO_LOGIN=1`
|
|
on a loopback address, for development.
|
|
- **Sessions.** In PostgreSQL, keyed by the SHA-256 of the cookie's value, so
|
|
a deploy does not sign anyone out and a database dump holds no usable
|
|
session. The cookie is `__Host-visa` (Secure, HttpOnly, SameSite=Lax).
|
|
- **Forms.** Every POST must come from this site (`Sec-Fetch-Site`, else
|
|
`Origin`) and carry the session's form token (`csrf`).
|
|
- **Audit.** Personal data falls under Thailand's Personal Data Protection Act
|
|
(PDPA). Every view of a person and every change is written to `audit_log`
|
|
with the login, the record and the names of the changed fields, never their
|
|
values. The table refuses updates and deletes. The Activity page lists it.
|
|
- **Documents.** Scans and photos lie in the bucket `visa-documents` of
|
|
cnx01's Garage, one object per document, encrypted by the app with
|
|
AES-256-GCM before they leave it. Each file has a key of its own, derived
|
|
with HKDF-SHA256 from the app's file key and a random salt in the file's
|
|
header, and the document's id is authenticated with it, so a file renamed
|
|
to another document's id does not open. The file key is a systemd
|
|
credential that is never in the database or in Garage, so neither the
|
|
bucket nor its backups can be read without it. A small S3 client of the
|
|
app's own (SigV4 signing on reqwest and ring, as proplan does) talks to the
|
|
bucket and never replaces an object; in local development the same files
|
|
lie in a directory instead. What is known about each file is in the
|
|
database: its kind, the record it belongs to, the date on it, a note, its
|
|
name, type, size and SHA-256.
|
|
- **Passport data entry.** The two lines of the machine-readable zone (MRZ)
|
|
at the bottom of the photo page fill the name, nationality, date of birth,
|
|
sex, passport number, issuing state and expiry date. Their check digits
|
|
catch typing errors (ICAO Doc 9303, part 4).
|
|
|
|
## Data model
|
|
|
|
Phase 1 holds people, passports and addresses; phase 2 adds what a stay is
|
|
made of.
|
|
|
|
| Table | Holds | Phase |
|
|
| -------------------- | --------------------------------------------------------------------------------------------------------------------------- | ----- |
|
|
| `people` | names as in the passport, title, sex, birth date and place, nationality, occupation, employer (a company), phone, email, notes; archiving | 1 |
|
|
| `passports` | number, issuing state, issue and expiry dates, issuing authority, the MRZ as read; the current one has the latest expiry | 1 |
|
|
| `addresses` | the address in Thailand in the order Thai forms use, moving dates, the house master and the TM.30 receipt | 1 |
|
|
| `sessions` | signed-in sessions | 1 |
|
|
| `audit_log` | who viewed or changed which record, append-only | 1 |
|
|
| `companies` | name in English and Thai, the 13-digit registration number with its check digit, address, the office's GPS position, the director who signs; archiving | 2, 4 |
|
|
| `visas` | visa category (Non-B, Non-O, DTV and others), number, place and date of issue, validity, entries | 2 |
|
|
| `arrivals` | arrival date, port, flight, visa used, permitted-until date, TDAC number; departure date when the person left | 2 |
|
|
| `extensions` | extensions of stay: approval date, new permitted-until date, reason, office, receipt | 2 |
|
|
| `reentry_permits` | TM.8 permits, single or multiple, valid until | 2 |
|
|
| `ninety_day_reports` | the report date, the way it was filed, the receipt and the next due date printed on it | 2 |
|
|
| `work_permits` | number, employer (a company), position, validity | 2 |
|
|
| `documents` | uploads of a person (tied to one of their records, or none) or of a company: kind, date on the document, note, file name, type, size, SHA-256; the file itself lies encrypted in the bucket | 4 |
|
|
|
|
## Deadline rules
|
|
|
|
The rules below come from the Immigration Bureau's pages. Where the receipt
|
|
or the stamp shows a date, that date wins over any calculation, and the app
|
|
shows a calculated date as an estimate until a receipt confirms it.
|
|
|
|
- **90-day report (TM.47).** The day of arrival counts as day 1, so the first
|
|
report is due on the arrival date plus 89 days. After each report the
|
|
receipt names the next date. Leaving Thailand ends the count; after the
|
|
next arrival it starts again from day 1. A report in person, or by someone
|
|
the person authorizes, is accepted from 15 days before to 7 days after the
|
|
due date. Online it is accepted from 15 days before to 7 days before. The
|
|
first report after a new passport, and the first after an extension of
|
|
stay, is made in person. A late report costs 2,000 THB; being caught
|
|
without one, up to 5,000 THB. An extension of stay starts the count again,
|
|
so when the permission to stay ends before the next report is due, the app
|
|
shows no report: the person either leaves or extends.
|
|
- **Extension of stay (TM.7).** The application must be made before the
|
|
permitted-until date. Chiang Mai accepts it from 30 days before (some
|
|
categories 45); the app opens the window 30 days before and counts down to
|
|
the last working day, the Friday when the permission ends on a weekend.
|
|
An overstay costs 500 THB a day, at most 20,000 THB. A first application
|
|
for work is often stamped "under consideration" for 30 days; the app then
|
|
shows the day to return for the decision.
|
|
- **Passport.** An extension never runs past the passport's expiry, so the
|
|
app warns 12 months before expiry and marks a passport with less than six
|
|
months left.
|
|
- **Re-entry permit (TM.8).** Leaving without one cancels the extension of
|
|
stay; a planned trip without a valid permit raises a warning.
|
|
- **TM.30.** The house master reports the person's address within 24 hours
|
|
of arrival, also after a trip abroad; extensions and 90-day reports ask for
|
|
the receipt.
|
|
- **TDAC.** Submitted online within the three days before each arrival; its
|
|
number replaces the old TM.6 card number on the forms.
|
|
|
|
Sources: Immigration Bureau, TM.47 online manual
|
|
(bangkok.immigration.go.th/en/tm47online-manual); Immigration Division 1 form
|
|
downloads (bangkok.immigration.go.th/en/downloads_en); thailand.go.th,
|
|
"Business visa extension for foreigners working in Thailand"; TDAC manual
|
|
(tdac.immigration.go.th/manual/en).
|
|
|
|
## The Non-B extension pack (phase 6)
|
|
|
|
For an extension of stay based on work, Chiang Mai Immigration asks for the
|
|
following. The pack lists each item with its state (generated, uploaded,
|
|
missing, out of date, or not needed for this person) and prints them in this
|
|
order.
|
|
|
|
1. TM.7 with a 4 x 6 cm photo, the acknowledgment of overstay penalties and
|
|
STM.2, all filled in from the records.
|
|
2. STM.1, the employer's certificate of employment.
|
|
3. Copies of the passport: the photo page, the visa, the latest arrival stamp,
|
|
earlier extensions, and the TDAC.
|
|
4. The last 90-day receipt and the TM.30 receipt.
|
|
5. The work permit and its copy.
|
|
6. B4L's company documents: the company certificate and the list of
|
|
shareholders (BOJ.5), both certified within six months; the latest
|
|
balance sheet with PND.50; PND.1 withholding tax and SPS 1-10 social
|
|
security for the last three months; PP.30 VAT returns; the applicant's
|
|
PND.91; a map; photos of the office outside and inside. Every page carries
|
|
the company seal and the director's signature, in two sets.
|
|
|
|
The company documents are shared by every employee's pack, so they are kept
|
|
once per company with their own expiry (a certification older than six months
|
|
counts as out of date).
|
|
|
|
How the app judges each item, at the date of the application (`src/pack/`,
|
|
a unit test per rule):
|
|
|
|
- **Forms** are generated from the records; one with blank lines is marked
|
|
"Has blanks" with links to what fills them.
|
|
- **Copies of records** (the passport's photo page, the visa, the last
|
|
arrival's stamp and TDAC, the re-entry permit when the last arrival used
|
|
one, the stamp of every extension approved since the passport was issued,
|
|
the last 90-day receipt, the TM.30 receipt of the current address, the work
|
|
permit): a document of the kind tied to that record, else one tied to no
|
|
record. A copy tied only to another record (an earlier passport or
|
|
arrival) is out of date. Arrivals before May 1, 2025 had no TDAC.
|
|
- **The photo** was taken within the six months before (the date on it, else
|
|
the day it was added). It is glued to TM.7, so it is brought along rather than printed.
|
|
- **The company certificate and BOJ.5** were certified by the registrar
|
|
within the six months before; the page says until when each counts.
|
|
- **The balance sheet with PND.50** is the latest year's: dated at the end of
|
|
the year it covers, it counts for 17 months, since the next year's are
|
|
filed within five months of its end.
|
|
- **PND.1, SPS 1-10 and PP.30** cover the last three months: the newest is
|
|
dated within the two months before, and every one of the last four months
|
|
goes into the pack, oldest first.
|
|
- **The applicant's PND.91** of the latest year is dated within the 15 months
|
|
before; someone whose first work permit was issued this year has none yet.
|
|
- **A map** is any; **photos of the office** are two or more (outside, with
|
|
the number and the name of the company; inside, with the staff at work).
|
|
- A document whose date matters but is not recorded goes into the pack, and
|
|
the page asks for its date.
|
|
|
|
The PDF starts with a cover sheet: the contents with the page of each item,
|
|
what is still missing, and what to do before handing it in (print two sets,
|
|
the signatures, the company's seal on every page of the employer's
|
|
documents, the photo, the fee of 1,900 THB and the originals to bring).
|
|
|
|
Sources: thailand.go.th, "Business visa extension for foreigners working in
|
|
Thailand" (guide-book-detail/006_008); Immigration Division 1, "List of
|
|
documents required to support an application by a foreigner for extension of
|
|
a Non-Immigrant Visa Category B" (counter M); Ministry of Foreign Affairs,
|
|
Non-Immigrant Visa B (a photo taken within the past six months).
|
|
|
|
## Phases
|
|
|
|
Each phase ends with the tests, clippy, formatting, screenshots in light and
|
|
dark at desktop and phone width, a commit and a push.
|
|
|
|
| Phase | Content | Status |
|
|
| ----- | --------------------------------------------------------------------------------------------------------------- | ---------------------------- |
|
|
| 1 | App, Kanidm login, people, passports with MRZ reading, addresses in Thailand, audit log, demo data, CI | built Nov 17, 2026 |
|
|
| 2 | Companies; stays: visas, arrivals with TDAC, extensions, re-entry permits, 90-day reports, work permits; deadlines | built Nov 17, 2026 |
|
|
| 3 | On cnx01: flake package, fleet module, Kanidm client and group, bkk01 site, backups; real data from here on | live Nov 17, 2026 |
|
|
| 4 | Documents: encrypted uploads (passport pages, TDAC, receipts, photo) in a bucket of cnx01's Garage (first on the dataset `zroot/visa`) with a key var, viewing and download, all audited; the office's GPS position and photo | live Nov 18, 2026; Garage built Nov 19, 2026 |
|
|
| 5 | Filled-in forms: TM.7, STM.2, the overstay acknowledgment (STM.9), STM.11, STM.1, TM.47 and TM.8 as PDF | built Nov 18, 2026 |
|
|
| 6 | The Non-B extension pack: B4L's company documents, the checklist, one PDF to print | built Nov 20, 2026 |
|
|
| 7 | The client link: a client fills in their own record on a phone, the MRZ read from a photo, and signs Lanna Desk's agreements | built Nov 20, 2026 |
|
|
| 8 | Reminders by Matrix room message and by email; text messages later | mail and the Notifications page built Nov 22, 2026 |
|
|
| 9 | The legal practice: lawyers, clients (Thai and foreign, people and organizations), general and artist contracts with versions that never change, paper copies with ids and places, the journal as a hash-chained ledger | built Nov 21, 2026 |
|
|
| 10 | One client list: a visa record becomes part of a client; People becomes the visa clients | planned Nov 21, 2026 |
|
|
| 11 | The conflict check and the other parties of a contract; the journal's last hash sent outside the server each day | built Nov 22, 2026 |
|
|
| 12 | Originals in our care (passports, signed contracts, deeds: where each one is) and the inbox that files a pile of scans | step 1 built Nov 23, 2026 |
|
|
| 13 | The other side reviews a draft through a link: crosses out, adds, highlights; we take their changes one by one | step 1 built Nov 23, 2026 |
|
|
| later | Thai user interface, agency cases and fees, other visa categories' packs | |
|
|
|
|
### Phase 1: app, login, people
|
|
|
|
- [x] 1.1 Repository: Cargo crate `visa`, templates and static files compiled
|
|
in, migrations, CI (secret scan, format, clippy, tests against
|
|
PostgreSQL 18), pre-commit secret scan.
|
|
- [x] 1.2 Login through Kanidm (OIDC with PKCE), sessions in PostgreSQL,
|
|
group `visa`; `VISA_INSECURE_NO_LOGIN=1` for loopback development.
|
|
- [x] 1.3 Same-site check and form token on every POST; security headers.
|
|
- [x] 1.4 People: list with filter, page, create, edit, archive, restore.
|
|
- [x] 1.5 Passports: add, edit, delete; the current one marked; expiry
|
|
warnings at 12 and 6 months.
|
|
- [x] 1.6 MRZ reading with check digits, on the new person and the new
|
|
passport forms.
|
|
- [x] 1.7 Addresses in Thailand with house master and TM.30 receipt.
|
|
- [x] 1.8 Audit log with the Activity page.
|
|
- [x] 1.9 Demo data with invented people (`visa seed-demo`, development only).
|
|
|
|
### Phase 2: stays and deadlines
|
|
|
|
- [x] 2.1 Visas and arrivals: arrival date, port, flight, visa used,
|
|
permitted-until date, TDAC number and date; departures.
|
|
- [x] 2.2 Extensions of stay and re-entry permits.
|
|
- [x] 2.3 90-day reports with the next due date from the receipt.
|
|
- [x] 2.4 Work permits.
|
|
- [x] 2.5 The deadline engine as pure functions with unit tests for every
|
|
rule above (arrival plus 89 days, the windows, a trip resetting the
|
|
count, the extension window, passport and work permit expiry).
|
|
- [x] 2.6 Dashboard at `/`: every person's deadlines sorted by urgency, with
|
|
a company filter; the person's status and deadlines on the Overview
|
|
and the "Visa and stay" tab; the next deadline in the people list.
|
|
- [x] 2.7 Companies: list, page, form, archive; the employer chosen from
|
|
them on the person form and on work permits; people added to a
|
|
company from its page; the people list filtered by employer.
|
|
|
|
The six kinds of stay record and companies share one description each
|
|
(`Kind` in `src/records.rs`): one form template, one set of routes and the
|
|
same audit entries serve them all. A new kind of record is a migration and
|
|
one `Kind`.
|
|
|
|
### Phase 3: on cnx01
|
|
|
|
- [x] 3.1 `flake.nix` with `packages.visa` (crane), built in WSL against the
|
|
fleet's nixpkgs (Rust 1.95): a 9.8 MB binary, 58 MB with its closure.
|
|
- [x] 3.2 Fleet module `modules/visa` (roles `enable` on cnx01 and
|
|
`kanidmClient` on web01), database `visa` on cnx01's PostgreSQL, vars
|
|
`visa-oidc` and `postgres-visa`, `visa-admin`, VM test `checks.visa`;
|
|
group `visa` in `identity/`. The dataset `zroot/visa` and the file key
|
|
move to phase 4, which builds the uploads that use them.
|
|
- [x] 3.3 Decided on November 17, 2026: B4L/visa is public. It holds code and
|
|
invented demo data only, so the fleet fetches it like proplan and needs
|
|
no read token.
|
|
- [x] 3.4 `sites.nix` entry `visa` on bkk01 and the A record; deployed to ns1,
|
|
web01, cnx01, bkk01 and control on November 17, 2026
|
|
(cnx-network-clan PR #121).
|
|
|
|
### Phase 4: documents
|
|
|
|
- [x] 4.1 Encrypted store (`src/files.rs`): one file per document,
|
|
`<id>.vdoc`, written to a part file and synced before it takes its
|
|
name, never replaced. The file key is 64 hex digits from
|
|
`VISA_FILES_KEY_FILE` or the credential `files-key`; with the login on,
|
|
the app does not start without it and `VISA_FILES_DIR`.
|
|
- [x] 4.2 Uploads on a new Documents tab of each person: a one-line dashed
|
|
strip that takes dropped files, up to 10 files of 20 MB each and 64 MB
|
|
in all. PDF, JPEG, PNG and WebP are taken, told by their first bytes.
|
|
The kinds follow the Non-B pack, and a document may belong to one of
|
|
the person's records (passport, visa, arrival, extension, re-entry
|
|
permit, 90-day report, address, work permit). The form token is the
|
|
upload's first field and is checked before any file is read; a file
|
|
that is there already for the person is refused.
|
|
- [x] 4.3 Company documents on the company's page: the certificate, BOJ.5,
|
|
the balance sheet with PND.50, PND.1, SPS 1-10, PP.30, a map and photos
|
|
of the office, each with the date on it for phase 6's six-month rule.
|
|
- [x] 4.4 Viewing and download: a file opens in the browser's image or PDF
|
|
viewer under its own Content Security Policy, in which nothing runs, and
|
|
is never cached. A download is named after the person or company, the
|
|
kind and the date. Each record lists its documents next to its Edit
|
|
link, with "+ Document" to add one.
|
|
- [x] 4.5 Audit: upload, view (opening the file), download (a new action),
|
|
change and deletion; a company's entries carry its id
|
|
(`audit_log.company_id`). `visa files-check` reads every file back and
|
|
lists damaged, missing and stray files. `visa seed-demo` adds demo
|
|
documents: PDFs marked as demos and PNGs of shapes.
|
|
- [x] 4.6 Fleet: the dataset `zroot/visa` at `/var/lib/visa` with the files
|
|
in `files/`, the var `visa-files` with the key, the files in cnx01's
|
|
borg backups, and the VM test uploading a scan through the login
|
|
(cnx-network-clan PR #126, merged and deployed on November 18, 2026).
|
|
By November 19 four real documents had arrived on the live app, and
|
|
`visa-admin files-check` on cnx01 read all four back without a
|
|
problem.
|
|
- [x] 4.7 A company's office, asked for on November 18, 2026: its GPS
|
|
position on the company form, read from the numbers Google Maps
|
|
copies, a link to the place on Google Maps or OpenStreetMap, or
|
|
degrees, minutes and seconds, kept as decimal degrees and checked to
|
|
lie in Thailand (`src/gps.rs`); an Office card on the company's page
|
|
with the position, links that open it on either map, the newest photo
|
|
of the office, and a strip that adds a photo and returns to the card.
|
|
The photos are documents of the kind "Photo of the office", so they
|
|
are encrypted and audited like every other file.
|
|
- [x] 4.8 Documents in Garage, asked for on November 19, 2026: the files
|
|
lie in the bucket `visa-documents` of cnx01's Garage instead of the
|
|
dataset, as the fleet's other apps keep theirs, so the app can later
|
|
move into a guest of its own without its files. The app encrypts each
|
|
file exactly as before, so the bucket holds the same `VISADOC1` files
|
|
and never a key; Garage's SSE-C stays off, since its key would come
|
|
from the same secret. A small S3 client (`src/s3.rs`, SigV4 on reqwest
|
|
and ring, as in proplan) asks before it writes, so no object is ever
|
|
replaced (Garage 2.5 ignores the `If-None-Match: *` it sends as well),
|
|
and tries a busy server three times. `VISA_S3_*` name the bucket and the key; the secret
|
|
comes from the credential `s3-secret`. `visa files-migrate --from DIR`
|
|
copies the files of a directory into the bucket, each opened and
|
|
compared with its upload before and after, and may run again;
|
|
`visa files-mirror --to DIR` keeps a copy of the bucket, still
|
|
encrypted, for the backups, and a restore is `files-migrate` from it.
|
|
The tests run against an S3 server inside the test that checks every
|
|
signature (`tests/common/fake_s3.rs`), and `tests/garage.rs` against
|
|
the Garage version cnx01 runs (`scripts/dev-garage.sh`).
|
|
- [ ] 4.9 Fleet: the key `visa` and the bucket `visa-documents` (10 GB) in
|
|
cnx01's Garage, the app's S3 settings, the four live documents moved
|
|
into the bucket at the first start (`files/` then becomes
|
|
`files-before-s3`, kept a week), `visa-mirror` before each borg run
|
|
into `/var/lib/visa/s3-mirror`, and the VM test moving a scan from the
|
|
directory into the bucket through the deploy. Built and checked in
|
|
cnx-network-clan PR #150 (branch `visa-s3`, opened Nov 19, 2026); Alex
|
|
merges and deploys it. After the deploy: `visa-admin files-check` on
|
|
cnx01 and an upload on the live app.
|
|
|
|
### Phase 5: filled-in forms
|
|
|
|
- [x] 5.1 The blank forms as the Immigration Bureau publishes them, in
|
|
`forms/` with their sources and checksums in `forms/README.md`: TM.7,
|
|
STM.2, STM.9 (the acknowledgment of the penalties for overstay),
|
|
STM.11, STM.1, TM.47 and TM.8. Each page goes unchanged into a new PDF
|
|
and the values are written on its dotted lines in Sarabun, the font of
|
|
the forms; a box is ticked and the person's title circled where the
|
|
form asks for that. Signatures, the photo and the officers' parts stay
|
|
blank.
|
|
- [x] 5.2 Where each value goes: `scripts/gen_layout.py` finds the dotted
|
|
lines in the blank PDFs and writes `src/papers/layout.rs`. TM.47 has no
|
|
dotted lines, so its blanks are measured from the lines drawn on it. A
|
|
new version of a form needs the script run again and every page checked.
|
|
- [x] 5.3 The values (`src/papers/values.rs`) come from the person, the
|
|
passport that runs longest, the current address, the last arrival with
|
|
its visa and permission to stay, the work permit and the employer, and
|
|
the date of the company certificate from the company's documents. They
|
|
are written in capitals with the Western year, as the passport has
|
|
them. What only the application says (the date, the office, the reason,
|
|
the days asked for, which yearly extension it is, a trip for TM.8) is
|
|
on the tab, with defaults from the records, and travels in the links as
|
|
query parameters, so none of it is stored.
|
|
- [x] 5.4 A Forms tab on each person: every form with what it is for, Open
|
|
and Download, and what would stay blank, each with a link to where it
|
|
is added. "The extension's five forms" gives TM.7, STM.2, STM.9, STM.11
|
|
and STM.1 in one PDF, in the order the officer reads them.
|
|
- [x] 5.5 New fields for the forms (`migrations/0005_forms.sql`): a
|
|
company's registered and paid-up capital, the year of its latest
|
|
financial statements with the revenue and the owners' equity, the
|
|
foreign staff's pay for the next year, its Thai and foreign staff, and
|
|
a coordinator for immigration; a work permit's monthly salary and
|
|
contract dates; where an arrival came from. A Thai year such as 2568 is
|
|
taken as 2025.
|
|
- [x] 5.6 Audit: opening or downloading a form is logged as `form` with the
|
|
codes of the forms, never their values.
|
|
- [x] 5.7 The commit that runs, asked for on November 18, 2026: the footer
|
|
of every page names it with a link to it, and `/version` answers with
|
|
the full hash without a login. The flake passes its source's revision
|
|
to build.rs as `VISA_COMMIT`, set on the package alone so that the
|
|
dependencies' build stays the same; a build in a checkout asks git.
|
|
Live with the release after `a2cedcd`.
|
|
|
|
### Phase 6: the Non-B extension pack
|
|
|
|
- [x] 6.1 The rules (`src/pack/mod.rs`): every item of the pack in the
|
|
officer's order with its state at the date of the application, as a
|
|
pure function of the records and the documents, with a unit test per
|
|
rule ("The Non-B extension pack" above).
|
|
- [x] 6.2 A Pack tab on each person: the six parts with each item's state,
|
|
what it holds (the form, the files with their dates), and what fixes
|
|
it: the upload with the kind and the record chosen (`?for=` and the new
|
|
`?kind=` on the Documents tab and on a company's page), a document's
|
|
date, or a record to add. The application's fields are those of the
|
|
Forms tab, and the two tabs carry them to each other.
|
|
- [x] 6.3 One PDF to print (`/people/{id}/pack.pdf`, `src/pack/pdf.rs`): the
|
|
cover sheet, the five forms, then every copy in the pack's order. An
|
|
uploaded PDF goes in page by page as it is (a PDF 2.0 file makes the
|
|
pack 2.0), an image is turned as its EXIF tag says, and a file that
|
|
cannot be read gets a page that says so. Since November 21 (Alex:
|
|
orient pages for print, do not blow small pictures up to A4, a card's
|
|
two sides on one sheet) every page is A4 upright: a PDF page or a
|
|
whole-page picture that lies wider than tall is turned onto it, a PDF
|
|
page is only made smaller, never larger, and a picture never prints
|
|
larger than its resolution (its JFIF or PNG dpi, else 150 dpi) nor
|
|
than its kind's box: passport pages, visas and stamps 180 x 128 mm,
|
|
cards 130 x 90 mm, a phone's screenshot (TDAC, or anything twice as
|
|
tall as wide) 150 x 75 mm, at the top of the page. The new kind "ID
|
|
card" and the work permit are cards: two pictures uploaded together
|
|
are its front and back (`documents.back_of`, migration 0008), listed
|
|
together, printed on one sheet in the pack and from the Documents tab
|
|
(`.../documents/{id}/sides.pdf`). Bookmarks lead to each item. Opening or saving it logs the
|
|
forms' codes and a view or download of every document that went in.
|
|
- [x] 6.4 A company's page shows its part of every employee's pack, with
|
|
until when each certification counts and what to upload.
|
|
- [x] 6.5 The extension's deadline (Deadlines page, a person's deadlines)
|
|
links to the pack when the person has an employer. The tabs fit a 390
|
|
px phone: "Visa and stay" reads "Stay" there.
|
|
- [x] 6.6 Demo data: copies of Erika's visa, arrival stamp, extension stamp,
|
|
re-entry permit and work permit, and the employer's balance sheet,
|
|
three months of PND.1, an undated SPS 1-10 and a map, so every state
|
|
shows (the BOJ.5 is out of date, PP.30 missing, one office photo).
|
|
- [x] 6.7 Settled: which office (decisions table).
|
|
|
|
### Phase 7: the client link
|
|
|
|
Planned on November 20, 2026, from Alex's answers (decisions table).
|
|
|
|
- [x] 7.1 Links: staff make a link on a person's page, and "+ New client" in
|
|
the people list makes a record with only the name staff know (and an
|
|
email address, if any) with its link. The app keeps only the SHA-256 of
|
|
the link's token, as with sessions: it shows the link once, to copy, to
|
|
email or as a QR code to show on a phone, and a new link closes the
|
|
person's earlier one. The person's page lists the newest three links
|
|
with their state (open, opened, sent, closed, expired), and staff close
|
|
one (`src/links.rs`, `src/web/links.rs`, `migrations/0006`).
|
|
- [x] 7.2 The client's pages at `/c/<token>`, the one part of the app open
|
|
without a login: about you, the passport, the address in Thailand,
|
|
contact, the documents, and Send. Plain English, phone first, each part
|
|
saved on its own; the link's own form token and the same-site check;
|
|
nothing about anyone else (`src/web/client.rs`, `templates/client*.html`
|
|
in a frame of their own). The parts show what the record holds, so the
|
|
client corrects rather than retypes. A passport from a zone fills in
|
|
the personal details still empty. A passport with the same number is
|
|
changed; an address unlike the current one is added beside it, so the
|
|
current one and its TM.30 receipt stay until staff check; a second
|
|
save changes what the link added. After Send, or 14 days, or once staff
|
|
close it, the link shows only that it is closed.
|
|
- [x] 7.3 The passport from a photo, built ahead on November 20, 2026 on
|
|
the staff's new person and new passport forms (the client's pages
|
|
reuse `templates/_mrz_photo.html`). "Take a photo" opens a camera view:
|
|
a frame of the photo page's shape and a band for the two lines, with
|
|
a hint that says when it is too dark, when there is glare on the
|
|
lines, when no lines are in the band, the picture is not sharp or
|
|
still moves, and that takes the photo by itself once the band has
|
|
looked readable and stood still for 2.5 seconds (never in the first
|
|
1.5 seconds; a second was too quick on a phone, Nov 20), counting
|
|
down in the hint; "Take the photo" takes it at once. "Choose a picture" reads any image (EXIF orientation, the
|
|
four quarter turns, a tilt either way). Reading happens in the browser
|
|
(`static/mrz-photo.js`): Tesseract.js 7 with Doubango's MRZ model, all
|
|
served by the app (`static/vendor/tesseract/README.txt`, about 6 MB,
|
|
loaded at the first photo), so the photo stays on the device. Only
|
|
those pages and those files allow WebAssembly (`'wasm-unsafe-eval'`)
|
|
and the camera (`camera=(self)`). The lines found go into the zone's
|
|
field and Read is pressed; `mrz::from_ocr` picks the first line and
|
|
the second whose check digits match best among them, cuts or fills a
|
|
miscounted filler run, and swaps look-alikes (O for 0) only where a
|
|
check digit asks for it. The note then asks to compare the names,
|
|
which have no check digit. Tried on 12 made-up phone photos and 16
|
|
specimen pages: every readable zone read, except under a hard shadow
|
|
across the lines; the specimens that failed have their zone blanked
|
|
out.
|
|
- [x] 7.4 Uploads from the client into the encrypted store: the passport's
|
|
photo page, the photo, the visa, the arrival stamp, the TDAC, the work
|
|
permit and other scans, each tied to the person's newest record of its
|
|
kind where there is one. The client sees the names of what they
|
|
uploaded through the link, never the files.
|
|
- [x] 7.5 Audit: every view and change through a link is logged with the
|
|
actor `link <id>` and the names of the fields; making, sending and
|
|
closing a link too (actions `send` and `close`, entity `link`). The
|
|
person's page says when the client opened and sent the form and links
|
|
to each record changed, with the fields.
|
|
- [x] 7.6 Agreements, built on November 20, 2026 (`src/agreements/`,
|
|
`src/web/agreements.rs`, `migrations/0007`). Staff add an agreement
|
|
under Agreements by pasting legal's text (an empty line between
|
|
paragraphs, `# ` a heading, `- ` a list item) and publish it as
|
|
version 1; a published text never changes (the table refuses it), a
|
|
changed one is the next version. Every active agreement is the first
|
|
step of every client link, in its current version, and the rest of
|
|
the link opens only once each is signed (Alex, Nov 20: read and sign
|
|
first, then enter the details); every other page of the link leads
|
|
to the agreement until then and takes nothing posted to it. The
|
|
client reads it, ticks that they accept, types their name and signs
|
|
with a finger.
|
|
The signed copy is a PDF (Sarabun, so Thai prints) with the text, the
|
|
name, the drawing, the time, the link, the client's address and
|
|
browser and the text's SHA-256, kept as the person's encrypted
|
|
document of kind `agreement`. A new version is signed again at the
|
|
next link; the person's page says who has signed which version. An
|
|
agreement switched off is no longer asked for.
|
|
|
|
### Phase 9: the legal practice
|
|
|
|
Lanna Desk does more than visas: its larger work is contracts, general ones
|
|
and artists', for clients who are Thai or foreign, people or organizations
|
|
(Alex, Nov 21, 2026). Several lawyers work in the team.
|
|
|
|
- **Lawyers** (`/lawyers`): name, Thai name, license number of the Lawyers
|
|
Council of Thailand, contact, the id.cnx.network login of one who uses
|
|
the app (then "My contracts" shows theirs), in the team or left.
|
|
- **Clients** (`/clients`, record cards): a person or an organization; the
|
|
name in English and Thai, a stage name or brand, nationality, a Thai ID
|
|
number (checked), a passport number or a registration number, a contact
|
|
person, the lawyer in charge, current or former.
|
|
- **Contracts** (`/contracts`): code `LD-<year>-<number>` from a sequence,
|
|
title, kind (service, employment, lease, sale, loan, NDA, partnership,
|
|
sponsorship; the artist kinds recording, management, publishing,
|
|
performance, license, merchandise), client, other party, status (draft,
|
|
in negotiation, signed, in force, ended, terminated, not concluded), the
|
|
lawyer in charge, the dates (signed, in force, ends, notice by) and the
|
|
value. A contract in force shows its notice day 45 days ahead and its end
|
|
60 days ahead. Filters: general or artists, a lawyer, mine, those over.
|
|
- **Versions**: each a text kept in the app, a file (PDF or scan, encrypted
|
|
as the client's document of kind `contract`) or both, with a note of what
|
|
it is. Numbered per contract, never changed (a trigger refuses UPDATE and
|
|
DELETE, and a version's file cannot be deleted or its checksum changed).
|
|
A text equal to the last is not kept again. Any version reads against the
|
|
one before as a line diff.
|
|
- **Paper copies**: the paper of a version gets the id `<code>-P<n>`, to
|
|
write on it or to print as a 90 x 50 mm label with a QR code to its page
|
|
(`/papers/<id>`); its place, state (filed, out, handed over, destroyed)
|
|
and holder change, every move into the journal; id, contract, version
|
|
and description never change. Contracts has a box to find a paper by id.
|
|
- **Journal** (`/journal`): every change to the above, in words (what was
|
|
added; each field from what to what) in the transaction of the change.
|
|
Entries chain: each holds the SHA-256 of the one before and its own over
|
|
its number, time, actor, client, contract, event, detail and the hash
|
|
before. The database refuses UPDATE, DELETE and TRUNCATE. The page checks
|
|
the whole chain and every version's text and fingerprints against its
|
|
entry, and shows the last hash; the CSV export is a copy to keep outside.
|
|
Someone with the database's own rights could still rewrite the chain from
|
|
the start; a last hash written down or kept elsewhere shows that.
|
|
|
|
Open: anchoring the last hash outside the server each day (a Matrix
|
|
message, the backup); contract templates; signing contracts on the client
|
|
link; reminders of notice days and ends (phase 8); links between a client
|
|
and their visa record.
|
|
|
|
### Phase 10: one client list (planned)
|
|
|
|
Since phase 9 there are two lists of the people Lanna Desk works for:
|
|
Clients (the legal practice) and People (the visa records), and nothing ties
|
|
Erika's visa record to a client. Alex asked on November 21, 2026 whether
|
|
People should become Clients; the plan is one list in which a visa record is
|
|
part of a client. Not started: build it when Alex says so.
|
|
|
|
**The model.** `clients` is everyone Lanna Desk works for. `people` stays as
|
|
the visa record of a person client, so passports, addresses, stays,
|
|
documents, client links, signatures, the deadlines, the forms, the pack and
|
|
the audit log keep their `person_id` and work as they do.
|
|
|
|
- `people.client_id` references `clients`, unique and, once filled, not
|
|
null: a client has at most one visa record, every visa record has a client.
|
|
- One place for each fact. The passport-style name (surname, first and
|
|
middle name, title, sex, date and place of birth) stays on the visa record,
|
|
since the forms need it as printed. Phone and email move to the client
|
|
(`people.phone` and `people.email` go after the copy); the client link's
|
|
Contact page and the forms read them there. A visa client's name on the
|
|
client list is taken from the visa record ("Erika Mustermann") and is not
|
|
edited on the client form.
|
|
- Nationality becomes an ISO alpha-3 code on clients too, with the country
|
|
list the person form uses, so both say "Germany" the same way.
|
|
- Archiving is the client's: a former client's visa record is archived with
|
|
it, and restoring the client restores it.
|
|
- The audit log keeps the visa side (views and changes of a person); the
|
|
journal keeps the client, contracts and papers, and adds an entry when a
|
|
visa record is opened for a client or the client's contact changes.
|
|
|
|
**Migration 0010** creates a client for every person (kind person, the name,
|
|
nationality, phone and email from the person, status from `archived_at`, no
|
|
lawyer), sets `client_id`, then the constraint, and writes one journal entry
|
|
per client ("client added from the visa record of person N"). It runs by
|
|
itself at the first start after cnx01 fetches the release, on the live
|
|
records, and a rollback does not undo it, so it needs a test that loads
|
|
people through the migrations up to 0009, applies 0010 and checks every
|
|
person has its client with the same name and contact.
|
|
|
|
**The pages.**
|
|
|
|
- Clients: every client; a chip on the cards of those with a visa record and
|
|
their next deadline; tabs All, With contracts, With a visa record.
|
|
- A client's page: a "Visa and stay" card with the stay and the next dates,
|
|
linking to the visa record's pages, which keep their `/people/{id}/...`
|
|
addresses (client links, bookmarks and audit rows point there). A client
|
|
without one gets "Open a visa record", which asks for the passport-style
|
|
name.
|
|
- The visa record's pages show "Clients / name" above the tabs and a link
|
|
to the client's contracts.
|
|
- The sidebar: under Visas and stays, People becomes "Visa clients", the
|
|
same clients filtered to those with a visa record; Deadlines stays the
|
|
start page.
|
|
- "+ New client" on the visa side opens the client and the visa record in
|
|
one step, as `/people/new-client` does now.
|
|
|
|
**Steps.**
|
|
|
|
1. Migration 0010, the backfill test, contact read from the client.
|
|
2. The client page's visa card, the visa pages' crumb, the list filters and
|
|
the sidebar.
|
|
3. The client link writes the contact to the client; the journal entries.
|
|
4. Docs, screenshots, release; on cnx01, `visa-admin` checks that the
|
|
number of people equals the number of clients with a visa record.
|
|
|
|
**Decided with Alex (November 21, 2026).**
|
|
|
|
1. A visa client's name reads as on the visa side: "MUSTERMANN, Erika".
|
|
2. Companies and organization clients become one list too: the company
|
|
record (registration, address, director, the pack's documents) becomes
|
|
part of an organization client, as the visa record is part of a person
|
|
client. Employees stay linked to the company record, so the forms and the
|
|
pack keep working. This adds a step after step 3: migration 0011 creates
|
|
an organization client per company, and the company pages move as the
|
|
visa pages do.
|
|
3. Every lawyer and staff member sees every client for now. The model leaves
|
|
room for finer access later (a client's team of lawyers, a role per
|
|
section), so no page should assume more than the queries enforce.
|
|
|
|
### Phase 8: notifications (begun)
|
|
|
|
**Mail (built November 22, 2026).** The app sends mail by SMTP submission
|
|
to mx1 as `reminders@lannadesk.com` (`src/mail.rs`, lettre over rustls
|
|
with the system's CA bundle): `VISA_SMTP_HOST` and the other `VISA_SMTP_*`
|
|
and `VISA_MAIL_*` settings, the password from `VISA_SMTP_PASSWORD_FILE` or
|
|
the credential `smtp-password`. On the fleet the mailbox's password is the
|
|
shared var `visa-mail-reminders` (mx1 takes its hash, cnx01 the
|
|
passphrase), as for thukthuk's `no-reply@thukthuk.io`. Replies go to
|
|
contact@lannadesk.com.
|
|
|
|
The Notifications page (Office) shows how mail is set up, sends a test
|
|
mail to an address and keeps the log of every message sent or failed
|
|
(`notifications`, migration 0011), with the mail server's answer.
|
|
|
|
**Next.** The reminders themselves (what, to whom, when), a Matrix room,
|
|
and text messages once a provider is chosen.
|
|
|
|
### Phase 11: the conflict check and the journal's anchor
|
|
|
|
**Step 1 (built November 22, 2026).** A contract's other side was one line
|
|
of text. Now each other party is a row (`contract_parties`, migration 0010)
|
|
with its names in English and Thai, an ID, passport or registration number
|
|
and its role; the old line became the first party. A party is never
|
|
deleted or rewritten: taking it off marks it removed, and adding and
|
|
removing are in the journal.
|
|
|
|
The conflict check (`src/conflicts.rs`) looks for a name or number among
|
|
the clients, the other parties, the visa people and the employers. Names
|
|
match regardless of case, word order, punctuation and company words in
|
|
English and Thai, or when every word of the shorter name, at least two, is
|
|
in the longer one; numbers on their letters and digits. What a match means
|
|
depends on who is checked:
|
|
|
|
- a new party that is a client, a visa client or an employer: a conflict;
|
|
- a new or renamed client that was on the other side of a contract: a
|
|
conflict; one with a client's name or number: perhaps the same client;
|
|
- everything else (the same party in another contract, a client who also
|
|
has a visa record): a note.
|
|
|
|
A conflict or a possible duplicate stops the save until a lawyer ticks
|
|
that they looked at the matches, with what they checked; the matches and
|
|
the note go into the journal entry of the client or party. A check without
|
|
a match is noted too. `/conflicts` runs the check alone before a first
|
|
meeting and saves nothing.
|
|
|
|
**Step 2 (built November 22, 2026).** The journal's anchor
|
|
(`src/anchor.rs`, migration 0012). Every day from 07:00 Chiang Mai time
|
|
the app mails the journal's last entry number and its hash to the
|
|
addresses set on the Notifications page, when anything was added since
|
|
the last anchor; a day without news is noted without a mail, a failed
|
|
send is tried again an hour later, and "Send the anchor now" sends at
|
|
once. The mail says whether the chain checked whole, and in capitals when
|
|
it did not. A change of the recipients is itself a journal entry. Kept
|
|
outside the server, the mails show later that nobody rebuilt the journal:
|
|
`/journal/anchor?seq=…&hash=…` (linked from each mail and the Journal
|
|
page) says whether the entry still has that hash, has another one, or is
|
|
gone. A Matrix room can be a second place for it once phase 8 has one.
|
|
|
|
## Tests that try every input (Nov 23, 2026)
|
|
|
|
The client link is open to anyone who has it, so the code that reads what
|
|
people paste and upload is tried with made-up input as well as with the
|
|
cases in the tests.
|
|
|
|
- [x] Property tests on every push (`src/props.rs`, proptest, about 3
|
|
seconds of `cargo test`): the passport zone (any text reads without a
|
|
panic, a composed zone reads back, OCR finds it among other lines and
|
|
puts back digits read as letters), Thai 13-digit numbers, names in the
|
|
conflict check, positions and their links, form dates, agreement texts,
|
|
the contract diff, the journal hash, and the PDF's line wrap. Their first
|
|
run found that the photo reader dropped a one-letter given name (the K of
|
|
SMITH<<K); fixed in `mrz::first_line`.
|
|
- [x] Coverage-guided fuzzing every night (`.gitea/workflows/fuzz.yml`,
|
|
cargo-fuzz on nightly Rust, 10 minutes a target): `text` (passport zones
|
|
and OCR output, positions, names, dates, agreement and contract texts),
|
|
`upload` (JPEG, PNG, WebP and PDF files through the pack's image and PDF
|
|
code, as the Documents tab prints them) and `signed_copy` (the drawn
|
|
signature's PNG and the agreement text in the signed copy). Their bodies
|
|
are in `src/fuzzing.rs`; `fuzz/seeds/` has small real files to start
|
|
from, the grown corpus stays in the runner's cache, a crash fails the job
|
|
with its input as the artifact `fuzz-findings`, and each one goes into
|
|
`tests/fuzz_cases/<target>/` with its fix, which `cargo test` replays on
|
|
every push. The multipart reading itself is axum's (multer), so no
|
|
target of ours.
|
|
- [x] The nightly job runs on runner02 on cnx01 (Alex, Nov 23, 2026), by
|
|
its own label `cnx01` (cnx-network-clan PR #170), at 03:00 and at the
|
|
lowest CPU priority (`nice`), so the app keeps first call on the CPU.
|
|
Its first two runs found two bugs, both fixed and replayed from
|
|
`tests/fuzz_cases/`:
|
|
- a drawn signature of 798 bytes whose PNG header claimed 300 x
|
|
738,197,594 pixels made the app ask for 885 GB, and the failed
|
|
allocation ended the whole app. Pictures are now sized from their
|
|
header before krilla decodes them (`papers::picture`, at most 50
|
|
megapixels);
|
|
- a broken PDF upload made the PDF reader panic, so that person's pack
|
|
failed every time. Such a file now prints as a note page
|
|
(`pack::pdf::copies`).
|
|
|
|
## The public demo (Nov 23, 2026)
|
|
|
|
`https://demoapp.lannadesk.com`, for pitches and the website (Alex: anyone,
|
|
no login; visitors may change things; uploads and mail off; everything
|
|
starts over every night). The app's demo mode, `VISA_DEMO=1`
|
|
(`config::Auth::Demo`): no login on any address, everyone is "Demo
|
|
visitor" (actor `demo`), a note on every page (`#demo-note`, the client's
|
|
pages too), the invented data added at start when the database is empty,
|
|
every file upload refused (`DEMO_NO_UPLOADS`; a contract version keeps its
|
|
text), and a mail server in its settings refused, so nothing leaves it.
|
|
It needs a place for the files and a key, for its own demo files and the
|
|
signed copies. The server side (cnx-network-clan `cnx.visa.demo`): the
|
|
service `visa-demo` on port 8042 runs the live release, its own database
|
|
`visa_demo` and files, and `visa-demo-reset` at 04:00 drops and recreates
|
|
the database. Test: `tests/demo.rs`.
|
|
|
|
## Phase 12: originals in our care, and the inbox (planned Nov 23, 2026)
|
|
|
|
Alex: the inventory is of the originals clients hand Lanna Desk (passports
|
|
for an extension, signed contracts, title deeds) and where each one is; the
|
|
sorting takes a pile of scans and files each one to the right client, kind
|
|
and record, with a suggestion to confirm.
|
|
|
|
### Step 1: the originals register (built)
|
|
|
|
- Table `originals` (migration 0013): a code on the label (`OR-2026-0001`,
|
|
Bangkok year and a sequence, like the contracts' codes), whose it is (a
|
|
client of the legal practice or a person of the visa side, exactly one),
|
|
its kind (passport, ID card, house registration, title deed, contract,
|
|
certificate, bank book, work permit, other), what it is in words, the
|
|
contract it belongs to (optional), when and from whom it came and who
|
|
took it in, and where it is now: `held` (a place in the office), `out`
|
|
(with someone, such as Chiang Mai Immigration, and when it should be
|
|
back) or `returned` (to whom). A date when it is due back with the client
|
|
is optional too. The database refuses a delete and a change of what an
|
|
original is, whose it is and how it came: like the paper copies, it stays
|
|
on record.
|
|
- Every intake and every move is an entry in the journal (the hash chain),
|
|
with the code first, so the item's page shows its history from there.
|
|
- Pages: Legal, Originals (`/originals`: held, out, returned, all; due and
|
|
overdue chips; a box that finds a code, as a scanner types it), the
|
|
item's page (`/originals/{code}`, the address in the label's QR code,
|
|
with the move form and the history), intake from the client's or the
|
|
person's page (`/originals/new?client=` or `?person=`), and the label
|
|
(90 x 50 mm, as for paper copies). Cards on the client's and the
|
|
person's pages list theirs.
|
|
- Demo data: a passport out at Chiang Mai Immigration, a title deed and a
|
|
signed contract held, one returned.
|
|
|
|
### Step 2: the inbox (planned)
|
|
|
|
- Staff drop many scans or photos at once into Office, Inbox (no owner
|
|
yet; stored encrypted like every document; the demo takes none). Each
|
|
waits as a row with its picture and a suggestion: whose it is, its kind,
|
|
the record it goes with. One click files it as a document of that
|
|
person, company or client (the documents' own rules apply: the type by
|
|
its first bytes, no duplicate, the same audit and journal entries);
|
|
"not this" leaves it for a choice by hand.
|
|
- Suggestions, each with the reason shown, strongest first:
|
|
1. a cover sheet: the app prints a sheet per client or person with a QR
|
|
code (`/inbox/sheet?client=`); pages scanned after it in one stack are
|
|
theirs until the next sheet;
|
|
2. a passport's zone, read in the browser by the reader the passport
|
|
form already has (Tesseract.js), matched by number and name;
|
|
3. a PDF's own text (scans from an office scanner with OCR, e-documents):
|
|
names and numbers matched like the conflict check (Thai ID, passport,
|
|
registration number), and words of a kind (TM.30, ใบอนุญาตทำงาน,
|
|
โฉนด);
|
|
4. the file name ("erika passport.jpg").
|
|
- A suggestion is never filed by itself: someone confirms, and the journal
|
|
or the audit log says who.
|
|
|
|
### Step 3: later
|
|
|
|
- A receipt PDF for the client at intake and at return, with their
|
|
signature on the phone (the agreements' drawing pad).
|
|
- Originals out past their date on the Deadlines page, and in the
|
|
reminders once phase 8 sends them.
|
|
- Phase 10 (one client list) turns an original's person into a client.
|
|
|
|
## Phase 13: the other side reviews a draft (planned Nov 23, 2026)
|
|
|
|
Alex: when our lawyers draft a version, they send it to the other party
|
|
with a link; there the other party edits it and sends it back. It should
|
|
have an editor that crosses out words and highlights passages, and in the
|
|
end read like a git diff.
|
|
|
|
### Step 1: the review link and the marking editor (built)
|
|
|
|
- A lawyer sends a version with a text to one of the contract's parties
|
|
(Contract, Review by the other side). This makes a link for that party
|
|
(`/r/<token>`, shown once, as the client links; 30 days) or, when the
|
|
party has an open one, a new round on the same link, so the other side
|
|
keeps one address for the whole negotiation.
|
|
- The other side's page shows our version in an editor that keeps every
|
|
change visible, as tracked changes do: what they delete stays in place,
|
|
crossed out in red; what they type is marked in green; the highlighter
|
|
marks a passage in yellow with an optional comment. Restore takes a mark
|
|
back. They send it back with their name and a covering message, once per
|
|
round; the page then shows what they sent until our next version.
|
|
- What they send is a list of pieces (same, added, crossed out,
|
|
highlighted). The server checks that the pieces without the added ones
|
|
give exactly the version we sent: nothing can change unseen. Their text
|
|
and its SHA-256 are kept unchanged (migration 0014, a trigger), and the
|
|
journal records each send and each reply with the fingerprints.
|
|
- Our review page shows their markup and a git-style diff (lines taken out
|
|
and added, the changed words marked), with each change numbered. The
|
|
lawyer ticks the changes to take; the contract page then opens with the
|
|
version form filled with our text plus those changes, to finish and add
|
|
as the next version, which can go back to them in the next round.
|
|
|
|
### Step 2: later
|
|
|
|
- Comments both ways on a highlighted passage (a thread per mark).
|
|
- Mail the link and each new round from reminders@ (phase 8 mail).
|
|
- Signing the agreed text on the link (with the agreements' drawing pad).
|
|
- Versions kept only as a file (a PDF draft): the editor works on text.
|
|
|
|
## Open questions
|
|
|
|
1. B4L's BOI application: once B4L is promoted, its staff extend their stay
|
|
through the BOI's One Start One Stop center, which changes phase 6's pack.
|
|
2. The agreements' texts come from Lanna Desk's lawyers. Whether a typed name and
|
|
a drawing are enough for each kind of agreement is theirs to say.
|