# Entity Model

---

**Document Version:** 1.0
**Project:** Student Bazaar
**Document Type:** Entity Model Specification
**Status:** Approved
**Last Updated:** 28 June 2026
**Author:** Nemmi Tangha

---

# 1. Purpose

This document defines the core entities of Student Bazaar and describes their responsibilities, relationships, and business rules.

Each entity represents a logical component of the system and will later be implemented as one or more database tables using SQLAlchemy and MySQL.

This document serves as the foundation for:

* Entity Relationship Diagram (ERD)
* Database Schema
* SQLAlchemy Models
* API Design
* Business Logic

---

# 2. Entity Overview

Student Bazaar is divided into the following domains:

* Authentication
* Marketplace
* Communication
* Negotiation
* Meet-up Scheduling
* Notifications
* Administration
* Premium Services
* Analytics

---

# 3. Authentication Entities

## User

### Purpose

Represents every registered account within the system.

A single Student account can act as both buyer and seller.

A Super Admin manages the platform.

### Relationships

* One User creates many Listings.
* One User sends many Messages.
* One User receives many Notifications.
* One User creates many Offers.
* One User creates many Reports.
* One User owns zero or one Premium Subscription.

---

## Email Verification

### Purpose

Stores email verification requests and verification tokens.

### Relationships

* Belongs to one User.

---

## Password Reset Token

### Purpose

Stores secure password reset requests.

### Relationships

* Belongs to one User.

---

# 4. Marketplace Entities

## Category

### Purpose

Organizes product listings into logical groups.

Examples include:

* Electronics
* Books
* Furniture
* Clothing
* Accessories

### Relationships

* One Category contains many Listings.

---

## Listing

### Purpose

Represents a product offered for sale.

A listing includes:

* Product Information
* Price
* Status
* Expiration
* Seller

### Relationships

* Belongs to one User.
* Belongs to one Category.
* Has many Images.
* Has many Offers.
* Has one Conversation.
* Has many Favorites.
* Has many Views.
* Has many Reports.

---

## Listing Image

### Purpose

Stores images belonging to a product listing.

Business Rule:

Each listing must contain:

* Minimum 1 image
* Maximum 7 images

### Relationships

* Belongs to one Listing.

---

## Favorite

### Purpose

Stores products saved by students.

### Relationships

* Belongs to one User.
* References one Listing.

---

# 5. Negotiation Entities

## Offer

### Purpose

Represents the current negotiation between buyer and seller.

Supports:

* Initial Offer
* Counter Offer
* Accepted Offer
* Rejected Offer

### Relationships

* Belongs to one Listing.
* Created by one User.

---

## Offer History

### Purpose

Maintains the complete negotiation history.

No offer should be permanently overwritten.

Every price proposal is preserved.

### Relationships

* Belongs to one Offer.

---

# 6. Communication Entities

## Conversation

### Purpose

Represents a chat related to one specific listing.

Business Rules:

* One conversation per listing.
* Chat activates only after both users exchange their first message.
* Free conversations contain 10 messages.
* Rewarded advertisements unlock 5 additional messages.
* Premium users have unlimited messaging.

### Relationships

* Belongs to one Listing.
* Connects two Users.
* Contains many Messages.

---

## Message

### Purpose

Stores messages exchanged during conversations.

### Relationships

* Belongs to one Conversation.
* Sent by one User.

---

# 7. Meet-up Entity

## Meet-up

### Purpose

Stores agreed meeting information after an offer is accepted.

Students may:

* Suggest Date
* Suggest Time
* Suggest Location
* Accept
* Reject
* Reschedule

### Relationships

* Belongs to one accepted Offer.

---

# 8. Notification Entity

## Notification

### Purpose

Stores user notifications.

Examples include:

* New Message
* New Offer
* Counter Offer
* Offer Accepted
* Meet-up Scheduled
* Listing Expiring
* Report Update
* Premium Reminder

### Relationships

* Belongs to one User.

---

# 9. Administration Entities

## Report

### Purpose

Stores reports submitted by students.

Reasons include:

* Fake Listing
* Spam
* Fraud
* Harassment
* Inappropriate Images

### Relationships

* Created by one User.
* References one Listing or another User.

---

## Advertisement

### Purpose

Stores advertisements displayed throughout the platform.

Supports:

* Banner Ads
* Rewarded Ads

### Relationships

Managed by the Super Admin.

---

## Premium Subscription

### Purpose

Stores premium membership information.

Tracks:

* Subscription Status
* Start Date
* Expiration Date

### Relationships

Belongs to one User.

---

## Super Admin Log

### Purpose

Records important administrative actions.

Examples:

* User Suspension
* Listing Removal
* Report Resolution
* Advertisement Updates

### Relationships

Created by one Super Admin.

---

# 10. Analytics Entities

## Listing Analytics

### Purpose

Basic marketplace analytics are stored directly within the `listings` entity.

Current analytics include:

- View Count
- Favorite Count
- Offer Count

These values support:

- Seller Dashboard
- Marketplace Statistics
- Popular Listings

Future versions may introduce a dedicated analytics module if detailed event tracking becomes necessary.

### Relationships

References one Listing.

---

# 11. Entity Relationships Summary

The core relationships include:

* User → Listings (1:M)

* User → Offers (1:M)

* User → Messages (1:M)

* User → Notifications (1:M)

* User → Reports (1:M)

* User → Favorites (1:M)

* Category → Listings (1:M)

* Listing → Images (1:M)

* Listing → Offers (1:M)

* Listing → Favorites (1:M)

* Listing → Reports (1:M)

* Listing → Views (1:M)

* Listing → Conversation (1:1)

* Conversation → Messages (1:M)

* Offer → Offer History (1:M)

* Accepted Offer → Meet-up (1:1)

---

# 12. Business Rules

The following business rules apply:

* Every listing belongs to exactly one student.
* Every listing must contain between one and seven images.
* Every conversation belongs to one listing.
* One listing can have only one active conversation between a specific buyer and seller.
* Meet-ups can only be scheduled after an offer is accepted.
* Student Bazaar never processes payments.
* Premium users receive unlimited messaging.
* Free users receive ten messages per conversation.
* One rewarded advertisement unlocks five additional messages.

---

# 13. Future Entities

Future versions may introduce additional entities including:

* Payment Transactions
* AI Recommendations
* QR Verification
* College Verification
* Delivery Tracking
* Mobile Devices
* Push Notification Tokens

These entities are intentionally excluded from Version 1.

---

# 14. Conclusion

The entities defined in this document represent the complete logical data model for Student Bazaar Version 1.

These entities will be translated into a normalized MySQL schema and SQLAlchemy models while preserving the relationships and business rules described in this document.
