# pcaglar/chegg-unlocker architecture

> Architecture diagram of the GitHub repository pcaglar/chegg-unlocker, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pcaglar/chegg-unlocker
- Repository: https://github.com/pcaglar/chegg-unlocker

## Overview

##### Project Type and Purpose
- This is a full-stack web application built with Node.js. Its primary function is to scrape Chegg textbook answers and present them via a web UI, using EJS templates for the front-end.
- A key feature is the integration of an automatic AI captcha solver, which is implemented as a separate module (captchaSolver.js).

##### File Structure
- Top-level files:
– server.js: The entry point for the Node.js backend which likely handles routing, scraping, and rendering views.
– captchaSolver.js: Contains the logic for solving captchas, a crucial element given the scraping needs.
– package.json & package-lock.json: Define dependencies and project configurations.
– filler.json: Likely serves as a configuration or placeholder file, which might be used during scraping or data management.
– README.md and Screenshots: Provide visual cues and documentation.
- Views Folder:
– Contains EJS templates (login.ejs, unlocker.ejs, imageView.ejs) used to render the UI.
– assets (including style.css): Provides supporting front-end resources.

- Main Components to Include:
- Web UI (Frontend)
- EJS templates (login, unlocker, imageView)
- Static assets (CSS, images) for styling and presentation.
- Node.js Backend (server.js)
- Central server handling HTTP requests/responses.
- Acts as the controller in an MVC-like structure, managing business logic.
- Captcha Solver Module (captchaSolver.js)
- Integrated as a service/module within the backend to automatically solve captchas during scraping.
- (Optional) Configuration/Supporting Data
- filler.json can be depicted as a configuration file feeding data to the application.

- Relationships and Interactions:
- The user interacts with the Web UI (rendered via EJS templates).
- Web UI sends requests (login, unlock, view requests) to the Node.js backend.
- The server processes these requests, which includes:
- Initiating scraping of Chegg content.
- When encountering a captcha challenge, delegating to the captcha solver module to resolve it.
- Once data is retrieved and processed, the server renders the appropriate views back to the user.
- Data Flow:
- Start from the user’s browser accessing the login or unlocker pages.
- Architectural Patterns:
- MVC-like pattern where views (EJS templates), controllers/server (server.js), and service modules (captchaSolver.js) work in concert.
- Separation of concerns: distinct modules for UI rendering, backend processing, and captcha handling.

##### Final Assembly
– Browser → Web UI (Rendered via EJS in the views folder)
– Web UI → Backend (server.js) to process the request.
– Within the backend, branch out to the Captcha Solver (captchaSolver.js) when a captcha challenge is encountered.
– Indicate the processing flow back from the Captcha Solver to the backend and finally to the Web UI for rendering the results.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes outside subgraphs
    Browser("User Browser"):::browser

    %% Frontend Subgraph 
    subgraph "Web UI (Frontend)"
        direction TB
        L("Login (login.ejs)"):::frontend
        U("Unlocker (unlocker.ejs)"):::frontend
        I("ImageViewer (imageView.ejs)"):::frontend
        Aset("Static Assets (views/assets)"):::frontend
    end

    %% Backend Subgraph
    subgraph "Backend"
        direction TB
        S("Server (server.js)"):::backend
        C("Captcha Solver (captchaSolver.js)"):::module
        F("Configuration (filler.json)"):::config
    end

    %% Data Flow
    Browser -->|"HTTP-request"| L
    Browser -->|"HTTP-request"| U
    Browser -->|"HTTP-request"| I
    
    L -->|"submit"| S
    U -->|"submit"| S
    I -->|"request"| S

    S -->|"captcha-challenge"| C
    C -->|"solved-captcha"| S

    S -->|"load-config"| F
    S -->|"render-view"| L
    S -->|"render-view"| U
    S -->|"render-view"| I

    %% Click Events
    click L "https://github.com/pcaglar/chegg-unlocker/blob/main/views/login.ejs"
    click U "https://github.com/pcaglar/chegg-unlocker/blob/main/views/unlocker.ejs"
    click I "https://github.com/pcaglar/chegg-unlocker/blob/main/views/imageView.ejs"
    click Aset "https://github.com/pcaglar/chegg-unlocker/tree/main/views/assets"
    click S "https://github.com/pcaglar/chegg-unlocker/blob/main/server.js"
    click C "https://github.com/pcaglar/chegg-unlocker/blob/main/captchaSolver.js"
    click F "https://github.com/pcaglar/chegg-unlocker/blob/main/filler.json"

    %% Styles
    classDef browser fill:#f9e79f,stroke:#7d6608,stroke-width:2px;
    classDef frontend fill:#aed6f1,stroke:#1f618d,stroke-width:2px;
    classDef backend fill:#a9dfbf,stroke:#145a32,stroke-width:2px;
    classDef module fill:#f9c74f,stroke:#d35400,stroke-width:2px;
    classDef config fill:#f5b7b1,stroke:#922b21,stroke-width:2px;
```
