Library Utilities
126 utility modules in backend/src/lib/, providing foundational building blocks used across services and routes. These are not services themselves — they are stateless helpers, clients, and infrastructure components.
By Category
Authentication & Encryption
File Purpose auth.tsPassword hashing (argon2id via Bun.password.hash()), JWT creation tokens.tsToken generation (portal, magic link, 2FA) encryption.tsAES-256-GCM encryption (encryptToken/decryptToken)
Key: ENCRYPTION_MASTER_KEY — see Authentication , HubSpot Integration for encrypted token storage.
Validation & Sanitization
File Purpose validation.tsShared Zod schemas sanitization-helpers.tsstrictTextField(), sanitizedLocalizedText(), optionalSanitizedLocalizedText()schema-validator.tsRuntime schema validation
See Validation Pattern for usage rules.
File Handling
File Purpose file-operations.tsFile read/write operations file-validation.tsFile type/size validation mime-validation.tsMIME type allowlist storage.tsS3/Tigris object storage client
See Files for the file management domain.
Business Logic
File Purpose funding-calculator.tsFunding amount calculations u-value-calculator.tsThermal transmittance (U-value) calculations
See Financial Calculations , Energy Calculations .
Access Control
File Purpose permissions.tsPermission definitions and checks ownership-guards.tsverifyProjectAccess(), verifyBuildingAccess(), verifyScenarioAccess()department-access.tsDepartment-scoped data access
Always use RBAC-aware functions from ownership-guards.ts. See RBAC Authorization .
External API Clients
Communication
Directory/File Purpose email/Email sending via Resend email-templates/Email template definitions sms/SMS via MessageBird
See Resend Email , MessageBird SMS , Notifications .
Infrastructure
File Purpose logger.tsStructured logging sentry.tsSentry error tracking setupcache.tsIn-memory caching redis/Redis client and utilities distributed-lock.tsDistributed locking via Redis
Background Jobs
Directory Purpose jobs/Job factory, config, schedulers, processors
See Background Jobs for the job processing architecture.
Utilities
File Purpose pagination.tsCursor/offset pagination helpers sort.tsMulti-column sort builder search-utils.tsFull-text search helpers number-utils.tsNumber formatting pdf-generator.tsPDF document creation