Entity Relation Design - NFSandbox/sh_trade_backend GitHub Wiki

[!warning] The overall entities and relationship design may changes over time. You should check out the ORM Class declaration file for more up-to-date and accurate info. You could get the link to that file at the Refs chapters at the end of this article.

In this wiki page, we will briefly discuss the design of the entities and relation in this system.

Sub ER Diagrams

User-Item-Trade ER Diagram

The image above illustrates the relationship between Users and Item.

  • A TradeRecord has references to two different users, the seller and buyer.
  • TradeRecord has a One-To-One relation with a single Item. The status(交易状态) field indicates the current state of the trade which is represented as an Enum type in Python and database.

For info about how Python Enum works with SQLAlchemy, check out SQLAlchemy Docs - Using Enum with ORM


User-ContactInfo Diagram

Image above shows sub ER diagram between User and ContactInfo.

Our system allows each user to have several contact info entries. Users could add several personal contact methods like QQ, WeChat, Phone Number and Email.

This feature achieved by creating a new entity ContactInfo, Here is breakdown of some of its field:

  • contact_info_type(平台) specifies the type of the info, (e.g.: WeChat).
  • contact_info(平台ID) stores the actual contact details with the specified type, (e.g.: QQ Number for rows with contact_info_type == 'QQ')

Item-Question ER Diagram

For each published Item, users (especially prospective buyers) often have questions that aren't adequately addressed in the item description written by seller.

To accomodate such issue, our system allows any eligible user to ask question about a specific Item.

  • Any users can ask questions about Item.
  • Question could be set to public or private. Public question are visible to any users including question and answer.
  • Only seller Item can reply the question relavant to the Item.

Items-Tags ER Diagram

Image above describes the item-tag system entities design in this system. Users could add several tags to their published Item, while buyers have the ability to categorize their search result or recommendation flow using Tag as filter.

There is a very classical Many-To-Many relation between Tag and Item entity, that is:

  • An Item could have several Tag attributes.
  • There are several Item objects belongs to a single Tag.

To achieve such relation, we used one more association table besides two entities with only two fields: tag_id and user_id with both of them specified as Primary Key.

Outline & Overall ER Diagrams

Outline ER Diagram

Full ER Diagram

[!note] If you are suffering issues about low image quality or image load failure, you could check out View ER Diagram DrawIO Project File Online link in Refs chapter below.

Refs