Skip to content

Refactor Django application to FastAPI#3

Draft
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
feat/refactor-django-to-fastapi
Draft

Refactor Django application to FastAPI#3
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
feat/refactor-django-to-fastapi

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

This commit refactors the original Django-based graph visualization application to a modern FastAPI framework. The goal of this refactoring was to modernize the codebase, improve maintainability, and leverage the benefits of FastAPI such as automatic API documentation and improved performance.

Key Changes:

  1. Application Framework: The entire backend has been migrated from Django to FastAPI. A new project structure has been created in the fastapi_app directory, following modern Python application design patterns.

  2. Database and Models:

    • The Django ORM has been replaced with SQLAlchemy for database operations.
    • The Command and CommandParameter models have been re-implemented as SQLAlchemy models.
    • Pydantic models have been introduced for data validation and serialization, ensuring a clear and robust API contract.
    • A simple SQLite database is used for data storage.
  3. Core Logic Refactoring:

    • The convertGraph function, which is responsible for parsing various graph formats, has been significantly refactored. The new implementation is more modular, readable, and maintainable, with separate parser functions for each supported format.
  4. API Endpoints:

    • All Django views have been re-implemented as FastAPI endpoints.
    • HTML pages are now served using a pages router with Jinja2 templates.
    • API endpoints are organized under an api router with a consistent /api prefix.
    • The modifyAPI endpoint, which executes external binaries, has been improved to use subprocess.run with stdin/stdout, which is more secure than the original implementation.
  5. Frontend Integration:

    • The frontend JavaScript files have been updated to communicate with the new FastAPI backend.
    • All API endpoint URLs in the JavaScript have been updated to match the new routing structure.
    • Django-specific CSRF token logic has been removed from the frontend code.

This refactoring provides a solid foundation for future development and improvements. The next step would be to thoroughly test the application to ensure all functionalities are working as expected.

This commit refactors the Django-based graph visualization application to a modern FastAPI framework.

The key changes include:
- Migration of the backend from Django to FastAPI.
- Replacement of the Django ORM with SQLAlchemy and Pydantic models.
- Refactoring of the core graph parsing logic for improved maintainability.
- Re-implementation of all views as FastAPI endpoints with a consistent API structure.
- Updates to the frontend JavaScript to integrate with the new backend.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants