Files
shared/README.md
T

170 lines
9.8 KiB
Markdown
Raw Normal View History

# shared
2026-08-04 15:17:15 +02:00
The single source of truth for code reused across every project in this workspace: a Svelte design system and application shell, and backend helpers (Postgres access, config, auth/session persistence, an AuthGuard client, log shipping) in four languages. Every project that consumes this repo — including the media-family services (CarrierNode, ContentScanner, CraftStudio, MediaViewer, KioskDisplay, ModerationHub, ProjectConfigurator) — is its own independent frontend/backend; none of them share a generic multi-flavor binary or app anymore.
2026-08-04 15:17:15 +02:00
---
2026-08-04 15:17:15 +02:00
## Tech Stack
2026-08-04 15:17:15 +02:00
| Layer | Technology |
|-------|------------|
| Web UI | Svelte, TypeScript |
| Backend helpers | Go, Node.js, Python, Java |
| Database | PostgreSQL (via `pgx`, `pg`, or `asyncpg`) |
| Package registry | Gitea npm / Go / PyPI registries |
2026-08-04 15:17:15 +02:00
---
2026-08-04 15:17:15 +02:00
## Packages
| Package | Language | Purpose |
|---|---|---|
| `@gabriel20xx/design-tokens` | CSS | Colors, typography, spacing, radii, shadows, light/dark theme variables. |
2026-09-23 05:34:02 +02:00
| `@gabriel20xx/web-ui` | Svelte | Shared application shell and reusable UI components. The complete public component inventory is documented below. |
| `@gabriel20xx/legacy-assets` | Browser JS/CSS | Legacy client-side assets, kept for a handful of older pages. |
| `repos.gfranz.ch/Gabriel20xx/shared/backend` | Go | Env config, `pgx` pools/transactions, auth persistence, an AuthGuard client (`authclient`), log shipping (`logshipper`), embedded Goose migrations, and the media-family's shared route/table surface (`mediaauth`, `mediacore`, `carriernodeclient`, `syncsocket`). |
| `@gabriel20xx/node-backend` | Node.js | `pg` pool/config/transactions/migrations, auth/session persistence, an AuthGuard client. |
| `gabriel20xx-shared-backend` | Python | `asyncpg` pool/config, auth/session persistence, an AuthGuard client. |
| `com.gabriel20xx.shared.auth` | Java | An AuthGuard client, mirroring the Go/Node/Python ones. |
2026-09-23 05:34:02 +02:00
### Public `web-ui` components
These are the complete Svelte component exports from `packages/web-ui/src/lib/index.ts` (22 components):
2026-09-23 05:34:02 +02:00
| Component | Includes |
|---|---|
| `AboutDialog` | About modal with application branding, description, version, links, and custom content. |
| `AppShell` | Application layout that composes the header, notification stack, theme, and primary-color handling. |
2026-09-23 05:34:02 +02:00
| `AuthPage` | Login, first-time setup, password-reset, and optional TOTP authentication flows. |
| `Badge` | Small inline label with default, primary, success, warning, and danger variants. |
| `Button` | Button with primary, secondary, outline, ghost, and danger variants; multiple sizes and full-width mode. |
| `Card` | Styled content section for grouping application content. |
| `Dialog` | Generic modal dialog with title, description, body, footer, and bindable open state. |
| `EmptyState` | Empty-content message with an inbox icon, title, and description. |
| `Header` | Branded application header with navigation, icons, actions, profile/settings menus, and logout. |
| `MediaPlayer` | Audio/video player with playback, seeking, volume, quality, fullscreen, keyboard controls, and custom end controls. |
| `MediaPlayerControls` | Reusable media controls for playback, seeking, volume, quality, fullscreen, optional graph toggling, and custom end controls. |
| `Metric` | Labeled metric/value display with optional detail and semantic variants. |
| `NotificationStack` | Global stack of dismissible success, error, warning, and informational notifications. |
| `Pagination` | Page navigation and page-size selection with total/item counts. |
| `PrimaryColorPicker` | Per-project primary-color selector backed by the shared color persistence helpers. |
| `ProfileDialog` | Profile username/email/password editing and TOTP settings. |
| `SectionTitle` | Section heading with optional description. |
| `SettingsDialog` | Generic settings modal with custom content or a default empty-settings message. |
| `StatusDialog` | Detailed service health/readiness status modal with refresh support. |
| `StatusWidget` | Header-friendly health/readiness indicator that polls `/healthz` and `/ready` and opens `StatusDialog`. |
| `TotpSettings` | TOTP status, setup, enable, and disable controls. |
| `UserManagement` | Role-aware user administration with listing, creation, editing, deletion, project scopes, and pagination. |
This inventory describes the public component API only; the package also exports notification helpers, primary-color helpers, and TypeScript types. When a public component is added, removed, renamed, or materially changes responsibility, update this table in the same change as `packages/web-ui/src/lib/index.ts`. Keep the table aligned with that barrel file, and do not add internal or generated components to it.
The `web-ui` components don't import `$app/state`, `$lib` stores, or a project-specific API — applications provide those through props and callbacks.
---
## How consumers actually use this
There are two different distribution paths in this workspace, used for different things:
### Vendored snapshot (the one every project actually uses)
Every consumer project vendors a full copy of this repo's tracked files into its own `shared/` directory, committed directly rather than installed from a registry. This exists because none of these projects are meant to resolve a private registry dependency in a fresh CI checkout without extra credentials, and because a git submodule pointing at this (private) repo breaks the same way — see `scripts/sync-consumers.ps1`'s own comments for the full history.
To pull the latest snapshot into every registered consumer:
```powershell
# from this repo
.\scripts\sync-consumers.ps1 -Commit -Push
```
The script copies every tracked file in this repo into each consumer's `shared/` folder, regenerates any `package-lock.json` that depends on a local `file:` package, and commits/pushes only if something actually changed ("Sync shared snapshot from `<short-sha>`"). Consumers are registered in the script's `$consumerProjects` list. A `post-commit` hook (installed via `scripts/install-sync-hook.ps1`) runs this automatically — with `-Commit` only, never `-Push` — after every commit to this repo, so pushing the sync commits it creates to each consumer is still a manual follow-up step.
### Published registry packages (for standalone/external use)
The npm, Go, and Python packages are also published to this Gitea instance's package registries, for a project that genuinely wants a version-pinned dependency rather than a vendored snapshot. `.gitea/workflows/publish-*.yml` publish on a `v*` tag push or a matching Gitea release; `PACKAGE_REGISTRY_USERNAME`/`PACKAGE_REGISTRY_TOKEN` must be configured as Actions secrets. See "Publishing" below for the details. No project in this workspace currently consumes a package this way — it exists for future/external use.
---
## Development
2026-08-04 15:17:15 +02:00
```bash
npm install
npm run check
npm run build # builds packages/web-ui/dist (gitignored, not committed)
2026-08-04 15:17:15 +02:00
npm run test:node-backend
```
```bash
cd backend
go test ./...
go vet ./...
```
---
2026-08-04 15:17:15 +02:00
## Typical `web-ui` wiring
2026-08-04 15:17:15 +02:00
```svelte
<script lang="ts">
import { AboutDialog, AppShell, ProfileDialog, SettingsDialog } from '@gabriel20xx/web-ui';
2026-08-04 15:17:15 +02:00
import { page } from '$app/state';
let aboutOpen = $state(false);
let profileOpen = $state(false);
let settingsOpen = $state(false);
</script>
<AppShell
brand="My application"
currentPath={page.url.pathname}
navItems={[{ href: '/', label: 'Dashboard' }]}
2026-08-04 15:17:15 +02:00
onLogout={() => auth.logout()}
onProfile={() => (profileOpen = true)}
onSettings={() => (settingsOpen = true)}
username={auth.user?.username ?? ''}
>
{#snippet children()}
<slot />
{/snippet}
</AppShell>
```
Import the stylesheet once, before project-specific overrides: `@import '@gabriel20xx/web-ui/styles.css';`. It uses an `sc-` class prefix, so it doesn't require Tailwind and doesn't collide with existing project classes. Set `data-theme="light"` or `data-theme="dark"` on the application root; dark is the default.
2026-08-09 10:34:06 +02:00
For authentication, use `AuthPage` and wire its callbacks to the project's auth service — every project in this workspace either talks to AuthGuard directly or proxies through its own backend to AuthGuard. See `Core/AuthGuard/README.md` for the identity service this whole authentication surface is built to work with.
2026-08-04 15:17:15 +02:00
---
## Using the Go backend package
```go
import (
"repos.gfranz.ch/Gabriel20xx/shared/backend/auth"
"repos.gfranz.ch/Gabriel20xx/shared/backend/authclient"
"repos.gfranz.ch/Gabriel20xx/shared/backend/postgres"
)
pool, _ := postgres.Open(ctx, postgres.FromEnv())
authStore := auth.NewStore(pool) // local Postgres-backed accounts
client := authclient.New(authGuardURL) // or proxy to AuthGuard instead
2026-08-04 15:17:15 +02:00
```
Use `auth.SchemaOptions{SingleUser: false, APITokens: true}` for a multi-user service that needs API tokens. This package owns persistence primitives and password/token utilities; each application still owns authorization rules, cookies, HTTP handlers, roles, and domain tables. For embedded SQL migrations, use `migrate.Up(ctx, databaseURL, embeddedMigrations, "migrations")` — this package has no application tables of its own, so migrations stay versioned with the service that owns those tables.
---
2026-08-04 15:17:15 +02:00
## Publishing
2026-08-04 15:17:15 +02:00
```bash
npm run changeset # describe the change
npm run version-packages # bump versions, commit the changelog
npm run release # publishes npm packages in dependency order (design-tokens first)
2026-08-04 15:17:15 +02:00
```
The Go module lives under `backend`, so its release tag uses the submodule prefix (`backend/v0.1.0`); push that tag and the Gitea workflow packages and uploads the module. The npm and Python workflows both skip a version already present in the registry, so retrying a partially completed release is safe.
2026-08-04 15:17:15 +02:00
---
2026-08-04 15:17:15 +02:00
## CI/CD
2026-08-04 15:17:15 +02:00
`lint.yml` and `tests.yml` each run three jobs — Node/Svelte, Go, and Python. `publish-npm.yml`, `publish-go.yml`, and `publish-python.yml` handle registry publishing as described above.