{"id":28938167,"url":"https://github.com/delexw/mermaid_rails_erd","last_synced_at":"2026-01-20T16:59:46.840Z","repository":{"id":299912428,"uuid":"1003432417","full_name":"delexw/mermaid_rails_erd","owner":"delexw","description":"A Ruby gem that generates Mermaid.js Entity Relationship Diagrams (ERD) from ActiveRecord models in Rails applications.","archived":false,"fork":false,"pushed_at":"2025-06-18T23:54:11.000Z","size":125,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-19T00:18:18.868Z","etag":null,"topics":["activerecord","activerecord-models","entity","entity-relationship-diagram","erd","gem","generator","mermaid","rails","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/delexw.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-17T06:27:47.000Z","updated_at":"2025-06-18T23:54:14.000Z","dependencies_parsed_at":"2025-06-19T00:18:22.514Z","dependency_job_id":"c83a267c-ff1e-47c4-abab-58060c4a34a0","html_url":"https://github.com/delexw/mermaid_rails_erd","commit_stats":null,"previous_names":["delexw/mermaid_rails_erd"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/delexw/mermaid_rails_erd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delexw%2Fmermaid_rails_erd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delexw%2Fmermaid_rails_erd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delexw%2Fmermaid_rails_erd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delexw%2Fmermaid_rails_erd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/delexw","download_url":"https://codeload.github.com/delexw/mermaid_rails_erd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/delexw%2Fmermaid_rails_erd/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261119541,"owners_count":23112206,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activerecord","activerecord-models","entity","entity-relationship-diagram","erd","gem","generator","mermaid","rails","ruby"],"created_at":"2025-06-22T22:07:05.776Z","updated_at":"2026-01-20T16:59:46.834Z","avatar_url":"https://github.com/delexw.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mermaid Rails ERD\n\n[![Gem Version](https://badge.fury.io/rb/mermaid_rails_erd.svg)](https://badge.fury.io/rb/mermaid_rails_erd)\n[![CI](https://github.com/delexw/mermaid_rails_erd/workflows/CI/badge.svg)](https://github.com/delexw/mermaid_rails_erd/actions)\n\nA Ruby gem that generates [Mermaid.js](https://mermaid.js.org/) Entity Relationship Diagrams (ERD) from ActiveRecord models in Rails applications.\n\n## Features\n\n- 🔍 **ActiveRecord Introspection**: Automatically discovers your Rails models and their relationships\n- 📊 **Mermaid ERD Generation**: Outputs clean, readable Mermaid.js ERD syntax\n- 🚀 **Simple Integration**: Easy-to-use Rake task for generating diagrams\n- 🔗 **Relationship Mapping**: Supports `belongs_to`, `has_one`, `has_many`, and `has_and_belongs_to_many` associations\n- 💫 **Polymorphic Support**: Accurately discovers and maps polymorphic relationships\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'mermaid_rails_erd', group: :development\n```\n\nAnd then execute:\n\n```bash\n$ bundle install\n```\n\nOr install it yourself as:\n\n```bash\n$ gem install mermaid_rails_erd\n```\n\n## Usage\n\n### Generate ERD with Rake Task\n\nThe simplest way to generate your ERD is using the provided Rake task:\n\n```bash\n$ bundle exec rails mermaid_rails_erd:generate\n```\n\nThis will:\n1. Analyze all your ActiveRecord models\n2. Generate a Mermaid ERD file at `tmp/erd.mmd`\n3. Provide instructions on how to view the diagram\n\n### Viewing the Generated ERD\n\nOnce you have generated the `.mmd` file, you can view it using the recommended viewer with better interactive below:\n\n- **Mermaid ERD Visulizer**: https://github.com/delexw/mermaid-erd-visualizer\n\n\n### Advanced Usage: Model Data Interface\n\nYou can access the collected model and relationship data directly without generating a diagram:\n\n#### Simple Data Collection\n\n```ruby\n# Get all collected data in a structured format\ndata = MermaidRailsErd.build.parsed_data\n\n# Access collected data\nmodels_data = data.models_data                           # Hash of models having table keyed by model name\nmodels = data.models                                     # Array of all loaded models\nmodels_no_tables = data.models_no_tables                 # Array of models missing tables\nrelationships = data.relationships                       # Array of relationship objects\ninvalid_associations = data.invalid_associations         # Array of associations missing associated table\npolymorphic_associations = data.polymorphic_associations # Array of polymorphic associations\nregular_associations = data.regular_associations         # Array of regular (non-polymorphic) associations\n\n```\n\n\n## Example Output\n\nGiven Rails models like:\n\n```ruby\nclass User \u003c ActiveRecord::Base\n  has_many :posts\n  has_one :profile\nend\n\nclass Post \u003c ActiveRecord::Base\n  belongs_to :user\n  has_many :comments\nend\n\nclass Comment \u003c ActiveRecord::Base\n  belongs_to :post\nend\n\nclass Profile \u003c ActiveRecord::Base\n  belongs_to :user\nend\n```\n\nThe gem will generate:\n\n```mermaid\nerDiagram\n  users {\n    bigint id PK\n    varchar email\n    varchar name\n    timestamp created_at\n    timestamp updated_at\n  }\n  \n  posts {\n    bigint id PK\n    bigint user_id\n    varchar title\n    text content\n    timestamp created_at\n    timestamp updated_at\n  }\n  \n  comments {\n    bigint id PK\n    bigint post_id\n    text content\n    timestamp created_at\n    timestamp updated_at\n  }\n  \n  profiles {\n    bigint id PK\n    bigint user_id\n    text bio\n    timestamp created_at\n    timestamp updated_at\n  }\n  \n  users ||--o{ posts : \"user_id\"\n  posts ||--o{ comments : \"post_id\"\n  users ||--|| profiles : \"user_id\"\n```\n\n## Polymorphic Associations\n\nThe gem automatically detects and properly maps polymorphic associations in your models. For example:\n\n```ruby\nclass Comment \u003c ActiveRecord::Base\n  belongs_to :commentable, polymorphic: true\nend\n\nclass Post \u003c ActiveRecord::Base\n  has_many :comments, as: :commentable\nend\n\nclass Photo \u003c ActiveRecord::Base\n  has_many :comments, as: :commentable\nend\n```\n\nThe ERD will correctly show relationships between `comments` and both `posts` and `photos` tables.\n\n## Supported ActiveRecord Associations\n\n- **belongs_to**: Generates one-to-many relationships\n- **has_one**: Generates one-to-one relationships  \n- **has_many**: Covered by the corresponding belongs_to\n- **has_and_belongs_to_many**: Generates many-to-many relationships\n- **polymorphic**: Discovers and maps all polymorphic interfaces\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/delexw/mermaid_rails_erd.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for details about changes in each version. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelexw%2Fmermaid_rails_erd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdelexw%2Fmermaid_rails_erd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdelexw%2Fmermaid_rails_erd/lists"}