Technology Stack
Core Technologies
- TypeScript - Type-safe JavaScript for all code
- Node.js >= 18.16.0 - Runtime environment
- pnpm - Fast, disk space efficient package manager
- Turbo - High-performance build system for monorepos
Frontend
- Next.js 14 - React framework with server-side rendering
- React 18 - UI library
- TailwindCSS - Utility-first CSS framework
- Formik - Form management
- Zod - Schema validation
- Zustand - State management
- React Query - Data fetching and caching
- Socket.IO Client - Real-time communication
Backend
- Ts.ED - TypeScript framework for Node.js
- Express - Web server framework
- Prisma - Type-safe ORM
- PostgreSQL - Primary database
- Socket.IO - Real-time bidirectional communication
- JWT - Authentication tokens
- bcrypt - Password hashing
Monorepo Structure
SnailyCAD uses a monorepo architecture powered by pnpm workspaces and Turbo. This allows multiple packages to share code while maintaining clean separation of concerns.Apps Directory
Theapps/ directory contains the main applications:
API (apps/api/)
The backend API server that handles all business logic, database operations, and integrations.
Key Directories:
- RESTful API with Ts.ED decorators
- Real-time updates via Socket.IO
- Database access via Prisma ORM
- Authentication & authorization
- File upload handling with Multer
- Discord and FiveM integrations
pnpm watch- Development mode with hot reloadpnpm build- Build for productionpnpm start- Start production serverpnpm generate- Generate Prisma client
Client (apps/client/)
The frontend application built with Next.js that users interact with.
Key Directories:
- Server-side rendering (SSR) with Next.js
- Internationalization (i18n) support
- Real-time updates via Socket.IO
- Responsive design with TailwindCSS
- Form validation with Formik + Zod
pnpm dev- Development modepnpm build- Build for productionpnpm start- Start production serverpnpm validate-locales- Validate translation files
Packages Directory
Thepackages/ directory contains shared libraries used by both apps:
@snailycad/types
Generated TypeScript types from the Prisma schema. These types represent database models and are used throughout the application. Usage:@snailycad/schemas
Zod validation schemas for form validation and API request validation. Shared between client and API to ensure consistency. Usage:@snailycad/permissions
Permission definitions and helper functions for checking user permissions. Usage:@snailycad/config
Shared configuration values used by both client and API.@snailycad/utils
Utility functions primarily used by the client, including formatters, validators, and helpers.@snailycad/ui
Shared React component library used by the client.@snailycad/audit-logger
Utilities for logging user actions and system events for audit trails.Build System
SnailyCAD uses Turborepo to orchestrate builds and manage dependencies between packages.Turbo Configuration (turbo.json)
Defines task dependencies and caching strategies:
^build- Depends on upstream packages being built firstoutputs- Cached build artifactsdependsOn- Task execution order
Workspace Configuration (pnpm-workspace.yaml)
Data Flow
Request Flow
- Client - User interacts with UI (Next.js)
- API Request - Client sends HTTP request to API
- Controller - Ts.ED controller receives request
- Middleware - Authentication, validation, etc.
- Service - Business logic processing
- Prisma - Database query execution
- Response - Data returned to client
- UI Update - React re-renders with new data
Real-Time Updates
- Action - User performs action (e.g., creates a call)
- API - Saves to database
- Socket.IO - Server emits event to connected clients
- Client - Receives event and updates UI in real-time
Database Architecture
SnailyCAD uses PostgreSQL with Prisma as the ORM.Key Models
- User - System users with authentication
- Citizen - In-game characters
- Officer - Law enforcement characters
- EmsFdDeputy - EMS/Fire characters
- Call911 - Emergency calls
- Record - Citations, arrests, written warnings
- Vehicle - Registered vehicles
- Weapon - Registered weapons
- Value - Configurable dropdown values (vehicle types, departments, etc.)
Migrations
Database schema changes are managed through Prisma migrations:Development Workflow
Hot Module Replacement (HMR)
During development, changes are automatically detected:- Client: Next.js Fast Refresh updates React components instantly
- API: nodemon restarts the server on file changes
- Packages: Turbo rebuilds and propagates changes
Type Safety
The entire codebase is TypeScript with strict type checking:Code Quality
- ESLint - Linting with custom rules
- Prettier - Code formatting
- Husky - Git hooks for pre-commit checks
- lint-staged - Run linters on staged files
Deployment
SnailyCAD can be deployed using:- Docker - Official Docker images available
- Traditional hosting - Build and run with Node.js
- Reverse proxy - Nginx or Apache for production