Building a Solution

A solution is a site that is also a web app. Visitors read its public pages. Its members sign in to pages of their own — a learner's courses, a client's orders — and the people who run it work in an admin area made for what it does. All of it is built in one foundation, on the site's own Application Engine: the backend service under services:.

You don't write the server. Accounts, sign-in, roles, each member's entries and who may read them, a store, an inbox, and integrations with other systems are already there in the engine. Your foundation declares what the app needs and draws every screen people use.

Audience: developers, and the agents working for them, building a site where people sign in. The SDK covers @uniweb/sdk itself; this page puts the parts of a solution together.


The four parts

partwho uses itwhat it is
Public pagesvisitors, signed in or notsection types an author composes, as on any site; records the site shows; forms a visitor fills with no account
The members' areaeach kind of member: a learner, a client, an attendeepages of section types no author composes, reading and writing the member's own entries through @uniweb/sdk
Your admin areathe people who run the solution: its instructors, its sales team, its staffyour section types too, branded, in the solution's own words
The Solution Owner Consolethe site's ownerthe engine's own administration, the same for every solution

Your admin area is the solution's; the Solution Owner Console is every solution's. Build an admin area that speaks your solution's language and does its work: a course's roster and grading, a dealership's inventory and requests. Leave to the console what every solution has, done the same way for all of them: the site's payment account, the teams and who is in them, roles, an integration's address and keys, the store's offerings and coupons. A member the console admits reaches it from your site through its Admin link (adminHref from useSession()).


The path, step by step

1. Name the roles

Start from the people, not the pages. Who comes to the site, and what does each one do? A course platform has visitors, learners, instructors and the owner; a dealership has shoppers, sales and service staff. List the pages each role needs, the ones it grows into included: a member's profile and settings, and the page a mailed link lands on.

2. Model the types, with their rules

Each kind of entry is a Model, written as a data schema: a course, a lesson, a submission. The Entity Model says what belongs in one Model and what gets a Model of its own; Data Schemas has the syntax. The engine applies a schema's rules on every write, whatever the screen does, so put the rules there:

  • append_only on a section that is added to and never edited, such as attendance;
  • readable_with: edit on a reference, so the people who edit the course read every submission to it;
  • sold_with: true on a reference, so whoever bought the course reads its lessons;
  • grantable: false on a type whose entries are never shared one by one;
  • visitor_fills: true on the fields a visitor with no account may fill.

3. Write the blueprint

blueprint.yml, beside site.yml, says how the site's engine starts (Blueprint): who may sign up, the teams it founds, who adds entries of each type, who reads or edits all of them, what visitors who aren't signed in may read, and the integrations it starts with.

Every type starts closed: only the account that runs the site adds entries of it. Open the types that need opening — the ones members create, and the ones a team keeps — and leave closed what only the owner writes. The blueprint applies once, when the engine starts; after that, the owner changes these settings in the Solution Owner Console.

4. Build the members' area and your admin area

Both are section types that read and write through @uniweb/sdk:

  • The session: useSession, sign-in and sign-up (useSignIn, useSignUp), through a provider the owner offers too (useSignIn's withProvider), and the links the engine mails (useMailedLink).
  • Entries: useEntities lists them, useEntity reads one, and useEntityWriter writes it.
  • Sharing: useAccess grants a person read, edit or admin on an entry, such as an instructor enrolling a student, and useUnits says where a new entry lands.
  • Units: a unit's administrator staffs it, says who reads or edits a type's entries in it, and archives it when its use ends, a course at the end of its term (useUnitStaff, useUnitEntryGrants). The people they invite answer in useInvitations.
  • Acting for the solution: an administrator acts through their role only after confirming it is them (useElevation). Draw your admin area's controls from what each entry says the viewer may do, since the engine decides.

Ask whether the site has an engine before drawing any of it: isBackendEnabled() from @uniweb/kit. The same foundation then also serves a site without one, and what needs the engine draws nothing there.

5. If it sells

What a site sells is an entry of its engine, such as a course or a membership, which your admin area creates through the SDK or the owner adds. A file in records/ can't be sold: it's the site's content, kept with its pages, and the engine never holds it. The owner sets what the site sells in the Solution Owner Console, and connects their own Stripe account there. Your section types draw the store and its checkout:

  • useStore reads the store's offerings, and whether the viewer holds each. Its buy sends the buyer to the payment page, or takes a free offering at once.
  • Its stateOf says what a Buy button draws from that one read (offeringState outside React).
  • useCoupon previews a code the buyer types, with what it takes off or why it can't apply, and buy takes the code it accepted. The owner makes the codes in the Solution Owner Console; the field and its words are your section type's.
  • buy(offering, { inPage: true }) keeps the buyer on your page: the payment form opens in a frame you draw (kit's Overlay), and the store says when the offering is theirs.
  • useEntitlements lists what a member holds, for a "My courses" page, and useHolders lists who holds an entry, for an instructor's roster.
  • A member cancels a subscription on the site, or takes the cancel back, through useEntitlements; ends_at says when their access ends.

A purchase gives the buyer read access to what an offering sells, and, through it, to what its sold_with references point to. The @uniweb/sdk README has the details, under Selling.

6. Tell people what concerns them

The engine writes to each member's inbox: an entry someone shared with them, an invitation. useNotifications reads it — a badge with the unread count, and the rows when the member opens them.

7. Connect other systems

An integration moves entries of a type to or from another system, through one of your foundation's mappings: a catalog feed out, a lead in (Blueprint § Integrations). One the owner set to run by hand is a button on your pages: useIntegrations lists those the member may run, useImport brings a vendor's file in after a preview, exportFile takes entries out to a file, and useSendEntry sends one entry now. Small logic, such as grading a quiz against an answer key a learner must never see, can be a compute function your foundation ships, which the platform runs.

8. Work on your machine

Build against the real engine from the start. The engine's Developer Edition runs it on your machine: uniweb create sets one up for a site that asks for backend and has a blueprint, and uniweb dev sends it your blueprint and types and serves your site against it, so every type is closed until the blueprint opens it, each entry is its owner's, and append_only holds, as in production. Walk each role's pages with an account in that role, and check that each can do what it must. uniweb dev --published runs your working copy against a published site (Testing a Web App Locally).

9. Publish, and hand over

uniweb publish takes the site live on Uniweb hosting, and the site's first publish with the backend service provisions its engine: a dedicated Application Engine deployment, with its own PostgreSQL database, started from its blueprint. Uniweb hosting and the engine are paid. The first time, the browser opens to the page where the site's owner pays.

Then the owner sets up what is theirs, in the Solution Owner Console: their payment account, the people in each team, roles, and an integration's address. None of it belongs in your files.


Where to start

Start a solution the way you start any site, from the starter template, and add the engine when you reach step 3:

uniweb create my-solution

To read a working one first, the conference template is an event site that is also an app: a programme the organiser keeps, which every member reads, and the attendance each attendee keeps for themselves. It comes with services.backend and a blueprint already wired.

uniweb create my-event --template conference

See also