Rental Tenant Profile — Design
Tenants get an optional profile (photo plus twelve fields such as age, race, nationality, occupation, occupants and pets) that landlords see on viewing requests, offers and message threads from that tenant. Every field is optional and clearable, only the request's own landlord can read it, and the tenant sees exactly what landlords see.
- Status Approved
Summary
Tenants get an optional profile — photo plus twelve fields such as age, race, occupation and pets — that landlords see on viewing requests, offers and message threads from that tenant. Nothing is required, every answer can be cleared, and the tenant sees exactly what landlords see.
Goal
Malaysian landlords screen tenants before agreeing to a viewing. Tenants get an optional profile they can fill in from their profile page; landlords see it on viewing requests, offers and message threads from that tenant.
Success criteria
- A tenant can fill in, change, and clear any profile field and the photo; nothing is required, and booking a viewing never depends on the profile.
- A landlord sees the profile of a tenant who sent them a viewing request (and therefore any offer or thread from it), at any request status, before confirming, countering or declining.
- No other landlord can read the profile.
- The tenant sees exactly what landlords see.
Decisions taken in brainstorming
- Field set
- Photo, gender, age, race, nationality, occupation, employment type, occupants, planned move-in, smoker, pets, languages, about me. All optional.
- Race
- Included as an optional field at the product owner's direction, after the discrimination/brand risk was raised.
- Excluded fields
- Religion (PDPA 2010 sensitive personal data) and monthly income (unverifiable; invites payslip requests).
- Visibility
- Landlord who owns a viewing request from the tenant, at any status. Not public; not browseable.
- Storage
- New Go-owned table
rental_tenant_profiles; Better Authuserstable is not changed. - Partner / landlord API (
/v1) - Out of scope. Web app only.
1 · Go-owned table
Typed columns per field in rental_tenant_profiles. Storage, validation and the visibility check stay together in the rental module, which already owns the tenant–landlord relationship.
2 · Columns on Better Auth users
Via additionalFields. Couples the auth schema to marketplace fields; writes would go through bun while visibility is enforced in Go.
3 · JSONB on users
Least schema work, but no database typing or constraints, the same auth coupling, and duplicated validation in two languages.
Data model
New table, added to the CreateRentalTables-family migrations in internal/shared/infrastructure/database/postgresql/migrations/migrator_rental.go:
CREATE TABLE IF NOT EXISTS rental_tenant_profiles (
user_id TEXT PRIMARY KEY,
photo_key TEXT,
gender TEXT,
birth_year SMALLINT,
race TEXT,
nationality TEXT,
occupation TEXT,
employment_type TEXT,
occupants SMALLINT,
move_in_month DATE,
smoker BOOLEAN,
pets TEXT[],
languages TEXT[],
about TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
user_id is the Better Auth user id, same type as rental_viewing_requests.tenant_user_id. The row is created on first save (upsert).
Field rules
Validation lives in the domain entity entity/tenant_profile.go; the database has no enum CHECKs (matching rental_viewing_requests.status handling of evolving value sets). Every column is nullable; NULL means "not answered".
| Field | Allowed values | Notes |
|---|---|---|
gender | male, female | |
birth_year | current year − 100 ≤ y ≤ current year − 18 | Never sent to landlords. |
race | malay, chinese, indian, bumiputera_sabah_sarawak, others | |
nationality | two uppercase letters (^[A-Z]{2}$); MY = Malaysian | UI: Malaysian / Non-Malaysian → country picker over a fixed ISO 3166-1 alpha-2 list; the server checks format only. |
occupation | 1–60 chars after trim | Empty after trim → NULL. |
employment_type | employed, self_employed, student, other | |
occupants | 1–10 | |
move_in_month | first day of a month; not before the current month (Asia/Kuala_Lumpur) at save time | Stored past dates stay valid when read; only rejected on save. |
smoker | true / false | false = explicit non-smoker. |
pets | subset of cat, dog, other, no duplicates | {} = explicit "no pets"; NULL = unanswered. |
languages | non-empty subset of ms, en, zh, ta, yue, other, no duplicates | Empty selection → NULL. |
about | 1–300 chars after trim | Empty after trim → NULL. |
Age range
Derived at read time for landlords from birth_year and the current year (age = current year − birth year):
18–24 spans seven years, the rest five, and 60+ is open-ended.Backend
Ports and adapters
port.TenantProfileRepositoryGet(ctx, userID) (*entity.TenantProfile, error)(returnsnil, nilwhen no row),Upsert(ctx, *entity.TenantProfile) error,SetPhotoKey(ctx, userID string, key *string) (previous *string, err error).port.TenantPhotoStore- New narrow port:
PutTenantProfilePhoto(ctx, userID, contentType string, data []byte) (key string, err error);PublicURL(key string) string;Remove(ctx, key string) error. Implemented by the existing storagePhotoStoreadapter. Keys go underrental/tenant-profiles/{userID}/{uuid}.{ext}with.jpg/.png/.webpfrom the content type.port.PhotoStoreand its test fakes stay unchanged; the module obtains the tenant store by type-asserting the configured photo store. - Postgres adapter
tenant_profile_repository.gobeside the other rental repositories.
Use case TenantProfileUseCase
-
GetOwnOwn profile; all-null value when no row. self -
SaveValidate via entity, upsert, return saved profile. self -
UploadPhotoTypeimage/jpeg|png|webp(elseport.ErrUnsupportedProfilePhotoType), size ≤port.MaxPhotoBytes(elseport.ErrPhotoTooLarge),PutTenantProfilePhoto,SetPhotoKey, best-effortRemoveof the previous key (failure logged, not returned). Nil store →port.ErrMediaUnavailable. self -
DeletePhotoSetPhotoKey(nil), best-effortRemove. self -
GetForOwnerLoad request viaViewingRequestRepository.GetByID; ifreq.OwnerUserID != ownerIDreturnport.ErrRequestNotFound; otherwise load the tenant's profile and map to the landlord view. owner
Square cropping happens client-side before upload; the server stores bytes as received.
HTTP (protected group, same as /me/offers)
| Method | Path | Response |
|---|---|---|
GET | /me/tenant-profile | tenantProfileSelfJSON (all fields incl. birth_year, photo_url; nulls when unanswered) |
PUT | /me/tenant-profile | Body: all non-photo fields; 200 tenantProfileSelfJSON; 400 ValidationError{Fields} |
POST | /me/tenant-profile/photo | Multipart part photo (same as property photos); 200 tenantProfileSelfJSON; 400 type/size; 503 ErrMediaUnavailable |
DELETE | /me/tenant-profile/photo | 200 tenantProfileSelfJSON |
GET | /requests/:id/tenant-profile | 200 tenantProfileOwnerJSON; 404 when caller is not the request owner or the request does not exist |
The owner route lives on the existing /requests group (ViewingRequestHandler routes, module.go reqGroup), so the web path is /api/rental/requests/:id/tenant-profile, matching how the frontend already addresses requests.
tenantProfileSelfJSON — tenant
- Every key present,
nullwhen unanswered - Includes exact
birth_year - Includes
photo_url
tenantProfileOwnerJSON — landlord
- Unanswered fields omitted (
omitempty; pointers forsmoker,occupants); empty profile is{} age_rangeinstead ofbirth_year- No user id, no name, no email
Known limits
Frontend (apps/rental)
Data access
src/features/rental/api/tenantProfile.ts, following api/requests (plain async functions plus tenantProfileQueryKeys; hooks stay inline in components): getOwnTenantProfile, saveTenantProfile, uploadTenantProfilePhoto, deleteTenantProfilePhoto, getRequestTenantProfile(requestId). ApiErrorEnvelope gains fields?: string[] so the form can read server field errors.
TenantProfileCard
features/rental/TenantProfileCard.tsx is a pure display of the owner-view shape, in two variants:
full: photo (initials avatar fallback), first name (prop), a line of answered facts (25–29 · Chinese · Malaysian · Software engineer), badges (non-smoker / smoker, occupants, move-in month, pets or "no pets", employment type, languages), about text.compact: photo, first name (prop), age range and occupation; expands tofullon tap.
Empty profile: "This tenant hasn't added profile details."
Mei
25–29 · Chinese · Malaysian · Software engineer
Quiet and tidy, works from the office on weekdays.
TenantProfileCard (full variant) — the same card renders as the tenant's "What landlords see" preview.Tenant page /tenant/profile
- Add
{ id: 'profile', href: '/tenant/profile' }as the lastTENANT_RENTAL_NAVIGATIONentry (rentalNavigation.ts). - Intro copy: "Everything here is optional. Landlords you've requested a viewing from can see what you fill in."
- One form, four groups: About you (photo, gender, birth year, race, nationality), Work (occupation, employment type), Move-in plans (occupants, move-in month, smoker, pets), More (languages, about). Every select defaults to "Not specified"; text fields show counters; one Save button. Photo upload/remove act immediately.
- "What landlords see" preview renders
TenantProfileCard(full) from the saved self profile mapped through the same owner-view mapping in TypeScript (age range computed with the same brackets). - Server 400
fieldshighlight the matching inputs; typed values are kept.
Landlord surfaces
Viewing request
fullroutes/landlord/viewings/[id].tsx- Card above
LandlordRequestActions
Offer
fullroutes/landlord/offers/[id].tsx- Via the offer's
request_id
Message thread
compactInboxView, only whenuserRole === 'landlord'- Under the conversation header, named from
counterparty_name
Booking nudge
On routes/tenant/requests/[id], show a dismissible hint "Landlords respond faster when they know a bit about you → Complete profile" only while the own profile has no answered fields and no photo. Dismissal is stored in localStorage. Booking never waits on or checks the profile.
i18n
All copy and every enum label (gender, race, nationality group, employment type, pets, languages, age brackets) as paraglide messages in i18n/en.json, ms.json, zh.json. Country names via Intl.DisplayNames in the active locale.
Testing
Go
- Entity: each field's boundaries (birth year at 18 and 100 years, occupants 0/1/10/11, text limits after trim, past move-in month rejected, unknown enum values and duplicates rejected);
smoker=falseandpets={}preserved distinctly fromNULL. - Handler integration (pg-test on
:55432): owner of a request from the tenant gets the profile at pending, declined and withdrawn statuses; another landlord and the tenant themselves get 404 on the owner endpoint; owner response hasage_rangeand nobirth_year;PUTwithnullclears a field;GETwith no row returns all nulls; photo replace removes the previous object. - No OpenAPI drift change:
openapi_drift_test.gocovers only/api/v1/rentalroutes.
Frontend (vitest)
- Profile form saves, clears a field, and shows server field errors.
- Preview and landlord card render identically for the same data.
- Landlord request page shows the empty-profile message for
{}and renders actions when the profile fetch fails. - Nudge shows only for an empty profile and stays dismissed.
rentalNavigation.test.tsupdated for the new entry.
Smoke (UAT, GO_ENV=development)
- Sign up a tenant, fill some fields and upload a photo.
- Book a viewing.
- As the landlord, see the card on the viewing request, offer and thread.
- As a second landlord, confirm the endpoint returns 404.
Out of scope
Partner API
not exposedExposing the profile through the partner / landlord /v1 API.
Verification
noneVerification of any field (ID, employment, income).
Filtering
noneLandlord-side filtering or sorting of requests by profile fields.
Deletion cleanup
all rental tablesAccount-deletion cleanup across rental tables.