DATA MODEL DOCUMENTATION / DOCIFY CLI

How to generate an ER diagram from code

An ER diagram is useful only when its entities and relationships match the data model. Docify starts with supported model and schema declarations in your checkout. It does not connect to or reverse-engineer a live database.

1. Find the schema declarations in your project

Look for the model or schema definitions that describe the data structure, such as supported ORM models or SQL CREATE TABLE statements. A database driver listed in a manifest alone is not enough to establish a table's fields and relationships.

Coverage varies by schema syntax and adapter. The generated result can be partial, especially when fields or associations are assembled dynamically. Start from the declarations in the checkout you intend to document.

2. Run the documentation generator

npx @autodocify/autodocs analyze .

Use Node.js 20 or newer and run the command from the project root. Docify inspects local files without starting the application or querying a database.

The command writes overview.md, architecture.md and er-diagram.md into docs/. Review existing files first so you do not lose hand-written content under those generated filenames.

3. Open the generated Mermaid document

docs/
  overview.md
  architecture.md
  er-diagram.md

Open docs/er-diagram.md in a Markdown viewer with Mermaid support. The file contains the detected entity-relationship diagram and a field reference. A plain Markdown editor may show the Mermaid source instead of rendering a diagram.

Use docs/architecture.md alongside the diagram to understand the detected stack, models and source components. A table map by itself does not explain authorization, lifecycle rules or the purpose of a relationship.

4. Verify fields and relationships

Compare the result with your source models and migrations. Check primary keys, foreign keys, table names and relationship directions. An omitted edge can reflect unsupported syntax rather than the absence of a real relationship.

Declared models and physical database tables can differ. Generated documentation also cannot confirm that migrations have been applied or that production uses the schema in your current branch.

5. Review diagram changes with schema changes

Regenerate after a model or schema change, inspect the Markdown diff and commit the reviewed result with the implementation. This makes unexpected diagram changes visible during code review.

Keep business rules and database operational notes in companion documentation. They require context beyond static schema declarations and should be maintained deliberately.