Of course! Here is a detailed ER (Entity-Relationship) diagram and explanation for a House Rental Management system with three user types: Admin, Owner, and Tenant.
Overview
This ERD is designed using Crow's Foot notation, which is common for representing relational database schemas. The model focuses on the core entities and the relationships between them to manage properties, rentals, payments, and maintenance.
The key to handling the three user types (Admin, Tenant, Owner) is a single Users table with a role attribute. This is a common and efficient design pattern that avoids creating separate, largely identical tables for each user type.
ER Diagram
mermaid
erDiagram
Users {
int user_id (PK) "Primary Key"
varchar first_name
varchar last_name
varchar email "Unique"
varchar password_hash
varchar phone_number
enum role "('admin', 'owner', 'tenant')"
timestamp created_at
}
Properties {
int property_id (PK) "Primary Key"
int owner_id (FK) "Foreign Key to Users"
varchar address
text description
decimal rent_amount
int num_bedrooms
int num_bathrooms
enum status "('available', 'rented', 'maintenance')"
}
Rentals {
int rental_id (PK) "Primary Key"
int property_id (FK) "Foreign Key to Properties"
int tenant_id (FK) "Foreign Key to Users"
date start_date
date end_date
decimal security_deposit
enum status "('active', 'expired', 'terminated')"
}
Payments {
int payment_id (PK) "Primary Key"
int rental_id (FK) "Foreign Key to Rentals"
decimal amount
date payment_date
varchar payment_method
text notes
}
MaintenanceRequests {
int request_id (PK) "Primary Key"
int property_id (FK) "Foreign Key to Properties"
int tenant_id (FK) "Foreign Key to Users"
text description
enum status "('pending', 'in_progress', 'completed')"
timestamp request_date
}
Users ||--o{ Properties : "owns"
Users ||--o{ Rentals : "rents"
Users ||--o{ MaintenanceRequests : "submits"
Properties ||--o{ Rentals : "is rented via"
Properties ||--o{ MaintenanceRequests : "has"
Rentals ||--o{ Payments : "has"
Explanation of Entities and Relationships
1. Entities (Tables)
Users
This is the central table for all individuals interacting with the system.
user_id (PK): Unique identifier for each user.
email: Used for login and communication. It must be unique.
role: This is the most critical field for your requirement. It will store whether the user is an 'admin', 'owner', or 'tenant'. The application logic (in PHP) will use this field to determine permissions and what the user can see or do.
Properties
This table stores information about each rental property.
property_id (PK): Unique identifier for each property.
owner_id (FK): A foreign key that links to the user_id in the Users table. This establishes the "owns" relationship. The role for this user must be 'owner'.
status: Tracks if the property is currently available, rented, or under maintenance.
Rentals (Lease Agreements)
This entity acts as a link between a Tenant, an Owner (via the Property), and a specific rental period. It represents a lease agreement.
rental_id (PK): Unique identifier for each rental contract.
property_id (FK): Links to the property being rented.
tenant_id (FK): Links to the user who is the tenant. The role for this user must be 'tenant'.
Payments
Tracks all financial transactions, specifically rent payments.
payment_id (PK): Unique identifier for each payment.
rental_id (FK): Links each payment to a specific rental agreement, which in turn links it to a tenant and property.
MaintenanceRequests
Allows tenants to report issues with a property.
request_id (PK): Unique identifier for each maintenance request.
property_id (FK): Links the request to the specific property that has the issue.
tenant_id (FK): Links to the tenant who submitted the request.
2. Relationships (with Cardinality)
Users and Properties
An Owner (User) can own one or many Properties.
A Property is owned by one and only one Owner.
Implementation: The owner_id foreign key in the Properties table.
Users and Rentals
A Tenant (User) can have one or many Rentals (e.g., they could rent one property now and a different one later).
A Rental agreement is assigned to one and only one Tenant.
Implementation: The tenant_id foreign key in the Rentals table.
Properties and Rentals
A Property can be involved in zero or many Rentals over time (but typically only one 'active' rental at a time).
A Rental agreement pertains to one and only one Property.
Implementation: The property_id foreign key in the Rentals table.
Rentals and Payments
A Rental agreement can have many Payments made against it.
A Payment belongs to one and only one Rental agreement.
Implementation: The rental_id foreign key in the Payments table.
Users, Properties, and Maintenance Requests
A Tenant (User) can submit many Maintenance Requests.
A Maintenance Request is submitted by one and only one Tenant.
A Property can have many Maintenance Requests logged against it.
A Maintenance Request is for one and only one Property.
Implementation: The tenant_id and property_id foreign keys in the MaintenanceRequests table.
3. How the User Roles Work
Tenant: A user with the role of 'tenant'.
Can view their own Rental agreements and associated Properties.
Can make Payments.
Can submit MaintenanceRequests for the property they are renting.
Cannot see other tenants' information or properties they don't rent.
Owner: A user with the role of 'owner'.
Can create and manage Properties where their user_id is the owner_id.
Can view Rentals, Payments, and MaintenanceRequests associated with their properties.
Can view the details of the Tenants renting their properties.
Cannot see properties or data belonging to other owners.
Admin: A user with the role of 'admin'.
This role has no direct relationships in the ERD because its power is not structural but access-based.
The PHP application would grant Admins the ability to view, create, edit, and delete any record in any table. They oversee the entire system, manage user accounts, resolve disputes, and ensure data integrity.