Shared Layer
The renewa-one/shared/ directory contains cross-cutting types, constants, and utilities consumed by both backend and frontend.
Files
| File | Size | Purpose |
|---|---|---|
types.ts | 3,202 lines (127KB) | All entity types, LocalizedText, request/response types, enums |
constants.ts | 785 lines (23KB) | Centralized enum definitions, status mappings, option lists |
api-types.ts | — | ApiError, ApiResponse<T>, QueryError, PaginatedResponse<T> |
validation-constants.ts | — | Field length limits, shared validation rules |
lib/sanitize.ts | — | HTML sanitization utilities (shared between FE/BE) |
types.ts
The single source of truth for all TypeScript types across the application. Every entity in Database Architecture has a corresponding type here.
Key type categories:
- Entity types:
Project,Building,Scenario,Contact,Company,Lead,Quote,Invoice, etc. - LocalizedText:
{ de: string; en: string }— used for all bilingual database fields - Enums: TypeScript enum types mirroring PostgreSQL
pgEnumdefinitions - Request/Response: Typed API payloads for each endpoint
- Utility types:
Nullable<T>,WithTimestamps,WithAuditFields
constants.ts
Centralized enum values and option definitions. Used by both frontend (dropdowns, filters) and backend (validation).
Includes: status enums, role definitions, building type options, energy source types, document categories, and more.
api-types.ts
Shared API contract types:
interface ApiResponse<T> { data: T; message?: string; }
interface ApiError { error: string; details?: unknown; statusCode: number; }
interface QueryError { message: string; statusCode: number; }
interface PaginatedResponse<T> { data: T[]; total: number; page: number; pageSize: number; }Used by frontend API clients and backend error handlers.
validation-constants.ts
Field length limits shared between frontend form validation and backend Zod schemas:
export const FIELD_LENGTHS = {
SHORT_TEXT: 100,
MEDIUM_TEXT: 255,
LONG_TEXT: 1000,
// ...
};Consumed by Validation Pattern helpers like sanitizedLocalizedText(maxLength).
lib/sanitize.ts
HTML sanitization using DOMPurify. Three levels:
| Level | Tags Allowed | Use Case |
|---|---|---|
STRICT | None (strips all HTML) | 99% of user input |
BASIC_FORMATTING | <b>, <i>, <em>, <strong>, <br> | Rich text preview |
RICH_TEXT | Extended set | Admin-only content, never user input |
See Validation Pattern for sanitization integration with Zod schemas.
Package Configuration
The shared package is referenced via TypeScript path aliases in both backend/ and frontend/ tsconfigs:
{ "paths": { "@shared/*": ["../../shared/*"] } }No separate build step — consumed directly as TypeScript source.
Related Pages
- Backend Architecture — Consumes types for service layer
- Frontend Architecture — Consumes types for components and API clients
- Database Architecture — Entity types mirror schema tables
- Validation Pattern — Zod schemas using shared constants
- API Layer Pattern — API response types
- Error Handling Pattern — Error type definitions
- Coding Guidelines — LocalizedText and naming conventions
- Internationalization — Bilingual text handling