# queens-qmulus/qu-scrapers architecture

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

- Interactive diagram: https://gitdiagram.com/queens-qmulus/qu-scrapers
- Repository: https://github.com/queens-qmulus/qu-scrapers

## Overview

##### Project Type and Purpose
- The project is a specialized scraping library and command-line tool designed to harvest data from a variety of web resources at Queen’s University.
- From the README, it is clear that the goal is to provide multiple independent scraper modules (buildings, courses, news, textbooks) that can be invoked individually or collectively via the “run_scraper.py” module.
- It’s integrated with CI/CD (visualized by GitHub Actions) and follows a modular design to aid maintainability and extensibility.

##### File Structure
- Top-level files (e.g., Pipfile, README.md, run_scraper.py, tests.py) indicate standard Python project setup with environment management and testing.
- The “quartzscrapers” package contains an __init__.py and a logging configuration file (logging.yaml), plus a logs folder to persist logs.
- The “scrapers” subpackage is organized into domain-specific directories (buildings, courses, news, textbooks, and a test_scraper) where each directory contains its own __init__.py, main logic file, helper file, and in some cases its own README.
- The “scrapers/utils” folder hosts shared utilities (e.g., config and a generic scraper method) that likely play a central role across the different scrapers.

##### Key Components to Capture
a. Application Entry Points:
- Run Command: “run_scraper.py” serves as the command-line entry point to trigger multiple scraping tasks.
- Library Use: Application code can also import the “quartzscrapers” package to directly trigger individual scrapers (via classes like Textbooks, Buildings, etc.).
b. Core Scraper Modules:
- Separate modules for each scraping domain:
- Buildings Scraper (in quartzscrapers/scrapers/buildings)
- Courses Scraper (in quartzscrapers/scrapers/courses)
- News Scraper (in quartzscrapers/scrapers/news)
- Textbooks Scraper (in quartzscrapers/scrapers/textbooks)
- Each module may have both a main scraping class/function and helper functions.
c. Shared Utilities and Configuration:
- “quartzscrapers/scrapers/utils”: Centralized configuration logic and a generic scraper routine that provides a common interface or shared functionality across scrapers.
- Environment configuration: Usage of .env (populated via environment variables like GITHUB_TOKEN, GOOGLE_MAPS_KEY, etc.) for external API keys and credentials.
d. Logging:
- Centralized logging configuration given in “quartzscrapers/logging.yaml”, with actual log outputs directed to the “quartzscrapers/logs” folder.
e. Testing & CI/CD:
- “tests.py” for the testing suite.
- GitHub workflows under .github/workflows indicating automated test and build processes.

##### Relationships and Interactions
- The “run_scraper.py” module interacts with the individual scraper modules by invoking their scrape() functions, optionally passing configuration arguments (like location paths).
- The scrapers themselves use the shared utility functions (from “scrapers/utils”) to apply common configuration settings, environment variable handling, and other preprocessing tasks.
- All components use logging as a cross-cutting feature for monitoring, thus a logging component is linked to every scrapper component.

##### Architectural Patterns & Design Principles
- Modularity: Each scraper is a self-contained module with its own README and helper functions, making it easy to extend or modify in isolation.
- Separation of Concerns: There is a clear separation between configuration (utils/config.py), logging (logging.yaml), scraper logic (within each scraper folder), and orchestration (run_scraper.py).
- Reusability: The utility module encourages code reuse for common scraping tasks across the different projects.
- Command Design: The existence of a CLI entry point (run_scraper.py) indicates a command design pattern where different commands (scraper invocations) can be executed.

## Diagram (Mermaid)

```mermaid
graph TD
    A["run_scraper.py (Executor/CLI)"]:::cli
    B["Buildings Scraper"]:::scraper
    C["Courses Scraper"]:::scraper
    D["News Scraper"]:::scraper
    E["Textbooks Scraper"]:::scraper
    U["Utilities & Config"]:::utility
    L["Logging"]:::logging
    X["External Services"]:::external

    subgraph "Quality Assurance"
        T["tests.py"]:::qa
        G["GitHub Actions"]:::qa
    end

    A -->|"triggers"| B
    A -->|"triggers"| C
    A -->|"triggers"| D
    A -->|"triggers"| E

    B -->|"uses"| U
    C -->|"uses"| U
    D -->|"uses"| U
    E -->|"uses"| U

    B -->|"logs"| L
    C -->|"logs"| L
    D -->|"logs"| L
    E -->|"logs"| L

    B -->|"scrapes"| X
    C -->|"scrapes"| X
    D -->|"scrapes"| X
    E -->|"scrapes"| X

    A -->|"validatedBy"| T
    A -->|"validatedBy"| G

    classDef cli fill:#fde2e4,stroke:#d9534f,stroke-width:2px;
    classDef scraper fill:#cce5ff,stroke:#337ab7,stroke-width:2px;
    classDef utility fill:#d5f5e3,stroke:#5cb85c,stroke-width:2px;
    classDef logging fill:#fff3cd,stroke:#f0ad4e,stroke-width:2px;
    classDef external fill:#d1c4e9,stroke:#8e44ad,stroke-width:2px;
    classDef qa fill:#f9e79f,stroke:#f1c40f,stroke-width:2px;

    click A "https://github.com/queens-qmulus/qu-scrapers/blob/develop/run_scraper.py"
    click B "https://github.com/queens-qmulus/qu-scrapers/tree/develop/quartzscrapers/scrapers/buildings"
    click C "https://github.com/queens-qmulus/qu-scrapers/tree/develop/quartzscrapers/scrapers/courses"
    click D "https://github.com/queens-qmulus/qu-scrapers/tree/develop/quartzscrapers/scrapers/news"
    click E "https://github.com/queens-qmulus/qu-scrapers/tree/develop/quartzscrapers/scrapers/textbooks"
    click U "https://github.com/queens-qmulus/qu-scrapers/tree/develop/quartzscrapers/scrapers/utils"
    click L "https://github.com/queens-qmulus/qu-scrapers/blob/develop/quartzscrapers/logging.yaml"
    click T "https://github.com/queens-qmulus/qu-scrapers/blob/develop/tests.py"
    click G "https://github.com/queens-qmulus/qu-scrapers/tree/develop/.github/workflows"
```
