# chinoogawa/fbht architecture

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

- Interactive diagram: https://gitdiagram.com/chinoogawa/fbht
- Repository: https://github.com/chinoogawa/fbht

## Overview

##### Project type and purpose
- Type: A command-line, Python-based data-collection and graph-analysis tool
- Purpose: Automate Facebook data extraction (via Selenium/Mechanize), parse and store it, then compute and render social graphs using NetworkX/Matplotlib/Pygraphviz, finally dumping results as DOT/PDF/HTML.

##### File structure
- Top-level scripts (main.py, mainFunc.py, mainLib.py): orchestrate workflows
- Modules:
– MyParser.py – raw HTML/text parsing
– community.py – community-detection routines
– database.py – sqlite access (fb_db.db)
– handlers.py – low-level HTTP/form handlers (Mechanize)
- Data & dumps:
– fb_db.db – SQLite storage
– dumps/… – DOT, PDF, HTML graph artifacts
– massive/, cellphones/, PRIVATE/ – sample data sets
- Config/deps: setup.py, dependencias.txt
- Logging: logs/error.log

##### Key external dependencies (from README)
- Selenium (drives browser emulation)
- Mechanize (HTTP form automation)
- NetworkX, Pygraphviz, Matplotlib, Numpy, Simplejson
- Gephi (post-processing graphs)

##### Main components and interactions
a. User/CLI Layer
- main.py – parses CLI args, triggers workflows in mainFunc.py
b. Scraping Layer
- handlers.py + Selenium/Mechanize
- Invokes browser sessions, fetches pages
c. Parsing Layer
- MyParser.py – extracts user nodes, edges, metadata
d. Storage Layer
- database.py – writes/reads SQLite (fb_db.db)
e. Analysis Layer
- community.py – runs community detection algorithms on stored graph data
f. Visualization Layer
- mainLib.py + NetworkX/Matplotlib/Pygraphviz – builds and exports graph visualizations (DOT → PDF/PNG)
- Optional: Gephi import for interactive exploration
g. Output Layer
- dumps/… – file sinks for graphs, references, logs
- massive/, cellphones/, PRIVATE/ as data input or example repositories
h. Logging & Config
- logs/error.log – captures runtime errors
- setup.py/dependencias.txt – defines environment and dependencies

##### Architectural patterns & principles
- Modular layering: clear separation of scraping, parsing, storage, analysis, visualization
- Single responsibility per module (e.g., community.py only cares about graph algorithms)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    FB["Facebook"]:::external
    Gephi["Gephi"]:::external

    %% User/CLI Layer
    subgraph "User/CLI Layer"
        Main["main.py"]:::python
        MainFunc["mainFunc.py"]:::python
    end

    %% Scraping Layer
    subgraph "Scraping Layer"
        Handlers["handlers.py"]:::python
    end

    %% Parsing Layer
    subgraph "Parsing Layer"
        Parser["MyParser.py"]:::python
    end

    %% Storage Layer
    subgraph "Storage Layer"
        Database["SQLite DB (fb_db.db)"]:::db
    end

    %% Analysis Layer
    subgraph "Analysis Layer"
        Community["community.py"]:::python
    end

    %% Visualization Layer
    subgraph "Visualization Layer"
        Visualizer["mainLib.py"]:::python
    end

    %% Output Layer
    subgraph "Output Layer"
        Dumps["dumps/"]:::fileIO
        Samples["massive/, cellphones/, PRIVATE/"]:::fileIO
        Logs["logs/error.log"]:::fileIO
    end

    %% Config & Dependencies
    subgraph "Configuration & Dependencies"
        Setup["setup.py"]:::fileIO
        Deps["dependencias.txt"]:::fileIO
    end

    %% Data Flow
    FB -->|HTML pages| Handlers
    Main -->|"CLI args"| Handlers
    Handlers -->|"raw HTML"| Parser
    Samples -->|sample data| Parser
    Parser -->|"parsed JSON"| Database
    Database -->|"graph data"| Community
    Community -->|"NetworkX graph"| Visualizer
    Visualizer -->|"DOT/PDF/PNG"| Dumps
    Visualizer -->|"export graph"| Gephi
    Parser -->|"raw dumps only"| Dumps

    %% Error Handling
    Main -.->|errors| Logs
    MainFunc -.->|errors| Logs
    Handlers -.->|errors| Logs
    Parser -.->|errors| Logs
    Database -.->|errors| Logs
    Community -.->|errors| Logs
    Visualizer -.->|errors| Logs

    %% Config Dependencies Arrows
    Setup --> Main
    Setup --> Handlers
    Setup --> Parser
    Setup --> Database
    Setup --> Community
    Setup --> Visualizer
    Deps --> Main
    Deps --> Handlers
    Deps --> Parser
    Deps --> Database
    Deps --> Community
    Deps --> Visualizer

    %% Click Events
    click Main "https://github.com/chinoogawa/fbht/blob/master/main.py"
    click MainFunc "https://github.com/chinoogawa/fbht/blob/master/mainFunc.py"
    click Handlers "https://github.com/chinoogawa/fbht/blob/master/handlers.py"
    click Parser "https://github.com/chinoogawa/fbht/blob/master/MyParser.py"
    click Database "https://github.com/chinoogawa/fbht/blob/master/database.py"
    click Community "https://github.com/chinoogawa/fbht/blob/master/community.py"
    click Visualizer "https://github.com/chinoogawa/fbht/blob/master/mainLib.py"
    click Dumps "https://github.com/chinoogawa/fbht/tree/master/dumps/"
    click Samples "https://github.com/chinoogawa/fbht/tree/master/massive/"
    click Logs "https://github.com/chinoogawa/fbht/blob/master/logs/error.log"
    click Setup "https://github.com/chinoogawa/fbht/blob/master/setup.py"
    click Deps "https://github.com/chinoogawa/fbht/blob/master/dependencias.txt"

    %% Styles
    classDef python fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef db fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef fileIO fill:#ffe6cc,stroke:#333,stroke-width:1px
    classDef external fill:#e6e6e6,stroke:#333,stroke-width:1px
```
