Development ​
Layout ​
fxmanifest.lua
shared/lib/ NpDrugs namespace, locale, integration registry, substance and item registries
shared/config.lua core settings; shared/config/<name>.lua per module
bridge/np_admin.lua the np_admin lib, byte-identical to np_admin/lib/np_admin.lua (global npAdmin)
shared/np_admin_settings.lua np_admin's settings page, the permission nodes, the fallback without np_admin
shared/locales/en|de/*.lua one file per module
shared/zz_init.lua builds the registries after every config and locale file
bridge/framework/{client,server}/ qbx | qb | esx | standalone
bridge/inventory/server/ ox | qb | esx | none (np_inventory claims the slot from integrations/)
bridge/mdt/server/ none (md-stempeluhr from integrations/)
integrations/server|client/ one file per sibling
server/core/NN_*.lua init, db, rpc, inventory API, MDT, hooks, events, players, timers, batches, stamps,
body, secrets, demand, items, sale, api, admin, actions
server/modules/<m>.lua batch (the reference) conceal carry production use effects addiction overdose ems
rehab vitals hud medical search tests_kit k9 trash street dispatch
client/core/, client/modules/ the client half of every module
sql/install.sql, production.sql, medical.sql
web/ React NUI (index.html, phone.html)
tests/ plain-Lua harness, fakes, smoke.lua, suites, run.sh
mockups/ the HTML mockups and their renders
There is one global table, NpDrugs, on client and server. Code resolves NpDrugs.X when it is called, never in a
file-level local. Every Lua file must also parse with plain lua 5.4 / 5.5, so the harness can load it.
Commands ​
tests/run.sh # luac -p and every Lua suite (all frameworks and inventories, the flows, the balance)
tests/run.sh flow # one suite VERBOSE=1 shows the resource's log
cd web && npm test && npm run build # strings, contract check, vitest; FiveM guard, typecheck, build
cd web && npm run dev # browser mock: http://localhost:5186/?screen=batch (&locale=de)
cd web && PORT=4391 scripts/screenshots.sh # every screen, HUD piece and the phone app to web/screenshots/
Mock mode URL parameters: ?screen=<id>, ?locale=de, ?bg=none, ?clean=1 (no dev index, no animations). A mock's
shots add named pictures. SCALE=3 renders at triple size for bottom-edge checks, LOCALE=de the other locale.
After re-rendering, run npm run sync:images in this docs repo.
Tests ​
tests/run.sh runs every tests/test_*.lua in its own process:
- Core:
core(ESX + np_inventory boot, schema, registries, items, the RPC layer with a fuzz pass over every method, hooks, events, sync, timers, tokens, actions, locales, admins),stores(batches, stamps, reputation, body, secrets, demand, exports, restart),sale. - One suite per module: batch, conceal, carry, production, use, effects, addiction, overdose, medical, rehab, search, k9, tests_kit, trash, street, dispatch.
- Flows:
flow(the three loops end to end) andbalance(real days of use per substance: casual, heavy, comeback, alcohol at the blackout). - Bridges:
boot_np(ESX + np_inventory with every sibling),boot_esx(ESX inventory),boot_qb(qb-core + qb-inventory),boot_qbx(qbx + ox_inventory),boot_standalone; each runstests/smoke.lua. - Seams and siblings:
integrations(declared exports against the sibling repositories),integrations_admin(np_admin: the byte-identical lib, without np_admin, with a fake np_admin, its restart and stop, the schema file in its sandbox),integrations_mdt,integrations_shops,client,client_siblings,body_client,client_city,seams(manifest, net events, and API.md against the code both ways).
The harness loads the resource in fxmanifest.lua order with stubbed natives, a controllable clock, an in-memory
oxmysql that runs the real SQL, and fakes of es_extended, qb-core, qbx_core, np_inventory, ox_inventory, qb-inventory,
np_hud, np_phone, np_character and np_discord with their real signatures. What it cannot see (animations, peds, props,
oxmysql itself) is on Before you open it.
Adding a module ​
A module is a set of new files; batch is the worked reference for every step.
| File | What goes in |
|---|---|
shared/config/<m>.lua |
Config.<M> = {…}; job groups with Config.Jobs.<group> |
shared/locales/en/<m>.lua, de/<m>.lua |
Keys prefixed <m>., error codes error.<code>, the same keys in both |
server/modules/<m>.lua |
RPCs <m>.<name> with a schema, timed actions (NpDrugs.Action.define), migrations, timers, item actions |
sql/<m>.sql |
Only with new tables: the same statements as the migration |
client/modules/<m>.lua |
Screens, client-local RPCs, world options, effects |
web/src/screens/<m>/ |
index.tsx, types.ts (RpcMap entries), mock.ts, <m>.css, optional hud.tsx |
tests/test_<m>.lua |
Scenarios in the harness |
Contract ​
docs/ARCHITECTURE.md is the contract for
the data shapes, the database, the NUI protocol, every RPC, the bridges, the integration layer and the server rules.
It changes in the same commit as the code. The public API is
docs/API.md, summarised on
Exports & hooks and Events.