# 0x6rss/matkap architecture

> Architecture diagram of the GitHub repository 0x6rss/matkap, 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/0x6rss/matkap
- Repository: https://github.com/0x6rss/matkap

## Overview

##### Main Components
- Configuration/Environment Module:
– Represent the .env file (illustrated by .env-example) which contains API credentials (Telegram, FOFA, URLScan).
- Core Application:
– Matkap’s entry point (matkap.py) which handles user input, Telegram session management (authentication via Telethon), and controls the overall workflow.
- FOFA Module:
– fofa_api.py, which encapsulates the logic to search for exposed Bot Tokens or Chat IDs on websites indexed by FOFA.
- URLScan Module:
– urlscan_api.py, which handles similar scanning capabilities using the URLScan service.
- External APIs and Services:
– Telegram Bot API / Telethon: The channel by which Matkap communicates with Telegram.
– FOFA and URLScan external web services: Shown as distinct external components.
- Logging & Data Export Component:
– Although not a separately defined file, the README mentions “export logs” and saving captured messages to a “captured_messages” directory. This should be depicted as a module/functional block handling data logging and storage.

##### Relationships and Data Flow
- Configuration is loaded first (from the .env file) and passed into the main application.
- Once authenticated, the main application initiates message capture and forwarding operations.
- The data flow should display that alerts or hunt results from the scanning modules flow back into the process log, and handled messages are exported to file storage.

##### Architectural Patterns and Design Principles
- Modularity: Emphasize the separation between the core application and the API integration modules (FOFA and URLScan).
- Loose Coupling: Each module (Telegram interaction, FOFA API, URLScan API, logging/exporting) is designed to work independently, making it easier to update one without impacting the others.
- Dependency Injection: The use of configuration parameters (from the .env file) injected into modules.

##### And Label Technologies, Frameworks, or Libraries
- Python (main programming language)
- Telethon (for Telegram Bot API interaction)
- Requests (likely for calling FOFA and URLScan APIs, as hinted by the presence of separate API modules)
- Environment configuration handling (.env file)

##### Essential Elements
- Use clear labels for each module/component (e.g., “Telegram Integration (Telethon)”, “FOFA API Module”, “URLScan API Module”, “Configuration Loader”, “Logging & Export Module”).
- From Configuration to Core Application.
- Between the Core Application and each external API module.
- From external APIs back to the Core Application’s logging or process log.
- Outward to external services (e.g., Telegram, FOFA, URLScan).
- Internal logic (e.g., main script, configuration, logging/export)
- External services (e.g., Telegram Bot API, FOFA, URLScan)
- Adding annotations for key design principles (modularity, dependency injection) alongside each module.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Internal Modules
    subgraph "Internal Modules"
        Config("Configuration Loader (.env)"):::internal
        Core("Matkap Core Application (matkap.py)"):::core
        Telegram("Telegram Integration (Telethon)"):::internal
        FOFA("FOFA API Module (fofa_api.py)"):::internal
        URLScan("URLScan API Module (urlscan_api.py)"):::internal
        Logging("Logging & Export Module"):::internal
    end

    %% External Services
    subgraph "External Services"
        TelegramAPI("Telegram API"):::external
        FOFAExternal("FOFA External Service"):::external
        URLScanExternal("URLScan External Service"):::external
    end

    %% Data Flow Connections
    Config -->|"config_injected"| Core

    Core -->|"init_auth"| Telegram
    Telegram <-->|"auth_exchange"| TelegramAPI

    Core -->|"trigger_hunt"| FOFA
    FOFA -->|"send_query"| FOFAExternal
    FOFAExternal -->|"return_results"| FOFA

    Core -->|"trigger_hunt"| URLScan
    URLScan -->|"send_query"| URLScanExternal
    URLScanExternal -->|"return_results"| URLScan

    Core -->|"captured_messages"| Logging
    FOFA -->|"hunt_results"| Logging
    URLScan -->|"hunt_results"| Logging

    %% Styles
    classDef internal fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef core fill:#87cefa,stroke:#000,stroke-width:2px;
    classDef external fill:#ffcccb,stroke:#000,stroke-width:1px;

    %% Click Events
    click Config "https://github.com/0x6rss/matkap/blob/main/.env-example"
    click Core "https://github.com/0x6rss/matkap/blob/main/matkap.py"
    click FOFA "https://github.com/0x6rss/matkap/blob/main/fofa_api.py"
    click URLScan "https://github.com/0x6rss/matkap/blob/main/urlscan_api.py"
```
