This is the EverShop core repository β the codebase for the modular monolith eCommerce platform built on Express + React (SSR) + PostgreSQL + GraphQL. The package source lives at packages/evershop/src/ and is published as @evershop/evershop.
The author and maintainer is The Nguyen (support@evershop.io). Assume deep familiarity with the codebase.
A curated wiki for this codebase lives in wiki/. Before answering architectural questions or making non-trivial changes, read the relevant wiki page(s), not just the docs in ../docs/ or the source code. The wiki is hand-curated to be the fastest source of truth for "how does this actually work" questions.
wiki/index.mdβ catalog of all pages with one-line summaries. Read this first to find the right page.wiki/log.mdβ chronological record of ingests, queries, and audits.wiki/<topic>.mdβ the content pages.
If a page doesn't exist for the topic you need, that's a signal to ingest (see Operations below).
When the user asks a question that the wiki could answer:
- Open
wiki/index.mdand find candidate pages. - Read those pages.
- Answer using the wiki content. Cite pages by filename (e.g., "see
wiki/widgets.md") so the user can jump in. - If the wiki content is outdated relative to the code (rename, removal, signature change), update the wiki page in the same response and append a note to
wiki/log.md.
When the user explains something non-obvious about the codebase, or when you investigate an unfamiliar subsystem and the answer is worth keeping:
- Discuss the takeaways with the user inline (don't go silent for minutes writing files).
- Decide whether the knowledge belongs on an existing page or warrants a new one. Prefer updating existing pages β a page with five short sections beats five tiny pages.
- Write/update the page using the conventions below.
- Update
wiki/index.mdif a new page was added or a description changed. - Append a one-line entry to
wiki/log.mdwith prefix## [YYYY-MM-DD] ingest | <topic>.
When asked to audit the wiki, or when you notice drift while answering questions:
- Verify file paths and line references still resolve (they decay as files move).
- Check that named functions/flags/files referenced in the wiki still exist (
grep,Read). - Reconcile contradictions between pages.
- Flag pages that haven't been touched in a long time and describe an area that has clearly evolved (use
git log --oneline -- <path>to spot churn). - Append a
## [YYYY-MM-DD] lint | <scope>entry towiki/log.mdsummarizing what was checked and what changed.
Every page follows this shape:
# <Title>
**TL;DR.** One paragraph. The thing the user came here to learn, said directly.
## <Section>
Body. Code snippets go in fenced blocks with the language tag. File references use `relative/path:line` format so the user can click into them.
## See also
- [Other page](other-page.md) β one-line hookSpecifics:
- File paths. Always relative to the package root (
packages/evershop/src/...) unless the file lives outside that tree. Add:linesuffix when pointing at a specific implementation. - Code samples. Prefer real, compilable snippets pulled from the codebase over invented examples. If you must invent, mark it clearly.
- No marketing. No "powerful", "robust", "comprehensive". Just what it is and how it works.
- Be willing to contradict the public docs. If
../docs/is wrong, the wiki should say so and explain the actual current behavior. - Date format. ISO
YYYY-MM-DDeverywhere.
For deep understanding, read the wiki pages. This section is the cheat sheet.
- Runtime: Node.js β₯ 20, Express, React 18 with SSR + hydration
- Database: PostgreSQL 13+ (no other DBs supported; SQL is plain Postgres)
- GraphQL: schema assembled at startup from per-module
.graphqlfiles - Bundler: webpack 5 with SWC for transforms (no Babel)
- Forms: react-hook-form (wrapped by
components/common/form/Form.tsx) - Styling: Tailwind v4 + PostCSS + custom plugins
Multi-page application (MPA) β each route gets its own bundle and a full HTML response. Hydrated on the client. Not a SPA β there is no client-side router.
- Migrations:
Version-X.Y.Z.ts(hyphen, not underscore) in<module>/migration/ - Routes: folder name = route ID, alphabetic only (a-z, A-Z),
route.jsondeclares the route - Middleware: lowercase first letter, bracket-syntax ordering
[after]name[before].ts - Master components: uppercase first letter,
.tsx, optionalexport const layout = { areaId, sortOrder } - Shared between routes: folder named
routeA+routeB/(e.g.productEdit+productNew/) - Site-wide middleware:
pages/admin/all/,pages/frontStore/all/,pages/global/,api/global/ - Subscribers:
subscribers/<event_name>/<handler>.ts - Modules: core in
packages/evershop/src/modules/, user extensions inextensions/(project root) - Module ID: must be unique across the system
The hook system and registry are locked after every module's bootstrap.ts runs. Calling addProcessor, hookBefore, hookAfter, registerWidget, registerJob, registerEmailService, registerPaymentMethod, etc. from inside a middleware or request handler throws. Always register from bootstrap.ts.
See wiki/reference.md for the full table. The most common ones:
import { select, insert, update, del, insertOnUpdate } from '@evershop/evershop/lib/postgres/query';
import { pool, getConnection } from '@evershop/evershop/lib/postgres';
import { addProcessor, getValue } from '@evershop/evershop/lib/util/registry';
import { hookBefore, hookAfter, hookable } from '@evershop/evershop/lib/util/hookable';
import { emit } from '@evershop/evershop/lib/event';
import { createSubscriber } from '@evershop/evershop/lib/event/subscriber';
import { buildUrl, buildAbsoluteUrl } from '@evershop/evershop/lib/router';
import { registerWidget } from '@evershop/evershop/lib/widget';
import { setContextValue, getContextValue } from '@evershop/evershop/graphql/services';import { Request, Response } from 'express'β wrong. UseEvershopRequest/EvershopResponsefrom@evershop/evershop/types/requestandtypes/response.module.exportsβ wrong. ESM. Useexport default.- MySQL syntax β wrong. PostgreSQL. Use
IDENTITYorSERIAL, double-quoted identifiers,JSONB,gen_random_uuid(). migrations/(plural) folder β wrong. Singularmigration/.Version_1.0.0.ts(underscore) β wrong. Hyphen:Version-1.0.0.ts.pages/frontend/β wrong.pages/frontStore/.- Arrow functions in hookable / processor callbacks when context is needed β
thisis bound via.call(), arrow functions can't access it. - Adding a hook or processor from a middleware β locked after bootstrap, throws.
The pitfalls above are syntactic β caught by lint or first compile. The ones below are runtime or integration traps. They compile cleanly and fail later. Each has bitten the codebase; the wiki pages explain why and show the fix.
- API handler that sends a response with a 2-arg
(request, response)signature βERR_HTTP_HEADERS_SENT. The framework inspectsfunction.length; a 2-arg handler is treated as passive, so it auto-callsnext()after your function resolves andapiResponsetries to send headers again. If you callresponse.json()/response.send()/response.redirect(), declare the thirdnextparameter even if you never call it β the 3-arg signature disables auto-next. See wiki/middleware-system.md β Active vs passive middleware. - Chaining
.where()or.orderBy()directly off.on()in a query-builder JOIN βwhere is not a functionat runtime..on()returns aNode;.where()and.orderBy()live onQuery/SelectQuery, notNode. Hold the query handle in a variable and call.where()/.orderBy()on it separately. The.where().and().execute()chain works fine (Node has.and()and.execute()) β the trap is only joins. See wiki/database.md β What chains on what. - Passing
(column, alias)to the top-levelselect(...)β silent column rename βcolumn "X" does not existat runtime. The top-levelselect(...)is variadic over columns βselect('foo.uuid', 'method_uuid')treats both strings as columns, not as(column, alias). Only the chained.select(col, alias)form supports aliasing. Useselect().from(table).select(col, alias)instead. See wiki/database.md βselect(...)is variadic. - Passing
{ isSQL: true, value: '...' }to.given()for raw SQL in UPDATE/INSERT βinvalid input syntax for type ...at runtime.UpdateQuery.given/InsertQuery.givencalltoString(value)on every entry, which JSON-stringifies object values. The{isSQL, value}raw-escape convention is only honored inside.where()/Leaf/RawLeaf, not for SET / VALUES. When you need raw SQL on the write side (COALESCE(col, NOW()),col + 1,gen_random_uuid()), drop toconnection.query()with bind parameters for just the user values. Canonical pattern:oms/services/updateShipmentStatus.ts:79-100. .execute(connection)/.load(connection)on a freshgetConnection()PoolClient beforestartTransaction(connection)βRelease called on client which has already been released to the poolat runtime. The query-builder's internalrelease()only short-circuits whenconnection.INTRANSACTION === true, a flag exclusively set bystartTransaction. Pre-tx reads on a freshly-acquired PoolClient auto-release it back to the pool, and the nextstartTransaction(connection)operates on a detached client. Rule: either callstartTransactionIMMEDIATELY aftergetConnection, or run pre-tx reads on the sharedpool(whichrelease()ignores) and acquire the dedicated PoolClient only at the top of the tx. The canonical "delayed tx" pattern (necessary when an external network call has to run between read and write β e.g.carrier.createLabel()) is inoms/services/createShipment.ts:330-410.- Hook called after a conditional early return in a React component β
Rendered more hooks than during the previous render. All hooks must run in the same order on every render. If one render takes an early return before auseEffectand the next render reaches it, React errors. Move every hook above any conditional return. .admin.graphqltype referenced from a non-admin.graphqlfile β "Unknown type X" at storefront schema build.buildStoreFrontSchemafilters out.admin.graphql; types defined there aren't visible to the storefront schema. Either move the type to a non-admin file or mark the referencing file.admin.graphqltoo. The two schemas build separately β admin sees both, storefront sees only non-admin.- Dropping a DB column without grepping across modules. EverShop modules share tables. A resolver in
modules/base/may read a column owned bymodules/checkout/. When dropping a column,grep -rn "table\\.column" packages/evershop/srcacross the whole tree, not just the owning module. - New
.jsfiles in new code paths. The codebase has mixed.jsand.tsbecause the migration to TypeScript is incremental, but new authorship is.ts(or.tsxfor React). Editing an existing.jskeeps it.jsfor small changes; full rewrites are a good moment to switch. See wiki/module-structure.md β TypeScript by default. hookable()keys hooks by the wrapped function's.name, so aβ¦Impldeclaration silently kills its public hooks.hookable(fooImpl)registers under'fooImpl', but ahookBeforeFoohelper that callshookBefore('foo', β¦)registers under'foo'β they never meet, the hook never fires, and nothing errors (the wrapped function still runs, the transaction still commits). Wrap a named function expression whose intrinsic name is the hook key, even if the binding differs:const fooImpl = async function foo() {β¦}(thecheckout.ts:10idiom βconst _checkout = async function checkout(). A plainfunction fooImpl() {}declaration sets.name = 'fooImpl'and breaks it. See wiki/hooks.md β Common pitfalls; guard testmodules/oms/tests/unit/hookNameAlignment.test.js.- A widget
settingComponentthat reads a list setting aswatch('settings.x') ?? initialworks in the page-builder drawer but throwsitems.map is not a functionon the legacy/admin/widgets/editpage. The two surfaces seed settings differently: the drawer's page-level form holds real arrays/objects, but the legacy<Form>seeds list fields as a JSON string via a hiddendefaultValue={JSON.stringify(...)}input β and??only guards null, so the string reachesRepeatableAccordionand would also fail the widget's AJV array schema on save (settings are never parsed in the save path). Read list settings withuseArraySetting('settings.x', initial)and mutate viaasArray(getValues('settings.x'), initial)(both from@components/common/page-builder), or hold the array withuseFieldArraylikeSlideshowSetting. See wiki/page-builder.md β Widget settings run on two surfaces.
- The published package is built from
src/todist/via SWC (npm run compile). Runtime loads.jsfromdist/. When editing, edit.tsinsrc/. - While
npm run devis running, compile withnpm run compile:dev, nevernpm run compile. The latter starts withrimraf ./packages/evershop/dist, which replaces the directory the dev server is watching. The watcher keeps a handle on the deleted inode and rebuilds forever β identical bundle hash, every few hundred milliseconds β and only restarting the server clears it.compile:devwrites in place and leaves the inode untouched. Use the fullcompilewhen a source file has been DELETED (only the rimraf clears its stale output), and expect to restart the dev server afterwards. - Tests run with Jest:
npm testfrom the repo root. - Lint with
npm run lint. - Dev server:
npm run dev(useswebpack-dev-middleware+ HMR). - Build for production:
npm run buildthennpm run start. - Never bypass
huskyhooks (--no-verify) or skip type/lint failures without an explicit go-ahead. - Themes, the theme lab and the asset library are not in this repo. They moved to
../extensionsFactory(copied 2026-10-09, removed here 2026-10-12); this repo is for core maintenance only. Before releasing a change to a storefront component, widget, shared class hook (evershop-widget__heading,__item-heading, β¦), markup or CSS, follow../extensionsFactory/.claude/skills/core-change-check/SKILL.md: compile this checkout withnpm run compile:dev, render it in the lab throughEVERSHOP_PKG, and compare every theme with its approved baseline. Source comments that cite "theme-lab FINDINGS #n" point at../extensionsFactory/theme-lab/FINDINGS.md; a core defect found by theme work is fixed here. See wiki/theme-lab.md.