Skip to content

Model graph image #1179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

yashgoyal0110
Copy link
Contributor

@yashgoyal0110 yashgoyal0110 commented Mar 25, 2025

fixes: #724

Summary by CodeRabbit

  • New Features
    • Introduced an automated process that generates up-to-date visual diagrams illustrating data relationships, providing enhanced clarity and oversight.
    • Upgraded system integration by incorporating advanced management tools and dependencies, resulting in a more consistent and reliable configuration.
    • These improvements streamline operations and facilitate easier maintenance.

@yashgoyal0110 yashgoyal0110 requested a review from arkid15r as a code owner March 25, 2025 20:48
Copy link
Contributor

coderabbitai bot commented Mar 25, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (2)
  • backend/poetry.lock is excluded by !**/*.lock
  • docs/models_relations.png is excluded by !**/*.png

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change introduces a new GitHub Actions workflow that generates and updates a model relationship diagram for the backend. The workflow is triggered by changes in Python model files and can also be manually activated. Additionally, the backend configuration has been updated by adding two new dependencies—django-extensions and pydotplus—and modifying the local settings to include the Django Extensions app.

Changes

Files Change Summary
.github/workflows/generate-erd.yaml Added a new GitHub Actions workflow to automate graph model generation on model file changes and manual trigger, including steps for environment setup, dependency installation, graph generation, artifact upload, and commit of the updated image.
backend/pyproject.toml, backend/settings/local.py Updated backend configuration by adding new dependencies django-extensions (^3.2.3) and pydotplus (^2.0.2) in the poetry config, and extended the local settings to include django_extensions in the INSTALLED_APPS list.

Assessment against linked issues

