# Raze Developer Guide # Welcome Raze is a FiveM roleplay server built from scratch in TypeScript and React. It uses no Qbox, ESX, ox_lib, oxmysql or other framework: we own the core, the database layer, the UI and the inventory. This guide is for developers joining the project. Read it once before your first change. **Private** This guide is private. Don't share it, the repos, or anything from them outside the team. ## Where to go next - [Tech stack and layout]: what the code is made of and where it lives - [Getting started]: set up, build and run - [Ground rules]: the three rules every change must follow - [Resource map]: which resource owns what - [Using AI on Raze]: give your Claude or other AI the project rules --- # Tech stack and repo layout Everything is TypeScript on Node 22 (`node_version '22'` in each manifest), bundled with esbuild and run with Bun scripts. | Part | What we use | | --- | --- | | Scripts | TypeScript, esbuild, `@citizenfx/client` and `@citizenfx/server` types | | UI (NUI) | React 19 in one shared resource, `raze_ui` | | Database | MariaDB/MySQL through our own `raze_db` (mysql2 pool) | | Font | Inter (`@fontsource-variable/inter`) | | Screenshots | Playwright (`bun run shot`) | The code lives in the private `Raze-Roleplay/raze-fivem` repo. Assets are in separate private repos: `raze-mlo` (map interiors), `raze-props`, `raze-vehicles` and `raze-clothing`. | Path | What's there | | --- | --- | | `resources/raze_*` | One folder per resource: `fxmanifest.lua`, `src/client`, `src/server`, often `src/shared`, JSON config, `sql/`, and `web/` for NUI files | | `packages/shared` | `@raze/shared`: shared types, helpers and the ready system. Each resource's types live here (`inventory.ts`, `jobs.ts`, ...) | | `scripts/` | Build, check, new-resource, screenshot and asset tools | | `server/server.cfg` | The `ensure` order. `secrets.cfg` (gitignored) holds the license key | | `dist/` | Build output, gitignored. Never edit it | --- # Getting started Ask Moe for access to the GitHub repos, the test server and your picture key first. 1. Clone `raze-fivem` and run `bun install` at the root. 2. Copy `resources/raze_db/config.example.json` to `config.json` and fill in your database login. 3. Copy `resources/raze_core/logging.example.json` to `logging.json`. Leave the webhooks blank for local work. 4. Copy `server/secrets.example.cfg` to `secrets.cfg`, add your own cfx.re license key, and put in your picture key (see below). 5. Run `bun run build` once, then `bun run dev` while you work (it rebuilds on save). 6. Before you hand anything in, run `bun run check`. It type-checks every resource, the web UI and `@raze/shared`. | Command | What it does | | --- | --- | | `bun run build` | Builds every resource into its `dist/` | | `bun run dev` | Same, in watch mode | | `bun run check` | Type-checks everything (must pass) | | `bun run new raze_` | Makes a new resource with the standard layout | | `bun run shot` | Takes UI screenshots with Playwright, for reviews | After a build, restart the resource in the server console (`ensure raze_`). Every resource must survive a restart while players are online (see [Ground rules]). ## Your picture key Clothing, tattoo, furniture and emote pictures aren't in any repo. They come from our picture server, `raze-cdn.mesender.com`, which only answers a key your server signs. Every developer has their own key: **ask Moe for yours.** Put it in `server/secrets.cfg`: ```ini set raze_cdn_key "the key Moe gave you" ``` - Keep it `set`, never `setr`: `setr` sends it to every player who joins. - Never commit it, paste it in chat or share it. `secrets.cfg` is gitignored. - Without it, the server warns at start and pictures are off: stores show numbers, and the emote and furniture menus show icons. Everything else works. - Restart `raze_appearance` after you set it. `bun run shot` reads the same key from `secrets.cfg`, so screenshots show pictures too. --- # Ground rules Three rules come before everything else: the server decides, every resource survives a restart, and every script is cheap to run. A change that breaks any of them gets sent back. ## Security first - The server decides money, items, jobs, task state, prices, and positions where it can. The client only displays and asks. - Validate every net event and callback on the server: types, ranges, ownership, state, distance and cooldowns. Nothing the client triggers grants anything on its say-so. - Assume every player dumps everything their client downloads: `files{}` entries, client JS, NUI, state bags and events. Locations, spawn pools, loot tables, rates, prices, admin lists and other players' info stay in server-only config and code. - Send each client only what that player needs right now, and re-check every interaction on the server. ## Restart-safe - No `dependency` or `dependencies` in `fxmanifest.lua` (asset-only resources like `raze_mlo` are the exception). Load order comes from the `ensure` order in `server/server.cfg`. - Providers call `announceReady()` from `@raze/shared/ready` once they've fully started. - Anything you register into another resource goes inside `whenReady('', fn)`, and `fn` must be safe to run twice. Never use `onResourceStart` plus `setTimeout`. - `:ready` belongs to the ready system, so never name a net event `ready`. `onClient` and `onServer` refuse it. A client asking the server for its state again (after a restart) sends `clientReady`. - Loops over players already online use `untilReady('raze_core').then(...)`. Per-second loops that call `raze_core` start with `if (!isReady('raze_core')) return;`. - A `raze_core` restart keeps players in their character, and `raze_jobs` keeps duty. Never clear per-player state on `onResourceStop('raze_core')`; use `raze_core:characterUnloaded`. - A resource restarting mid-task cleans up its own entities and state, never pays twice, and leaves nothing behind. ```ts import { announceReady, whenReady } from '@raze/shared/ready'; whenReady('raze_interact', () => { // register points here; this may run again after raze_interact restarts }); announceReady(); ``` ## Performance first Every script is built to be cheap: near 0.00 ms in `resmon` when idle, and no hitches on the server thread. Treat a cost you could have avoided as a bug. - Client `setTick` runs only while it's needed (the player is nearby, a screen is open) and is cleared afterwards. Anything that doesn't need every frame uses an interval or an event. - Proximity checks walk a short list of nearby points refreshed every second or so, never every point on the map each frame. - Send the least you can over the network: only to the players who need it, and only what changed. Nothing goes out every frame or as an every-second broadcast. Use state bags only for what other clients must see. - No database queries in loops or per-player timers. Cache read-mostly data in memory, write once per action, and index the columns you look things up by. - Release whatever you load and create: call `SetModelAsNoLongerNeeded` after spawning, delete entities, and clear ticks and timers when you're done and when the resource stops. - NUI renders only while it's open and never polls. - Measure before you hand work in: `resmon` on the client, and `razecost` (or the admin Performance page) on the server. ```ts // Draw only while someone is near: the tick starts and stops with distance. let tick: number | null = null; setInterval(() => { const near = isNearAny(); // checks a short nearby list, not the whole map if (near && tick === null) tick = setTick(draw); else if (!near && tick !== null) { clearTick(tick); tick = null; } }, 1000); ``` --- # Resource map There are 21 code resources plus 4 asset-only ones, listed in `ensure` order. New features go into the resource that already owns that area; we avoid lots of small resources. Small quality-of-life features go in `raze_smallresources`. | Resource | Owns | | --- | --- | | `raze_db` | MySQL pool and migrations for everyone (server only) | | `raze_core` | Login, characters, spawning, digital accounts, metadata, saving, logging (DB + Discord) | | `raze_ui` | The one React NUI: every screen, toasts, progress bars, the radial wheel | | `raze_voice` | Voice and radio | | `raze_chat` | Chat | | `raze_hud` | Status and vehicle HUD, round minimap (display only) | | `raze_interact` | Every world interaction: look at it, scroll, press E | | `raze_jobs` | Jobs, ranks, duty, paychecks, the taxi, trucking and garbage jobs | | `raze_business` | Government, public and player-run businesses, rank permissions | | `raze_banking` | Accounts, branches, ATMs, transfers, invoices | | `raze_appearance` | Character creator, clothing, barber and tattoo shops, outfits | | `raze_inventory` | Slots and weight, containers, stashes, shops, weapons, crafting bench | | `raze_props` / `raze_cars` / `raze_clothing` / `raze_mlo` | Streamed assets only, from the asset repos | | `raze_vehicles` | Ownership, dealer, garages, impound, keys, fuel, damage, mechanic repair | | `raze_emote` | Emotes, walks, moods, partner emotes, props held in hand | | `raze_medical` | Death, respawn, injuries, the EMS job | | `raze_police` | Cuffs, escort, search, MDT and dispatch | | `raze_phone` | Phone and tablet apps, camera, photos, the Mober ride app | | `raze_housing` | Wiwang apartments, Sandy Shores trailers, furniture, doors | | `raze_smallresources` | Small quality-of-life features | | `raze_admin` | Staff menu, spawners, bans, warnings, logs | | `raze_dev` | Dev console commands. Test server only; never ensure it on live | Each resource's shared types are in `packages/shared/src/.ts`. Exports are typed there and registered with `provideExports`, so you can read a resource's API without opening its code. --- # Code and UI conventions Write code that looks like the code around it: same structure, same naming, about the same number of comments. ## Code - TypeScript everywhere, strict, and `bun run check` must pass. - Settings go in each resource's JSON config files, not convars. Server-only settings stay in files that are never listed in `files{}`. - Use `@raze/shared` helpers before writing your own: `db`, the ready system, `provideExports` / `resourceExports`, progress bars (`@raze/shared/server/bar`) and the animation presets. - Every world interaction goes through `raze_interact`. No third-eye targeting and no plain "Press E" text. - New resources come from `bun run new raze_`, and only when no existing resource fits. - Never rename a command players already use. - US spelling in code, comments and UI text. ## UI (Mono style) - Every screen lives in `raze_ui` and uses the tokens in `resources/raze_ui/web/src/styles.css`. - Graphite panels with a soft sheen, a hairline border and about a 16px radius. - One primary action per screen: a white pill with near-black text. Secondary buttons are graphite. - Color only for meaning: green success, red danger, amber warning, blue info. No brand accent color. Job screens like the MDT may use their job's color inside. - Inter everywhere, with tight bold headings. - Never use `backdrop-filter` blur. FiveM renders it as black boxes, so use rgba backgrounds instead. - Include screenshots (`bun run shot`) with any UI change. --- # Clothing How clothing packs, saved outfits and the store pictures fit together. Clothing lives in the private `raze-clothing` repo (the `raze_clothing` resource); the store is in `raze_appearance` and `raze_ui`. ## Where things go | What | Where | | --- | --- | | Models and textures | `raze-clothing/stream//_//` (`civ1`, `civ2`, `police`; `replace` holds textures that replace base-game ones) | | Shop metas | `raze-clothing/data//`, each registered in `fxmanifest.lua` as `SHOP_PED_APPAREL_META_FILE` | | Picture indexes | `raze-clothing/web/pictures.json` (our packs, Rockstar DLCs from 2024 on) and `web/vanilla.json` (older Rockstar clothing) | | Store pictures | The picture server, `https://raze-cdn.mesender.com/clothing/` (never in a repo) | Clothing files never leave the private repos. Any change in `stream/` needs a full server restart, and players must reconnect to see it. Ask Moe for the restart. ## Pieces are saved as pack and number The game numbers drawables globally: vanilla first, then every streamed pack in load order. Adding or removing a pack shifts every number after it, so a saved global number would point at the wrong piece. So every saved piece also carries its pin, `{ collection, local }`: the pack's collection name (its `dlcName` for that ped) and the drawable's number inside that pack. The client reads both with the collection natives (`GetPedCollectionNameFromDrawable`, `GetPedCollectionLocalIndexFromDrawable`) and turns a pin back into today's global number (`GetPedDrawableGlobalIndexFromCollection`). The server checks pins against `pictures.json` before saving. - Never store or compare bare global numbers for streamed clothing. Use the pin. - A pack's drawables are numbered `000` up with no gaps, and that number is the local index. - A drawable's `_1` file (a jacket open or closed) is an alternate, not a drawable of its own. ## Store pictures One picture per drawable (its first texture). In the store, the variant slider changes the texture live on the ped. Pictures aren't in `raze_clothing`'s `files{}`, so players don't download them on join. The picture server only answers a request carrying a key (`?k=`) that raze_appearance signs for a player in a character, with `raze_cdn_key` from `secrets.cfg` (see [Getting started](/guide/getting-started#your-picture-key)). Each key names its character and is capped per day, so a key copied out of the game can't pull the whole catalog. A key lasts until the end of the next day (UTC), and the client gets a new one before it runs out. Without a key, the store shows numbers. Each index lists a picture name for each local drawable of each slot: - a name: the picture file - `null`: no picture (the store shows its number) - `false`: an empty model with nothing to wear. The store hides it. The server refuses to sell empty pieces from `pictures.json` (`isEmptyPiece` in `@raze/shared/appearance`). - `'none'`: the base game's one empty piece in a component slot (no mask, no bag, shirtless). The store shows it as a None tile. Empty legs, shoes and torsos make the body vanish, so they're always hidden. ## Adding a clothing pack 1. Put the pack in `raze-clothing/stream//` and its metas in `data//`, and register the metas in `fxmanifest.lua`. Every `dlcName` must be new. 2. Ask Moe for its pictures. Moe renders them, puts them on the picture server and sends you the updated `pictures.json`. 3. Commit the pack, metas and index in `raze-clothing`, and ask Moe for the restart. Until its pictures are up, a new pack shows numbers in the store. --- # Status and where to help Most systems are built, but many haven't been tested in-game yet. The fastest way to help is testing in-game and fixing what breaks. | Area | Status | Notes | | --- | --- | --- | | Core, jobs, businesses, banking | Needs in-game test | Coordinates and balance need a pass | | Inventory, weapons, vehicles | In progress | Weapon rework going on in `raze_inventory` | | Police, MDT and dispatch | In progress | MDT is a tablet app | | EMS | Needs in-game test | Injuries, defib, stretcher | | Civilian jobs | Needs in-game test | Taxi, Mober, garbage and trucking (convoys, weigh stations) | | Housing | In progress | Wiwang apartments and the first Sandy Shores trailer done; south side and Mirror Park houses being built | | Crafting bench | In progress | Mechanic parts bench | | Gangs | Open for help | Own resource, not designed yet | Pick an area with Moe before you start, so two people never build the same thing. --- # Using AI on Raze You can point Claude or another AI at Raze. These files give it the project rules, so its code follows them from the first try. | If you use | Do this | | --- | --- | | Claude Code, Codex, Cursor or Copilot in the repo | Nothing. `AGENTS.md` at the repo root (and `CLAUDE.md`, which loads it) is read automatically | | Claude on claude.ai or the desktop app | Download the [Raze skill](/raze-fivem-skill.zip) and upload it under Settings, then Capabilities, then Skills | | Any other chat AI | Download [llms-full.txt](/llms-full.txt) (the whole guide in one file) and attach it to your chat | The rules your AI gets are the same ones you follow: [Ground rules] and [Code and UI conventions]. Review what it writes like any other change.