Environment
Shiva code runs in three environments. Understanding which environment your code runs in is critical.
The Three Environments
| Environment | Where | What's Available |
|---|---|---|
| Server | FiveM server process | Database, all player data, economy, jobs |
| Client | Player's FiveM game | Ped manipulation, cameras, NUI, local state |
| Shared | Both | Pure Lua utilities, models, validation schemas |
Directory Convention
my-module/
├── server/ -- runs only on the server
├── client/ -- runs only on each player's game
└── shared/ -- runs in both, no side effectsWhat Goes Where
Server:
- Database reads/writes
- Player authentication and trust
- Economy, inventory mutations
- Authoritative game state
Client:
- Ped / entity manipulation
- Camera control
- NUI rendering
- Local caching for display
Shared:
- Data models (validation schemas)
- Locale strings
- Config defaults
- Pure utility functions
The Golden Rule
Never trust the client.
The client can send anything. All state mutations must happen on the server after validation. The client only ever receives display data or triggers server-side actions.
fxmanifest.lua
Every module has an fxmanifest.lua that declares which files go to which environment:
lua
fx_version 'cerulean'
game 'gta5'
name 'my-module'
version '1.0.0'
shared_scripts {
'shared/**/*.lua',
}
server_scripts {
'@oxmysql/lib/MySQL.lua',
'server/**/*.lua',
}
client_scripts {
'client/**/*.lua',
}