Gabriel20xx 90080a8425
Lint / Lint (Node/Svelte) (push) Successful in 17s
Lint / Lint (Go) (push) Successful in 19s
Lint / Lint (Python) (push) Successful in 9s
Tests / Test (Node/Svelte) (push) Successful in 13s
Tests / Test (Go) (push) Successful in 20s
Tests / Test (Python) (push) Successful in 10s
fix: use public SharedCode clone URL
2026-08-06 08:59:24 +02:00
2026-08-04 15:17:15 +02:00
2026-08-06 08:59:24 +02:00

SharedCode packages

This folder is the single source of truth for reusable web UI across the projects in this workspace.

The first packages are:

  • @gabriel20xx/design-tokens — colors, typography, spacing, radii, shadows, and light/dark theme variables.
  • @gabriel20xx/web-ui — Svelte components for the application shell, header/navigation, authentication, dialogs, profile/settings/about windows, buttons, cards, badges, and page headers.
  • repos.gfranz.ch/Gabriel20xx/SharedCode/backend — Go helpers for environment configuration, pgx PostgreSQL pools, transactions, common auth persistence/passwords/tokens, and embedded Goose migrations.
  • @gabriel20xx/node-backend — Node.js pg pool/configuration, transactions, migrations, and auth/session persistence.
  • gabriel20xx-shared-backend — Python asyncpg pool/configuration and auth/session persistence.

The components do not import $app/state, $lib stores, or a project-specific API. Applications provide those things through props and callbacks.

Build and check the packages

Run these commands from this directory:

npm install
npm run check
npm run build
npm run test:node-backend

npm run build creates the distributable package in packages/web-ui/dist. The generated dist directory is intentionally ignored by the package configuration and should not be committed.

Validate the Go backend package from SharedCode/backend:

cd backend
go test ./...
go vet ./...

Consume from the Gitea repository

The repository is the canonical source and is installable directly from Gitea. The root package builds the Svelte package during installation and exposes the runtime packages as subpaths:

npm install --save-exact git+https://repos.gfranz.ch/Gabriel20xx/SharedCode#<commit>

Use the shared UI from the root package:

import { AppShell, AuthPage, Header, SettingsDialog } from '@gabriel20xx/shared-code/web-ui';

Import the shared stylesheet once from the application's global stylesheet:

@import '@gabriel20xx/shared-code/web-ui/styles.css';

The dependency should be pinned to a commit in application lockfiles. Update it when a new SharedCode version has been validated.

Publish the individual packages

The package names use the @gabriel20xx npm scope. That scope must belong to the npm account used to publish. If a different scope is preferred, replace the scope consistently in both package manifests and imports before publishing.

Publish the tokens first because web-ui depends on them:

npm login
npm publish --workspace=@gabriel20xx/design-tokens --access public
npm publish --workspace=@gabriel20xx/web-ui --access public
npm publish --workspace=@gabriel20xx/node-backend --access public

For a private registry, configure that registry and omit --access public if the registry does not use npm's public scoped-package rules.

Install individual packages from a registry

From a project's frontend directory, install the published UI package:

npm install @gabriel20xx/web-ui@^0.1.0

The design-token package is installed transitively. Install it directly only when an application needs to reference its theme file itself:

npm install @gabriel20xx/design-tokens@^0.1.0

Import the shared stylesheet once from the application's global stylesheet, before project-specific overrides:

@import '@gabriel20xx/web-ui/styles.css';

The stylesheet imports the design tokens and uses an sc- prefix, so it does not require Tailwind and does not collide with existing project class names. Set data-theme="light" or data-theme="dark" on the application root to select a theme. Dark is the default.

Use the shared Go backend package

From a Go backend directory, add the module (the module is a subdirectory of the SharedCode repository):

go get repos.gfranz.ch/Gabriel20xx/SharedCode/backend@backend/v0.1.0

Then initialize the pool and shared auth store at startup:

import (
    "context"
    "log"

    "repos.gfranz.ch/Gabriel20xx/SharedCode/backend/auth"
    "repos.gfranz.ch/Gabriel20xx/SharedCode/backend/postgres"
)

cfg, err := postgres.FromEnv()
if err != nil {
    log.Fatal(err)
}
pool, err := postgres.Open(context.Background(), cfg)
if err != nil {
    log.Fatal(err)
}
defer pool.Close()

if err := auth.EnsureSchema(context.Background(), pool, auth.DefaultSchemaOptions()); err != nil {
    log.Fatal(err)
}
authStore := auth.NewStore(pool)

