# xdevplatform/search-tweets-python architecture

> Architecture diagram of the GitHub repository xdevplatform/search-tweets-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xdevplatform/search-tweets-python
- Repository: https://github.com/xdevplatform/search-tweets-python

## Overview

##### Project Type and Core Components
This is a Python library that serves as a wrapper for Twitter's premium and enterprise search APIs. The main components should be organized as follows:

##### Main Architectural Components

a. Core Components:
- Authentication Handler (credentials.py)
- API Request Manager (api_utils.py)
- Result Stream Processor (result_stream.py)
- Utility Functions (utils.py)

b. External Interfaces:
- Twitter Premium API
- Twitter Enterprise API
- Search Endpoints (30-day and Full Archive)
- Counts Endpoint

##### Client Layer (Top)
- Command Line Interface (tools/search_tweets.py)
- Python Library Interface

##### Authentication Layer
- Credential Manager
- Two paths: Premium and Enterprise auth

##### Core Processing Layer
- ResultStream Processor
- Rule Generator
- Tweet Parser Integration
- As interconnected components with clear data flow

##### API Integration Layer
- Request Handler
- Response Processor
- Rate Limiting

##### External Services Layer (Bottom)
- Twitter Premium API
- Twitter Enterprise API
- Search Endpoints
- Counts Endpoint

Use the following visual elements:

##### Connection Types
- Double lines: API boundaries

##### Authentication Flow
- Both Premium (bearer token) and Enterprise (username/password) paths
- Credential file and environment variable options

##### Data Flow
- Search request flow
- Pagination handling
- Count endpoint variations

##### Integration Points
- Tweet Parser integration
- Configuration handling
- Result streaming process

##### Error Handling
- Rate limit management
- Error response processing
- Retry mechanisms

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef core fill:#b3d1ff,stroke:#333
    classDef auth fill:#90EE90,stroke:#333
    classDef external fill:#FFA07A,stroke:#333
    classDef utility fill:#D3D3D3,stroke:#333
    classDef interface fill:#FFE4B5,stroke:#333

    %% Client Layer
    subgraph ClientLayer
        CLI["Command Line Interface"]:::interface
        PythonLib["Python Library Interface"]:::interface
        ConfigTemplates["Configuration Templates"]:::interface
        YAMLConfig["YAML Configuration"]:::interface
    end

    %% Authentication Layer
    subgraph AuthLayer
        CredManager["Credential Manager"]:::auth
        AuthHandler["Authentication Handler"]:::auth
    end

    %% Core Processing Layer
    subgraph CoreLayer
        ResultStream["Result Stream Processor"]:::core
        RuleGen["Rule Generator"]:::core
        TweetParser["Tweet Parser"]:::core
        RequestMgr["API Request Manager"]:::core
        Utils["Utility Functions"]:::utility
    end

    %% API Integration Layer
    subgraph APILayer
        ReqHandler["Request Handler"]:::core
        RespProcessor["Response Processor"]:::core
        RateLimit["Rate Limiting"]:::core
    end

    %% External Services Layer
    subgraph ExternalLayer
        TwitterPremium["Twitter Premium API"]:::external
        TwitterEnterprise["Twitter Enterprise API"]:::external
        SearchEndpoints["Search Endpoints"]:::external
        CountsEndpoint["Counts Endpoint"]:::external
    end

    %% Connections
    CLI --> CredManager
    PythonLib --> CredManager
    ConfigTemplates --> CredManager
    YAMLConfig --> CredManager
    
    CredManager --> AuthHandler
    AuthHandler --> RequestMgr
    
    RequestMgr --> ResultStream
    RequestMgr --> RuleGen
    ResultStream --> TweetParser
    Utils --> ResultStream
    
    RequestMgr --> ReqHandler
    ReqHandler --> RateLimit
    RateLimit --> RespProcessor
    
    RespProcessor --> TwitterPremium
    RespProcessor --> TwitterEnterprise
    TwitterPremium --> SearchEndpoints
    TwitterEnterprise --> SearchEndpoints
    TwitterPremium --> CountsEndpoint
    TwitterEnterprise --> CountsEndpoint

    %% Click Events
    click CLI "https://github.com/xdevplatform/search-tweets-python/blob/master/tools/search_tweets.py"
    click ConfigTemplates "https://github.com/xdevplatform/search-tweets-python/blob/master/tools/api_config_example.config"
    click YAMLConfig "https://github.com/xdevplatform/search-tweets-python/blob/master/tools/api_yaml_example.yaml"
    click AuthHandler "https://github.com/xdevplatform/search-tweets-python/blob/master/searchtweets/credentials.py"
    click RequestMgr "https://github.com/xdevplatform/search-tweets-python/blob/master/searchtweets/api_utils.py"
    click ResultStream "https://github.com/xdevplatform/search-tweets-python/blob/master/searchtweets/result_stream.py"
    click Utils "https://github.com/xdevplatform/search-tweets-python/blob/master/searchtweets/utils.py"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Authentication Components"]:::auth
        L3["External Services"]:::external
        L4["Utility Functions"]:::utility
        L5["Interfaces"]:::interface
    end
```
