Skip to content
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

Model graph image #1179

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

Conversation

yashgoyal0110
Copy link
Contributor

fixes: #724

@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 (1)
  • backend/poetry.lock is excluded by !**/*.lock

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.

Summary by CodeRabbit

This release brings a new automated process that generates and keeps our application's data model diagram up-to-date, offering clearer insights into the system structure. Additionally, enhancements to supporting tools and configurations improve the overall reliability of this feature.

  • New Features
    • Automated generation and update of a visual data model diagram.
  • Chores
    • Improved internal tools and configurations to support the enhanced diagram generation workflow.

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)

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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!

Copy link

sonarqubecloud bot commented Apr 6, 2025

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