How sjors-berendsen/pws works
The AI Module
• Located in the “ai” directory.
• Contains data (data.xlsx, input.txt) and scripts for training (train_model.py) and prediction (predict.py), along with a model definition (model.py).
• Represents the core machine learning functionality.
The API Component
• All of its code is located in the “api” directory.
• Likely built as a web service (e.g., using Flask or a similar framework in app.py), this module provides endpoints that can serve the AI model’s predictions.
• It also contains its own copies of model.py and predict.py, which indicates that the API layer might wrap or adapt the AI functionality to expose it externally.
• Includes a test HTML file (test.html) for possibly testing or demoing the endpoint responses and a domains.txt file, which might be used for configuration or filtering.
The Browser Extension
• Housed in the “extension/src” directory.
• Provides the frontend integration by interacting with online platforms (e.g., Gmail and other websites) to prevent scams. The extension’s code includes HTML, CSS, and JavaScript files such as various popups (e.g., aipopup.html, downloadpopup.html, popup.html, settings.html, warning.html) and their associated scripts.
• The manifest.json file indicates it’s structured as a typical browser extension.
• This module captures user interactions and communicates with the API component to fetch predictions or validate content.
a. Main Components:
• Browser Extension:
– Sub-components: Content scripts (content.js), background scripts (background.js), and multiple UI popups (e.g., aipopup.html, downloadpopup.html) along with their JavaScript and CSS files.
• API Server:
– The “app.py” script forms the central controller that handles requests.
– Supporting files for prediction and model integration (model.py, predict.py, test.html, domains.txt).
• AI Model/Engine:
– Training and inference modules (train_model.py, predict.py, model.py) along with data input files (data.xlsx, input.txt).
b. Relationships and Interactions:
• The Browser Extension acts as the client-side interface. It sends requests (e.g., to check content for scam detection) to the API Server.
• The API Server, upon receiving requests from the extension, uses the AI model’s prediction functionality to process the inputs.
• The AI Module (either called directly by the API or indirectly refreshed via a pre-trained model) processes the data and returns results to the API, which then communicates back to the Browser Extension.
• Configuration or static data (domains.txt, input.txt) as supplementary resources that feed into the behavior of the API/AI components.
c. Important Architectural Patterns:
• Separation of Concerns: Each module is self-contained—training/prediction is isolated from API exposure and from the user interaction layer provided by the extension.
• Service Orientation: The API layer abstracts the complexity of the AI module, exposing standardized endpoints to the extension.
• Modularity and Reusability: Both “ai” and “api” have similar scripts for prediction, suggesting versioning or adaptation of the core AI logic for production use.
• Client-Server Interaction: The extension (client) communicates with the API (server) to access AI-driven services in real time.
d. Relevant Technologies and Detail Their Roles:
• AI/ML Libraries and Data Handling (implied within Python scripts in the “ai” folder).
• Web Service Framework (likely in “api/app.py”) to manage HTTP requests.
• Browser extension frameworks, with the manifest.json hinting at Chrome/Firefox extension APIs.
• HTML/CSS/JavaScript for the extension’s user interface, along with JQuery (jquery.js) for DOM manipulation.
• Separation between the frontend (browser extension) and the backend (API and AI Modules).
• Data flow:
– User interactions trigger events in the Browser Extension.
– These events result in API calls reaching the API Server.
– The API Server routes the request to the AI Module for scam detection.
– The output (prediction result) is passed back up the chain, ultimately informing the user via the extension.
f. Instructing the Principal Software Engineer:
– Label one block “Browser Extension” with sub-components such as popup, background, and content scripts.
– Label another block “API Server” where app.py is the centerpiece.
– Label another block “AI Module” capturing training, prediction, and data management.
– From “Browser Extension” -> “API Server” for sending user requests.
– From “API Server” -> “AI Module” for invoking predictions.
– And then back from “AI Module” -> “API Server” -> “Browser Extension” for results.
• Static and external resources (e.g., data.xlsx, input.txt, and domains.txt) next to their corresponding modules.