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

feat: add bff handler context #577

Merged
merged 1 commit into from
Oct 31, 2024
Merged

feat: add bff handler context #577

merged 1 commit into from
Oct 31, 2024

Conversation

brobro10000
Copy link
Member

@brobro10000 brobro10000 commented Oct 28, 2024

Description:
This application, bffs, has been added to enterprise-access. bff stands for "backend-for-frontend" and is designed to provide a consolidated API layer for supporting enterprise micro frontends (MFEs). The bffs application serves as an intermediary between frontend components and underlying services, centralizing business logic and data transformation within a single BFF layer. This approach aims to streamline data returned to the frontend, minimizing the need for additional transformation on the client side, and enabling frontend components to consume data in a more ready-to-use format.

Additionally, this PR introduces a HandlerContext component. HandlerContext will store the instantiated requests originating from API client calls, preparing them to be utilized by an upcoming response builder, designed to construct responses for each corresponding API call.

Each MFE will support route-based API calls, allowing for flexible orchestration of the frontend. This structure enables individual MFEs to manage route-specific API calls, ensuring a seamless flow between frontend routes and backend data, optimized for MFE interactions and reducing redundant API calls across the application.

Jira:
ENT-XXXX

Merge checklist:

  • ./manage.py makemigrations has been run
    • Note: This must be run if you modified any models.
      • It may or may not make a migration depending on exactly what you modified, but it should still be run.

Post merge:

  • Ensure that your changes went out to the stage instance
  • Deploy to prod instance

@brobro10000 brobro10000 force-pushed the hu/ent-9628 branch 2 times, most recently from f7187a5 to 0ab0b2d Compare October 30, 2024 17:44
enterprise_access/apps/bffs/context.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/context.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/context.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/context.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/context.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/context.py Outdated Show resolved Hide resolved
@brobro10000 brobro10000 marked this pull request as ready for review October 31, 2024 14:28
self.enterprise_customer_uuid = None
self.lms_user_id = None
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: Something I considered but deferred on is the inclusion of url and params as a means of populating the enteprise_customer_uuid or lms_user_id within the HandlerContext. This would also help improve traceback of warnings/errors to specific calls within the BFF layer.

Copy link
Member

@adamstankiewicz adamstankiewicz Oct 31, 2024

Choose a reason for hiding this comment

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

[inform] I agree. From our synchronous discussion, we could likely move the initialize_common_context_data from the reference prototype's BaseHandler into the HandlerContext so the route/base handler's themselves don't need to worry about it.

Edit: as you proposed, this change could also be deferred for this PR and saved for your next ticket to bring in the actual handlers to populate the HandlerContext.

Comment on lines +18 to +22
def create(self, validated_data):
return validated_data

def update(self, instance, validated_data):
return validated_data
Copy link
Member Author

Choose a reason for hiding this comment

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

Included to fix linting error of abstract-method
Screenshot 2024-10-31 at 10 34 38 AM

Comment on lines +15 to +17
developer_message = serializers.CharField()
user_message = serializers.CharField()

Copy link
Member Author

@brobro10000 brobro10000 Oct 31, 2024

Choose a reason for hiding this comment

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

Note: Something I considered but deferred on was to serialize the request url and params as part of exposing pertinent metadata within the errors for better observability.

Copy link
Contributor

@iloveagent57 iloveagent57 left a comment

Choose a reason for hiding this comment

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

Looks good, small suggestion.

enterprise_access/apps/bffs/context.py Outdated Show resolved Hide resolved
@brobro10000 brobro10000 force-pushed the hu/ent-9628 branch 2 times, most recently from 70e7b82 to 256b217 Compare October 31, 2024 15:36
enterprise_access/apps/bffs/tests/test_context.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/tests/test_context.py Outdated Show resolved Hide resolved
enterprise_access/apps/bffs/context.py Outdated Show resolved Hide resolved
@adamstankiewicz adamstankiewicz dismissed their stale review October 31, 2024 17:30

Accidentally approved, instead of only leaving comments.

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

LGTM!

@brobro10000 brobro10000 merged commit ac5c9eb into main Oct 31, 2024
3 checks passed
@brobro10000 brobro10000 deleted the hu/ent-9628 branch October 31, 2024 19:47
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.

3 participants