Skip to content

Work · Energy

PetraOS

Petromex uses PetraOS on every fuel deal to connect sales, customer approval, contracts and proof of delivery.

Role
Technology Consultant and Product Builder
Period
March 2026–present
Status
Live · Private source
Stack
Next.js / TypeScript, Supabase, Anthropic SDK, Email / WhatsApp, Vitest
PetraOS: Product view, synthetic data.

01 Operate

How a fuel sale changes hands

Before a tanker can deliver fuel, sales has to agree on terms, compliance has to qualify the customer, and finance and logistics need the signed documents. When responsibility changes hands, the next person needs to see what has been approved and what is still missing.

I worked with Petromex staff to map those decisions, designed the operator and customer workflows, and built and deployed PetraOS with AI coding tools. Petromex sets the commercial terms and approves the customer. The software records those decisions and checks them before the deal advances.

Three-dimensional scene of a fuel tanker entering a terminal’s loading bays.
Illustrative fuel-terminal scene from the site’s 3D chapter.

02 Specify

From inquiry to proof of delivery

The pipeline records inquiry, quotation, acceptance, qualification, contract preparation, signature, countersignature, invoicing, payment, fulfillment and completion:

INQUIRY → QUOTED → ACCEPTED → QUALIFIED → CONTRACTED → SIGNED → COUNTERSIGNED → INVOICED → PAID → FULFILLMENT → COMPLETED

Not every sale follows the same sequence. The stage validator permits forward skips and single-step reversals, and requires approved customer due diligence (KYC) for any stage beyond qualification. It deliberately imposes no global payment-before-fulfillment rule: domestic and vessel transactions have different terms.

A Next.js application serves the operator portal and separate customer workflows; Supabase provides the database, authentication and document storage. Deal records connect communications, quotes, contracts, trips and events, so an operator doesn’t assemble that context by hand. Email and WhatsApp intake (Twilio), operator-triggered extraction with the Anthropic SDK, delivery confirmations, e-signature and CFDI stamping run in production on Vercel; Carta Porte helpers assemble the fiscal request fields.

One rule. A decision you can inspect.

Isolated reconstruction using synthetic data. It has no connection to the production system and uses no real client data.

Moving from QUALIFIED to CONTRACTED requires approved know-your-customer (KYC) review. Change the status and test the rule.

Requested transition

QUALIFIEDCONTRACTED

Choose a review status, then attempt the transition.

Rule shown: only APPROVED permits the transition. A missing status also blocks it.

Changing the selection resets the demonstration to QUALIFIED.

One deal, seen through the product.

Follow a sample record: first the context, then a blocked transition, and finally an allowed one. Move through it at your own pace.

Views reconstructed from the implementation, with synthetic data.

PetraOSReconstruction · synthetic data
DEMO-001

Sample customer A

Current stageQUALIFIED
Commercial owner
Sample operator
Product
Diesel
Requested volume
48,000 L · sample
Customer review
KYC pendingPENDING
Next action

Review the KYC record

Linked activity

Illustrative sequence for the same deal

  1. Linked quote

    The quote and its conversation can be consulted from the deal record.

    sample-quote.pdfFictional reference · no downloadable file
  2. Inquiry received

    Sample customer A requests a diesel quote. The volume and records in this view are fictional.

Only the stage gate is shown. Document review and signing have additional checks.

Context before action.

The operator workspace brings together the customer, owner, stage, and activity. Staff do not have to reconstruct the deal from disconnected messages.

Connect the operating record

The interface is organized around a deal and its next action, rather than disconnected metrics.

Try this rule with other states

View 1 of 3: Find the context

See evidence sources and limits

03 Ship

Status

Live
  • WhatsApp and email intake
  • Operator-triggered AI extraction (Anthropic)
  • Delivery confirmations with photos, signatures, GPS and delivered volume
  • E-signature
  • CFDI stamping

Used for every Petromex deal.

In progress
Ongoing development.
Not published
Customer counts, transaction volume and savings.

Approval, exceptions and access

Enforce the rule where the change happens.

Hiding a button is not an approval gate. KYC checks belong in the stage-validation logic and the signing endpoint. Regression tests cover pending, rejected or missing approval, including a signing request made after qualification has changed.

Model legitimate exceptions without making every transition arbitrary.

The validator separates the shared KYC invariant from payment ordering, permits legitimate forward skips and restricts backward movement to one stage at a time. Reopening a completed deal clears its resolution fields, so an active case is not still shown as closed.

Separate identity from permission.

Being signed in does not authorize someone to operate another workflow. Route tests distinguish operator and admin access from broker sessions and test token-to-deal binding on the payment-confirmation route. That is narrower, and more useful, than calling the whole application “secure.”

What the workflow tests cover

This case was checked against repository documentation, implementation and selected test definitions on October 2, 2026. The reviewed tests include stage-transition-rules.test.js, contract-sign-kyc-gate.test.ts, resource-authz-routes.test.ts, auditLog.test.ts, invoiceProvider.test.ts and carta-porte.test.js. They specify behavior for workflow gates, authorization, audit payloads, failure responses and fiscal-document helpers. Several use mocked services.

What supports these views

The walkthrough was checked against PetraOS’s operator workspace, activity history and stage validator on October 3, 2026. The composition is simplified for this case; names, deal ID, volume and documents were authored solely for the demonstration.

  • The context reflects fields and relationships in the operator workspace.
  • The block reconstructs the QUALIFIED-to-CONTRACTED KYC condition, not every contracting rule.
  • The allowed change shows how a stage change is recorded.

No private source was imported into these views, and no client services, records or files were accessed. Next, I want to measure handoff time, unresolved exceptions, document completeness and how often users need help to finish a workflow.