# megadose/toutatis architecture

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

- Interactive diagram: https://gitdiagram.com/megadose/toutatis
- Repository: https://github.com/megadose/toutatis

## Overview

##### Project type and purpose
- Project type: A Python-based command-line scraping tool (CLI application)
- Purpose: Given an Instagram username or ID and a valid session ID, extract public profile information (emails, phone numbers, follower counts, bio, etc.)

##### File structure
- setup.py – packaging script for PyPI/GitHub installation
- toutatis/ – root package
– __init__.py – initialization
– core.py – core logic and classes that perform HTTP requests, data parsing, and formatting

##### Key insights from the README
- The tool exposes two CLI commands (–u and –i) to trigger the same underlying logic
- Requires Python 3 and a valid session cookie from a logged-in Instagram session
- Outputs results to standard output in a formatted block

##### Main components
a. CLI Interface
– Argument parser (click, argparse, or custom)
– Commands “–u” and “–i” mapped to core functions
b. Core Engine (toutatis/core.py)
– Session Manager: accepts sessionID and attaches it to HTTP headers/cookies
– Request Layer: performs GET calls to Instagram endpoints (profile JSON or HTML)
– Data Parser: extracts fields (name, followers, email, phone, etc.) from response
– Formatter/Printer: formats the extracted fields into text output
c. External Service
– Instagram public API or web endpoints
d. Packaging & Deployment
– setup.py defines entry_point for CLI command “toutatis”

##### Relationships and interactions
- User invokes CLI → Argument Parser
- Parser calls Session Manager + Request Layer
- Request Layer interacts with Instagram over HTTPS
- Response flows into Data Parser → Formatter → STDOUT

##### Architectural patterns and design principles
- Separation of concerns – CLI parsing vs HTTP requests vs parsing vs formatting
- Single responsibility – each class or function in core.py handles one step
- Extensibility point – add new parsers or output formats without touching CLI logic

##### Elements
- Clear component labels: “CLI Parser”, “Session Manager”, “Request Layer”, “Data Parser”, “Formatter”
- Annotations for protocols (HTTPS) and data formats (JSON/HTML/text)

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Input
    User(("User")):::external

    %% Root Package Initialization
    subgraph "Root Package"
        Init["Root Package Init (__init__.py)"]:::internal
    end

    %% Packaging & Deployment
    Setup["Packaging & Deployment (entry point 'toutatis')"]:::package

    %% CLI Interface
    subgraph "CLI Interface"
        CLI["CLI Parser"]:::internal
    end

    %% Core Engine
    subgraph "Core Engine"
        Session["Session Manager"]:::internal
        Request["Request Layer"]:::internal
        Parser["Data Parser"]:::internal
        Formatter["Formatter/Printer"]:::internal
    end

    %% External Service
    Instagram["Instagram Endpoints"]:::external

    %% Output
    Output(("STDOUT")):::package

    %% Flow
    User --> CLI
    Setup --> CLI
    CLI --> Session
    Session --> Request
    Request -->|HTTPS| Instagram
    Instagram -->|JSON/HTML| Parser
    Parser --> Formatter
    Formatter --> Output

    %% Click Events
    click CLI "https://github.com/megadose/toutatis/blob/master/toutatis/core.py"
    click Session "https://github.com/megadose/toutatis/blob/master/toutatis/core.py"
    click Request "https://github.com/megadose/toutatis/blob/master/toutatis/core.py"
    click Parser "https://github.com/megadose/toutatis/blob/master/toutatis/core.py"
    click Formatter "https://github.com/megadose/toutatis/blob/master/toutatis/core.py"
    click Setup "https://github.com/megadose/toutatis/blob/master/setup.py"
    click Init "https://github.com/megadose/toutatis/blob/master/toutatis/__init__.py"

    %% Styles
    classDef internal fill:#cce5ff,stroke:#2b6cb0,color:#2b6cb0;
    classDef external fill:#d4edda,stroke:#276749,color:#276749;
    classDef package fill:#e2e3e5,stroke:#4a5568,color:#4a5568;
```
