Skip to content

ApiHost ​

One page for every option

This page covers every choice of --Persistence, --Auth, --IncludeTests and --Aspire. A label says which options a part is for; the copy in your app's docs/ folder has only yours. ApiHost stands for your app's name.

Marten

A full-stack app: a Wolverine API on ASP.NET Core and a React frontend (Vite, TypeScript, Tailwind CSS and shadcn/ui components). Data lives in PostgreSQL through Marten. In production the API also serves the built React app, so it deploys as one service.

EF Core

A full-stack app: a Wolverine API on ASP.NET Core and a React frontend (Vite, TypeScript, Tailwind CSS and shadcn/ui components). Data lives in PostgreSQL through EF Core. In production the API also serves the built React app, so it deploys as one service.

Run it ​

Without Aspire

You need the .NET 11 SDK, Node.js 22.22 or later, and Docker with the Compose plugin.

With Aspire

You need the .NET 11 SDK, Node.js 22.22 or later, and Docker with the Compose plugin.

With Aspire, one command starts the database, the API and the dev server, and opens a dashboard with their logs and traces (how):

bash
cd src/Client && npm install && cd ../..
dotnet run --project src/ApiHost.AppHost        # then open http://localhost:5173

Or start each part yourself:

bash
docker compose up -d                  # PostgreSQL on localhost:5432
dotnet run --project src/ApiHost        # the API on http://localhost:5133

In a second terminal:

bash
cd src/Client
npm install
npm run dev                           # open http://localhost:5173

With accounts

The Vite dev server forwards /api (including the SignalR WebSocket) to the API, so the browser only talks to one origin. If something doesn't start, see Troubleshooting.

Log in as demo@example.com / Demo123!. This user is created at startup in Development only, is an admin (so /admin works), and the dev server pre-fills the login form with it. Change it under DevelopmentUser in src/ApiHost/appsettings.Development.json and in src/Client/.env.development.

docker compose up -d also starts Mailpit, which catches every email the app sends in Development (confirmation, password reset, invitations): read them at http://localhost:8025. New accounts must confirm their email before they can log in; the demo user is already confirmed.

Without accounts

The Vite dev server forwards /api (including the SignalR WebSocket) to the API, so the browser only talks to one origin. If something doesn't start, see Troubleshooting.

To try the API without the UI, open src/ApiHost/ApiHost.http in Visual Studio, Rider, or VS Code with the REST Client extension, and run the requests in order. Or browse the interactive API reference at http://localhost:5133/scalar (Development only), generated from the OpenAPI document at /openapi/v1.json.

Project layout ​

src/ApiHost/
  Program.cs              All wiring: Wolverine, persistence, validation, SignalR, auth                                        (With accounts)
  Program.cs              All wiring: Wolverine, persistence, validation, SignalR                                              (Without accounts)
  Features/Todos/         The example feature: endpoints, messages, handler, model
  Features/Auth/          Log in (password, Google/GitHub, passkey, two-factor code), register, confirm email, reset password  (With accounts)
  Features/Account/       The signed-in user: profile, password, sign-in methods, passkeys, two-factor, delete account         (With accounts)
  Features/Admin/         Admin endpoints: users, roles, locks and invitations                                                 (With accounts)
  Features/Organisations/ Organisations: switching, members and roles, invitations, joining                                    (With organisations)
  Organisations/          The organisation model, its store, and choosing a session's organisation                             (With organisations)
  Realtime/AppHub.cs      SignalR hub that pushes messages to browsers
  Storage/                File storage (IFileStorage): local disk, S3-compatible or Azure Blob
  Analytics/              Google Tag Manager settings, for the client's cookie banner
  Data/Marten/            Marten setup: event store, projections, indexes                                                      (Marten)
  Data/EfCore/            AppDbContext, migrations, and migrate-on-startup                                                     (EF Core)
  Identity/               Users, JWT and refresh tokens, roles, lockout, two-factor, rate limits (used by the features)        (With accounts)
  Identity/Email/         Account emails: messages, their handler, and the SMTP sender (MailKit)                               (With accounts)
  Identity/External/      Google and GitHub set-up, and linking a provider's account to a user                                 (With accounts)
  Identity/Passkeys/      Passkey set-up (Identity's WebAuthn support)                                                         (With accounts)
src/ApiHost.AppHost/      Aspire AppHost: starts everything for development, with the dashboard                                (With Aspire)
src/Client/src/
  root.tsx, App.tsx       The HTML document (with the description and link-preview tags), and the page frame
  routes.ts, routes/      Each URL and the route module for its page, with the page's title
  pages.ts                Every page's path, and which are public: pre-rendered, and in sitemap.xml
  components/             Layout (header, navigation, footer), home page, not-found page
  features/todos/         Todo page, TanStack Query hooks, SignalR hook (useTodoRealtime)
  features/auth/          Login, register, email confirmation and password reset pages, route guards                           (With accounts)
  features/account/       Settings page and the header's user menu                                                             (With accounts)
  features/admin/         Admin page (/admin): users, roles, locks and invitations                                             (With accounts)
  features/organisations/ The organisation switcher, /organisation (members, invitations) and /join                            (With organisations)
  lib/api/                Typed API client generated from the OpenAPI document
  test/                   Unit test setup: the fake API (MSW) and render helpers
docs/                       Documentation and how-to guides
deploy/                     Production docker-compose, Caddy, and a server guide
tests/ApiHost.Tests/        Integration tests against a real PostgreSQL                                                        (With the tests)
tests/e2e/                  End-to-end tests in a real browser (Playwright)                                                    (With the tests)

Documentation ​

The docs folder explains how the app works and how to change it:

Common tasks ​

TaskCommand
With the tests Run the API tests (Docker must be running)dotnet test
Run the client's unit testsnpm test in src/Client
With the tests Run the end-to-end tests (how)npm test in tests/e2e, with the app running
Update the client's API typesnpm run gen:api in src/Client, with the API running
Lint the clientnpm run lint in src/Client
EF Core Add a database migration (how)dotnet ef migrations add <Name> --project src/ApiHost --output-dir Data/EfCore/Migrations
List the app's command-line tools (code generation, database, diagnostics)dotnet run --project src/ApiHost -- help
Publish for production (deployment)dotnet publish src/ApiHost -c Release -o publish

Created from a template ​

This project was created from the LibreSharp SaaS Starter (dotnet new saas-starter). Its documentation has these guides for every option, and how to upgrade this app to a newer version: newer template versions (dotnet new update) affect new projects only, not this one. .saas-starter.json records the template version and options this app was created with, for upgrading. See the repository for the roadmap and issues. You can delete this section (but keep .saas-starter.json).

Documentation for v0.9.0. Released under the MIT licence.