Board example
Board ERD Example
A community board ERD example with boards, posts, comments, attachments, and likes.
Scenario
Board ERD Example
A community board where users write posts, leave comments, attach files, and like posts.
Core tables
boards, posts, comments, attachments
Key relation
posts 1:N comments
Main caution
Nested comments and attachment ownership
Requirements
Requirements
- A board contains many posts, and each post has an author.
- Comments belong to posts and may support replies.
- Attachments belong to posts, and likes must be unique per user and post.
Table design
Table design
usersAuthors- id PK
- nickname UNIQUE
- email
- created_at
boardsBoard categories- id PK
- name
- slug UNIQUE
- visibility
postsPosts- id PK
- board_id FK
- author_id FK
- title
- status
commentsComments- id PK
- post_id FK
- author_id FK
- parent_comment_id FK
- body
attachmentsFiles- id PK
- post_id FK
- file_url
- file_name
- size_bytes
post_likesPost likes- post_id PK/FK
- user_id PK/FK
- created_at
Relationships
Relationships
boards 1:N postsusers 1:N postsposts 1:N commentscomments 1:N commentsposts 1:N attachmentsposts N:M users through post_likes
Design notes
Design notes
Use a join table for likes
A composite primary key on post_likes(post_id, user_id) prevents duplicate likes.
Model replies with a self reference
comments.parent_comment_id can point to comments.id when nested comments are needed.
Decide deletion rules early
Author deletion, hidden posts, and attachment cleanup affect foreign keys and status columns.
Implementation checks
Implementation checks
- Add unique indexes for boards.slug and users.nickname.
- Use a composite primary key on post_likes(post_id, user_id).
- Add posts(board_id, created_at) for board listing queries.
More ERD examples
More ERD examples
Use these structures as a starting point, or open a demo canvas before creating an account.