Use auth.SchemaOptions{SingleUser: false, APITokens: true} for a multi-user service that needs API tokens. The shared 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"). The package does not contain application tables, so migrations remain versioned with the service that owns those tables.

The Go module lives under backend, so its release tag must use the submodule prefix (backend/v0.1.0). If the SharedCode code is moved into its own repository, update the module path and use ordinary v0.1.0 tags instead.

For Node services, install the shared package after publishing it:

npm install @gabriel20xx/node-backend@^0.1.0

For Python services, build and publish the wheel to the Python package index used by the projects, then install it normally:

python -m pip install build
python -m build packages/python-backend
python -m pip install gabriel20xx-shared-backend==0.1.0

The Node and Python packages intentionally expose the same infrastructure concepts but use their native database drivers. This is the safe way to share behavior across the polyglot services; a Go package cannot be imported by the Python or Node applications.

Existing MediaCollection shared package

Original/MediaCollection/MediaShared is an existing, larger media-specific package. It remains in place for media workflows and startup integration, while the MediaCollection WebUI authentication surface and admin-reset code use this shared package. Its remaining generic responsibilities can be migrated independently without introducing another authentication screen.

Typical application wiring

<script lang="ts">
  import {
    AboutDialog,
    AppShell,
    ProfileDialog,
    SettingsDialog
  } from '@gabriel20xx/web-ui';
  import { page } from '$app/state';

  let aboutOpen = $state(false);
  let profileOpen = $state(false);
  let settingsOpen = $state(false);

  const navItems = [
    { href: '/', label: 'Dashboard' },
    { href: '/about', label: 'About' }
  ];
</script>

<AppShell
  brand="My application"
  currentPath={page.url.pathname}
  navItems={navItems}
  onLogout={() => auth.logout()}
  onProfile={() => (profileOpen = true)}
  onSettings={() => (settingsOpen = true)}
  username={auth.user?.username ?? ''}
>
  {#snippet children()}
    <slot />
  {/snippet}
</AppShell>

<AboutDialog
  bind:open={aboutOpen}
  brand="My application"
  description="A short description supplied by this project."
  version="1.0.0"
/>

<SettingsDialog bind:open={settingsOpen}>
  {#snippet children()}
    <!-- Project-specific settings controls go here. -->
  {/snippet}
</SettingsDialog>

<ProfileDialog
  bind:open={profileOpen}
  currentEmail={auth.user?.email ?? ''}
  currentUsername={auth.user?.username ?? ''}
  onSave={(profile) => auth.updateProfile(profile)}
/>

For authentication, use the same shell with AuthPage and connect the callbacks to the application's existing auth service:

<AuthPage
  brand="My application"
  onLogin={(credentials) => auth.login(credentials.identifier, credentials.password)}
  onSetup={(credentials) => auth.setup(credentials)}
  onRequestReset={() => auth.requestAdminReset()}
  onConfirmReset={(code) => auth.confirmAdminReset(code)}
  setupRequired={setupRequired}
  tagline="Your project tagline"
/>

Applications that support MFA can enable the shared optional authenticator-code field with showTotp and forward credentials.totpToken to their login endpoint. The base layout and reset controls remain the same as every other shared auth screen.

The shared reset controls request a short-lived code printed by the server-side auth package and consume it once after confirmation. The package handles form state, validation attributes, loading state, and error presentation. The application remains responsible for deciding where to navigate after a successful action and how errors are returned.

Local package development

Before publishing, build the packages and install them from the local workspace in a frontend project:

# From Web/SharedCode
npm run build

# From a project frontend directory; do not commit this file dependency for CI
npm install ../../../SharedCode/packages/design-tokens ../../../SharedCode/packages/web-ui

For CI and normal development, use the published version instead of a file: dependency. A local file dependency only works when the checkout also contains the sibling SharedCode directory.

Updating the design system

When a component or token changes:

  1. Run npm run changeset and describe the change.
  2. Run npm run version-packages and commit the generated version/changelog files.
  3. Run npm install, npm run check, npm run build, and npm run test:node-backend.
  4. Run npm run release; Changesets publishes the npm packages in dependency order.
  5. Update each project with npm install @gabriel20xx/web-ui@<new-version> and commit its lockfile.

The package boundary is intentional: application-specific screens stay in their project, while repeated visual language and account/layout infrastructure stays here.

S
Description
This folder is the single source of truth for reusable web UI across the projects in this workspace.
Readme
1.7 MiB
0 Stars 1 Watchers 0 Forks
Languages
Go 39.9%
Python 19.5%
JavaScript 13.5%
Java 10.8%
Svelte 7.1%
Other 9.2%