Objective Addressed Explanation
Add backend models graph build job (#724)

🐇 In the garden where models grow,
A graph of relations begins to show.
With Django's help, we weave and spin,
A diagram bright, where data's kin.
Automated joy, in workflows we trust,
For clearer insights, it's a must! 🌱


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@yashgoyal0110
Copy link
Contributor Author

Hey @arkid15r
I have refined the code for model graph image generation process, Just have a look and please provide your feedback how can we improve it more

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.github/workflows/generate-erd.yaml (1)

58-64: Consider storing the graph image in a dedicated documentation directory

Currently, the image is stored in the backend root directory. Consider storing it in a dedicated docs folder for better organization.

- DJANGO_CONFIGURATION=$DJANGO_CONFIGURATION DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE poetry run python manage.py graph_models -a -o models_relations.png
+ DJANGO_CONFIGURATION=$DJANGO_CONFIGURATION DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE poetry run python manage.py graph_models -a -o ../docs/models_relations.png

And update the related paths:

- path: backend/models_relations.png
+ path: docs/models_relations.png
- git add models_relations.png
+ git add ../docs/models_relations.png
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac432f and ca80168.

⛔ Files ignored due to path filters (2)
  • backend/models_relations.png is excluded by !**/*.png
  • backend/poetry.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • .github/workflows/generate-erd.yaml (1 hunks)
  • backend/pyproject.toml (1 hunks)
  • backend/settings/local.py (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
backend/settings/local.py (1)
backend/settings/base.py (1)
  • Base (9-199)
🔇 Additional comments (6)
backend/settings/local.py (1)

22-22: Appropriate addition of django_extensions to local settings

This correctly adds django_extensions to the INSTALLED_APPS for the local environment only, which is the best practice since it's a development tool rather than a production requirement.

backend/pyproject.toml (1)

49-50: Appropriate addition of development dependencies

The additions of django-extensions and pydotplus as development dependencies align with the purpose of generating model graphs. Both are correctly specified with caret version constraints and appropriately placed in the dev dependencies group.

.github/workflows/generate-erd.yaml (4)

1-8: Well-structured workflow with appropriate triggers

The workflow is properly named and configured with appropriate triggers:

  • Triggering on model file changes ensures the graph stays updated
  • The manual trigger provides flexibility for on-demand updates

13-32: Good setup of dependencies and tools

All necessary dependencies (Poetry, Graphviz, Python) are correctly installed with proper caching. Using Python 3.13 matches the project requirements, and the working directory is correctly set.


34-46: Proper environment configuration for Django

The environment variables are properly set with placeholder values for secrets, which is appropriate since they aren't needed for graph generation.


47-51: Effective use of django-extensions command

The command correctly utilizes django-extensions' graph_models management command with appropriate parameters.

@yashgoyal0110 yashgoyal0110 force-pushed the feat/build-model-graph branch from 655b0e8 to 4954ba9 Compare March 26, 2025 06:30
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
backend/apps/owasp/models/event.py (1)

195-195: Trailing Newline & Clarify Comment Marker
The new comment #11 appears to serve as a marker but does not alter functionality. If it is meant for debugging or as a placeholder, please consider adding more context or removing it if unnecessary. Additionally, ensure the file ends with a newline to satisfy linting requirements (W292).

🧰 Tools
🪛 Ruff (0.8.2)

195-195: No newline at end of file

Add trailing newline

(W292)

.github/workflows/generate-erd.yaml (2)

3-8: Enhance Workflow Trigger with paths-ignore
To avoid re-triggering the workflow when the generated graph image is committed, consider adding a paths-ignore field. For example, update the trigger configuration as shown below:

-on:
-  push:
-    paths:
-      - "backend/apps/*/models/*.py"
-  workflow_dispatch:
+on:
+  push:
+    paths:
+      - "backend/apps/*/models/*.py"
+    paths-ignore:
+      - "backend/models_relations.png"
+  workflow_dispatch:

This change will help prevent unnecessary runs due to automated commits.


20-21: Update Apt Package List Before Installing Graphviz
It is a best practice to update the package list to ensure the latest packages are available. Consider modifying the "Install Graphviz" step as follows:

-      - name: Install Graphviz
-        run: sudo apt-get install -y graphviz
+      - name: Install Graphviz
+        run: sudo apt-get update && sudo apt-get install -y graphviz

This reduces the risk of installation failures or outdated package issues.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3c86c2c and 70ce58b.

⛔ Files ignored due to path filters (1)
  • backend/models_relations.png is excluded by !**/*.png
📒 Files selected for processing (2)
  • .github/workflows/generate-erd.yaml (1 hunks)
  • backend/apps/owasp/models/event.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
backend/apps/owasp/models/event.py

195-195: No newline at end of file

Add trailing newline

(W292)

@yashgoyal0110 yashgoyal0110 force-pushed the feat/build-model-graph branch 14 times, most recently from e0a5383 to b5e878c Compare March 26, 2025 12:02
@yashgoyal0110 yashgoyal0110 force-pushed the feat/build-model-graph branch from b5e878c to 848f7e7 Compare March 26, 2025 12:02
@yashgoyal0110
Copy link
Contributor Author

Hey @arkid15r
Can you please give your feedback for this once you get a chance
Thanks!

@yashgoyal0110
Copy link
Contributor Author

@CodeRabbit
can you review this PR

Copy link
Contributor

coderabbitai bot commented Apr 9, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll review the changes in PR #1179 "Model graph image" by running a script to examine the files more closely.


🏁 Script executed:

#!/bin/bash
# Get the content of the workflow file
echo "Examining the workflow file:"
cat .github/workflows/generate-erd.yaml

echo "Examining changes to pyproject.toml:"
cat backend/pyproject.toml

echo "Examining changes to settings/local.py:"
cat backend/settings/local.py

Length of output: 5752


@yashgoyal0110 I've reviewed your PR for the model graph image generation feature. Here's my assessment:

Overall Impression

This is a well-implemented solution that automates the generation of database model diagrams, which will be very helpful for documentation and visualizing the application structure. Nice work!

Strengths

  • Automation: The GitHub workflow automatically updates the diagram when model files change
  • Proper tooling: Good choice using django-extensions and pydotplus for diagram generation
  • Persistence: Storing both as an artifact and committing back to the repo ensures visibility

Suggestions for Enhancement

  1. Error handling: Consider adding error handling in the workflow for more robustness
  2. Customization options: The graph_models command supports additional flags that could improve visualization:
    # Example with grouping by application
    poetry run python manage.py graph_models --group-models -a -o ../docs/models_relations.png
    
    # Example excluding certain models that might clutter the diagram
    poetry run python manage.py graph_models -a -X ModelToExclude,AnotherModel -o ../docs/models_relations.png
    
  3. Image readability: For larger applications, diagrams can become complex. Consider options to:
    • Split diagrams by app
    • Use color coding for different model types
    • Add a legend for better understanding

Great implementation of an automated documentation feature! This will help maintain up-to-date visual documentation of your data models.

(__/)
(•ㅅ•)
/  づ 📝

@yashgoyal0110
Copy link
Contributor Author

yashgoyal0110 commented Apr 12, 2025

Hey @arkid15r
Can you please give your feedback for this once you get a chance
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add backend models graph build job
3 participants