FlowPrime guides

Marketplace: companies with teams, and independent workers who serve several companies

A worked example of a two-sided marketplace on FlowPrime: companies post jobs and pay for the product, their staff work in the company's space, and independent workers (cleaners, drivers, tutors) sign in on their own and apply to jobs from any company. It uses only what is live today. Read platform_guide topic=auth first for the sign-in code and the token checks this guide relies on.

What FlowPrime does and what your product does

Part Who holds it How
Who the person is, and which company they act for FlowPrime Auth the token: sub, account, account_role
A company's team (owner and staff), invitations, removing a seat FlowPrime Auth hosted Team page, or POST /v1/orgs/{org}/accounts/mine/invites
The company's subscription and plan FlowPrime Payments and Licensing checkout, then license_customer_entitlements
Jobs, applications, assignments, reviews, who may see what YOUR database your tables, keyed by account and sub
Photos, documents, contracts FlowPrime Storage a space per company, file ids kept in your database
Splitting a payment between the company and the worker (payouts) FlowPrime Payments, on your own Stripe account with Stripe Connect turned on reseller_payee_create, reseller_payee_signup_link for the worker to finish sign-up, then reseller_booking_checkout per job; see platform_guide topic=payments, "Pay your providers"

FlowPrime has no database. Your jobs and applications need one, with backups: see "Your database" below.

The model in one picture

Sparkle Ltd  = account A  owner Ana, member Bruno  -> app "company"
Fresh Homes  = account B  owner Carla              -> app "company"
Dina         = consumer   sub dina-123             -> app "worker"

jobs:          id, account_id (A or B), title, when, status
applications:  id, job_id, worker_sub (dina-123), status

Dina applies to a job of Sparkle and a job of Fresh Homes with one login. She is never a member of either company: the link between her and a company is an application row in your database.

Step by step

1. Two sign-in apps, both customer

Use signupProfile on each app for the fields each side must give at sign-up (a company number for companies, a phone for workers).

2. Staff join their company

The company owner invites staff from the hosted Team page or through your app (POST /v1/orgs/{org}/accounts/mine/invites with the owner's own token). An invited person is seated as member of that company once they accept. Removing the seat cuts their access at the next refresh.

3. Your API checks every request

Validate every token as platform_guide topic=auth says (signature, issuer, your workspace, azp), then route by who is calling:

COMPANY_APP = os.environ["COMPANY_CLIENT_ID"]
WORKER_APP = os.environ["WORKER_CLIENT_ID"]

def company_user(c: dict = Depends(claims)) -> dict:
    if c.get("azp") != COMPANY_APP or c.get("account_role") not in ("owner", "member"):
        raise HTTPException(403, "company route")
    return c   # scope every query to c["account"]

def worker(c: dict = Depends(claims)) -> dict:
    if c.get("azp") != WORKER_APP or c.get("account_role") != "consumer":
        raise HTTPException(403, "worker route")
    return c   # scope every query to c["sub"]

@app.get("/company/jobs")
def company_jobs(c=Depends(company_user)):
    return db.jobs.where(account_id=c["account"])

@app.get("/company/jobs/{job_id}/applications")
def applicants(job_id: str, c=Depends(company_user)):
    job = db.jobs.get(job_id)
    if not job or job.account_id != c["account"]:
        raise HTTPException(404)          # another company's job: say nothing
    return db.applications.where(job_id=job_id)

@app.get("/jobs")                          # open jobs from every company
def open_jobs(c=Depends(worker)):
    return db.jobs.where(status="open")

@app.post("/jobs/{job_id}/apply")
def apply(job_id: str, c=Depends(worker)):
    return db.applications.insert(job_id=job_id, worker_sub=c["sub"], status="applied")

@app.get("/me/applications")
def my_applications(c=Depends(worker)):
    return db.applications.where(worker_sub=c["sub"])

Rules that keep the sides apart:

4. A person who is both

If a worker is also on a company's staff, seat them in that company too (an invitation). They then sign in on the company app as a member of that company, and on the worker app as themselves. Someone seated in several companies is asked which one at sign-in (the hosted account chooser), and their token names only that one.

5. Files

Give each company a space in Storage (storage_create_space), upload with a space key from your backend, and keep the file id in your database next to the job or application it belongs to (platform_guide topic=storage).

Your database

FlowPrime has no database. Jobs, applications and permissions need a durable relational database with backups, which you run next to FlowPrime:

Things that trip agents up

Where to go next