Skip to main content

Database Schema

Xylem uses PostgreSQL as its primary database, accessed through Prisma ORM. The schema is defined in xylem-backend/prisma/schema.prisma.

Entity Relationship Overview

┌──────────────┐     ┌──────────────────┐     ┌─────────────────────────┐
│ Organization │────▶│ User │────▶│ RefreshToken │
│ │ │ │ └─────────────────────────┘
│ - name │ │ - firstName │
│ - domain │ │ - email │ ┌─────────────────────────┐
│ - website │ │ - password │────▶│ EmailVerification │
└──────┬───────┘ │ - roleId ───────┼──┐ └─────────────────────────┘
│ └────────┬─────────┘ │
│ │ │ ┌─────────────────────────┐
│ ┌───────▼────────┐ └─▶│ Role │
│ │ ProjectShare │ │ - name │
│ │ - accessLevel │ │ - permissions[] │
│ └───────┬────────┘ └─────────────────────────┘
│ │
▼ ▼
┌──────────────┐ ┌────────────────┐ ┌─────────────────────────┐
│ Project │────▶│ ProjectVariant │─────▶│ ProjectVariantSolution │
│ │ │ │ │ - solutionEngineId │
│ - name │ │ - name │ │ - solutionData (JSON) │
│ - tags[] │ │ - productMix │ │ - overallScore │
│ - location │ │ - metaData │ └─────────────────────────┘
│ - coverImage│ │ - currentStage│
│ - surveyMapId └────────────────┘
└──────┬───────┘


┌──────────────┐
│ SurveyMap │
│ - dwgId │
│ - dxfId │
│ - pdfId │
│ - geojsonId │
│ - metaData │
└──────────────┘

Core Models

Project

The central entity. A project represents a real estate development site.

FieldTypeDescription
idUUIDPrimary key
nameStringProject name
tagsString[]Searchable tags
locationString?Address or location description
coverImageString?URL path to cover image
surveyMapIdUUID?Link to the uploaded survey map
organizationIdUUID?Owning organization

ProjectVariant

Each project can have multiple design variants with different configurations.

FieldTypeDescription
nameStringVariant name
variantTagsString[]Tags for filtering
currentStageEnumDRAFTIN_PROGRESSCOMPLETED
productMixJSONArray of unit mix entries (BHK types, counts, areas)
metaDataJSON?Additional configuration data

ProjectVariantSolution

Solutions generated by the simulation engine, stored as JSON blobs.

FieldTypeDescription
solutionEngineIdStringUnique ID from simulation engine
solutionDataJSONComplete solution object
overallScoreFloat?Primary metric for sorting

SurveyMap

Tracks the processing pipeline of uploaded DWG survey files.

FieldTypeDescription
originalDwgIdUUIDReference to uploaded DWG file
dxfIdUUID?Converted DXF file reference
pdfIdUUID?Converted PDF file reference
geojsonIdUUID?Converted GeoJSON file reference
metaDataJSON?AI-extracted metadata (Gemini)

Auth & User Models

User

FieldTypeDescription
firstName, lastNameStringUser name
emailString (unique)Login email
passwordStringBcrypt-hashed password
isEmailVerifiedBooleanEmail verification status
isActiveBooleanAccount active flag
roleIdUUIDAssigned role (FK to Role)
organizationIdUUID?Organization membership

Role & Permission

Roles are linked to permissions in a many-to-many relationship.

model Role {
id String @id @default(uuid())
name String @unique
description String?
permissions Permission[]
users User[]
}

model Permission {
id String @id @default(uuid())
name String @unique // e.g., "manage:users"
roles Role[]
}

ProjectShare

Enables sharing projects with specific users at different access levels.

FieldTypeDescription
projectIdUUIDShared project
userIdUUIDUser receiving access
accessLevelEnumVIEWER or EDITOR
sharedByIdUUIDUser who initiated the share

Organization Models

OrganizationInvitation

Tracks email invitations to join an organization with a specific role.

OrganizationJoinRequest

Handles user-initiated requests to join an organization. Status: PENDINGAPPROVED / REJECTED.

DomainBlacklist

Maintains a list of email domains that are blocked from registration.

Domain-Specific Models

RegulatoryRule

Stores visual node-graph-based regulatory rules (created in the admin panel with ReactFlow).

FieldTypeDescription
idStringRule ID (e.g., RUL-XXXXXXXX)
nameStringHuman-readable rule name
authorityStringGoverning authority (BDA, BBMP, etc.)
parametersJSON{ inputs: [], outputs: [] }
graphJSONReactFlow node/edge graph definition

RegulatoryVariable

Global variable registry for the regulatory engine — defines the inputs and outputs available to rules.

FieldTypeDescription
keyString (PK)Dot-notation key (e.g., site.area)
labelStringDisplay label
categoryStringINPUT or OUTPUT
dataTypeStringnumber, boolean, string
unitString?Unit of measurement

CatalogUnit

Pre-defined apartment unit templates used in floorplate generation.

FieldTypeDescription
unitIdString (PK)e.g., 2bhk_corner_96
bhkTypeString1BHK, 2BHK, 2.5BHK, 3BHK, 4BHK
areaSqmFloatUnit area in square meters
entranceDirectionStringNORTH, SOUTH, EAST, WEST
isCornerBooleanCorner unit flag
geometryJSONCAD geometry entities

Prisma Commands

# Generate Prisma client after schema changes
npx prisma generate

# Create and apply a migration
npx prisma migrate dev --name description_of_change

# Deploy migrations in production
npx prisma migrate deploy

# Open Prisma Studio (GUI)
npx prisma studio

# Seed the database
npx prisma db seed