Project

arerd

0.0
The project is in a healthy, maintained state
Provides a Rake task that extracts entity-relationship information from ActiveRecord models and generates an ER diagram in Mermaid notation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

>= 6.0
 Project Readme

Arerd

Arerd is a Ruby gem that extracts Entity-Relationship (ER) information from your ActiveRecord models and generates clear, visual ER diagrams in Mermaid format.

Once integrated into your Rails project, Arerd provides a convenient Rake task (db:erd:mermaid or db:erd:markdown) that outputs a Mermaid-formatted ER diagram directly to your terminal.

You can also automate ER diagram generation in your CI pipeline by outputting the diagram in Markdown format. This ensures your ER diagram documentation is always up to date and easy to maintain.

Installation

Add Arerd to your Rails application's Gemfile:

gem "arerd"

Then install the gem:

bundle install

Usage

Generate a Mermaid ER Diagram

Run the following command to create a Mermaid ER diagram:

bin/rails db:erd:mermaid

This will output the diagram in Mermaid's erDiagram format to standard output. You can copy and paste the result into the Mermaid Live Editor or any Mermaid-compatible tool to visualize your ER diagram.

Generate a Markdown ER Diagram

To output the ER diagram in Markdown format:

bin/rails db:erd:markdown

This command prints the diagram wrapped in triple backticks and tagged as mermaid, allowing you to preview it directly in supported Markdown editors or viewers.

Internationalization (I18n) Support

Table and column names in diagrams are automatically translated using your Rails application's locale files. Arerd leverages Rails' I18n system to provide localized names for entities and attributes, making diagrams more accessible for international teams.

Notes

  • All associations must specify the inverse_of option.
  • Associations using has_many :through are ignored.
  • Polymorphic associations (e.g., belongs_to :taggable, polymorphic: true) are not supported.

Example Output

erDiagram
  User["User (ユーザー)"] {
    integer id PK "Id"
    string name UK "名前 (indexed)"
    datetime created_at "作成日時"
    datetime updated_at "更新日時"
  }
  Profile["Profile (プロフィール)"] {
    integer id PK "Id"
    integer user_id FK "ユーザーID (indexed)"
    string bio "自己紹介 (nullable)"
    datetime created_at "作成日時"
    datetime updated_at "更新日時"
  }
  Post["Post (投稿)"] {
    integer id PK "Id"
    string title "タイトル"
    text body "本文"
    integer user_id FK "ユーザーID (indexed)"
    datetime created_at "作成日時"
    datetime updated_at "更新日時"
  }
  Notification["Notification (通知)"] {
    integer id PK "Id"
    integer user_id FK "ユーザーID (indexed)"
    integer sender_id FK "送信者ID (nullable, indexed)"
    string message "メッセージ"
    datetime created_at "作成日時"
    datetime updated_at "更新日時"
  }
  Follow["Follow (フォロー)"] {
    integer id PK "Id"
    integer follower_id FK "フォロワーID (indexed)"
    integer followed_id UK "フォロー対象ID (indexed)"
    datetime created_at "作成日時"
    datetime updated_at "更新日時"
  }
  Community["Community (コミュニティ)"] {
    integer id PK "Id"
    string name "名前"
    datetime created_at "作成日時"
    datetime updated_at "更新日時"
  }

  User ||--o{ Post : "posts / user"
  User ||--o| Profile : "profile / user"
  User ||--o{ Follow : "follows / follower"
  User ||--o{ User : "followees / followers"
  User ||--o{ Follow : "reverse_follows / followee"
  User ||--o{ User : "followers / followees"
  User ||--o{ Notification : "notifications / user"
  User |o--o{ Notification : "sent_notifications / sender"
  Community }o--o{ User : "users / communities"
Loading