- JavaScript 83.6%
- CSS 16.4%
This adds the Relationships 2.0 specification, architecture diagrams, test matrix, and phased implementation roadmap for the canonical universe explorer. It defines the source-of-truth model for pair relationships, parentage, species, houses/organizations, romance situations, and release validation while preserving admin/account safety requirements. |
||
|---|---|---|
| .forgejo/workflows | ||
| .github/instructions | ||
| backend | ||
| docs | ||
| frontend | ||
| .gitignore | ||
| AGENTS.md | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| UNIVERSE_NAVIGATION_VERIFICATION.md | ||
waifudb boilerplate
Express backend + React (Vite) frontend with Material UI.
Project structure
backend- Express APIfrontend- React + MUI apppackage.json- root scripts to run both apps
Configuration
Backend example config: backend/.env.example
PORT- backend port (default4000)SITE_NAME- site/app nameFRONTEND_ORIGIN- CORS origin for frontendDB_HOST- MariaDB hostDB_PORT- MariaDB port (default3306)DB_NAME- MariaDB database nameDB_USER- MariaDB usernameDB_PASSWORD- MariaDB passwordDB_LOG_SQL- set totrueto log Sequelize SQLDB_SCHEMA_MODE-update(default) orvalidateAUTH_BCRYPT_ROUNDS- bcrypt work factor for stored passwords
Frontend example config: frontend/.env.example
FRONTEND_PORT- Vite dev server port (default5173)VITE_FRONTEND_PORT- frontend port shown in the UIVITE_SITE_NAME- site name fallback for frontend runtime configVITE_API_BASE_URL- backend API base URLVITE_CONFIG_TIMEOUT_MS- request timeout for runtime config API (default2500)
Copy these to .env files if you want to override defaults.
Scripts
From the repository root:
npm run dev- run backend + frontend togethernpm run dev:backend- run only backendnpm run dev:frontend- run only frontendnpm run build- build frontend
Authentication
The backend uses Sequelize with the MariaDB dialect for account storage and persistent login sessions.
POST /api/auth/register- create an account withusernameandpasswordPOST /api/auth/login- log in withusernameandpasswordGET /api/auth/me- return the current user for a bearer tokenPOST /api/auth/logout- invalidate the current bearer token
Frontend auth stores the bearer token in localStorage, and the backend persists the session record in MariaDB so login survives server restarts until logout.
Start MariaDB, configure the backend connection, then run npm run dev (or npm run dev:backend). Before accepting requests, the backend creates the configured database if missing and prepares its tables from backend/sql/schema.sql. The MariaDB account needs CREATE privileges for a missing database, and CREATE/ALTER/INDEX privileges for schema updates. Existing databases can use an account limited to that database.
Startup adds missing tables, columns, indexes, foreign keys, and check constraints. It also reconciles defaults and automatic timestamp updates when the column type, nullability, and auto-increment setting already match, preserving stored values. Existing rows and extra tables/columns are retained. Required columns without defaults on populated tables, incompatible column definitions, conflicting indexes/foreign keys, or incompatible table storage/collation stop startup for manual review. Column errors include suggested SQL and actual metadata; review/backfill your data before applying it. Renames and data transformations require deliberate manual SQL. DDL commits independently: a failed adjustment may leave earlier additions applied, and restarting resumes from that state. Back up populated databases before schema upgrades.
DB_SCHEMA_MODE=validate checks an existing database without applying schema changes and fails startup when adjustments are needed. Validation checks column types, nullability, defaults, auto-increment and timestamp updates, indexes, foreign-key targets/actions, and the presence of named CHECK constraints. It does not compare existing CHECK expressions, triggers, or extra objects. Startup uses a database advisory lock to serialize schema management across backend instances.
The agent does not execute SQL or start a database-connected backend during verification; runtime schema updates happen when you start the application.
Schema setup SQL:
backend/sql/schema.sql
Manual verification (use a disposable database):
- Configure a new
DB_NAME, start the backend, and confirm the database/tables are created before/api/healthsucceeds. - Register, log in, fetch
/api/auth/me, restart and confirm the session persists, then log out. - Restart again and confirm the schema log reports zero adjustments and records remain intact.
- Manually remove a nullable column or nonunique index; restart to confirm it is restored. Repeat in
validatemode and confirm startup fails without restoring it. - Change a column type or omit a required column on a populated table; confirm startup fails with review instructions and preserves records.
- Test insufficient database privileges and invalid connection settings; confirm the API never begins listening. Verify frontend config fallback while the API is unavailable.
API starter routes
GET /api/health- basic health checkGET /api/config- returns public runtime config used by the frontendPOST /api/auth/register- create accountPOST /api/auth/login- log inGET /api/auth/me- resolve active sessionPOST /api/auth/logout- log outGET /api/sources- list sources (supportssearchandtypequery params)GET /api/sources/:id- source details with relations and linked character IDsPOST /api/sources- create source (mod/admin)PATCH /api/sources/:id- update source (mod/admin)POST /api/sources/:id/cover- upload source cover image (mod/admin)
Shared runtime config flow
Frontend runtime config resolves in this order:
GET /api/config(live API values)- Last good config cached in
localStorage - Frontend
.envdefaults
This keeps the app usable when the backend config API is temporarily unavailable.