# swagatade/custom-ai architecture

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

- Interactive diagram: https://gitdiagram.com/swagatade/custom-ai
- Repository: https://github.com/swagatade/custom-ai

## Overview

##### Main Components
- User Interface/Client: Represent the frontend component delivered via Streamlit, which includes interactive elements like a sidebar for API key input, query submission, file uploads (for PDFs or images), and display areas for results.
- Application Core: Show the main application logic that resides in main.py (documented as app.py in the README). This core handles routing user actions, interfacing with the appropriate libraries (e.g., PyPDF2 for PDF summarization, Pillow for image processing), and managing overall app state.
- External API Integrations: Identify external services that the app uses:
- Weather API (for current and location-based weather information).
- OpenRouter API (for general query and AI model interactions).
- DuckDuckGo Search (for web search capabilities).
- AI-based image generation services.
- Local Temporary Storage: Although minimal, include the temp_data/ folder (mentioned in the README) which handles temporary files from user uploads and process outputs.
- Security/Configuration: Include configuration elements (like API key management) that are controlled via the Streamlit sidebar and environmental variables. Note also the existence of configuration files like .devcontainer for workspace setup.

##### Relationships and Interactions
- The User interacts with the Streamlit frontend, triggering events that are captured by the Application Core.
- The Application Core directs each request to the corresponding component or external API. For instance:
- For PDF summarization, the uploaded file is processed using PyPDF2, then summarized and returned to the UI.
- For weather inquiries, the application makes a call to the Weather API and displays the fetched data.
- For query processing and image generation, the system sends requests to external AI services.

##### Architectural Patterns and Technologies
- Modular Design: Even if the application currently consists of a single main file, conceptually break the functionalities into modules. Each module (e.g., PDF processing, weather data retrieval, image processing, etc.) acts as an independent component that communicates with the central controller.
- Streamlit Framework: Highlight Streamlit as the core framework enabling rapid app development and user interface rendering.
- External Libraries: Mention PyPDF2, Pillow, Requests, and DuckDuckGo Search as significant libraries that underpin various features.

##### Detail the System’s Architecture
- That all dependencies are managed via the provided requirements.txt file, which underlines that installations and environment configurations are key to launching this application.

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Layer"
        UI("User Interface (Streamlit Frontend)"):::ui
    end

    subgraph "Application Layer"
        AC("Application Core (main.py)"):::core
        PDF("PDF Processing Module (PyPDF2)"):::module
        IMG("Image Processing Module (Pillow)"):::module
        WEATHER("Weather API Integration"):::module
        QUERY("Query and AI Interaction Module (OpenRouter API)"):::module
        SEARCH("Web Search Integration (DuckDuckGo)"):::module
        LIB("External API Dependencies & Library Management"):::config
        TEMP("Temporary Data Storage (temp_data)"):::storage
        SEC("Security/Configuration"):::config
    end

    subgraph "External Services Layer"
        EXT_WEATHER("Weather API"):::external
        EXT_ROUTER("OpenRouter API"):::external
        EXT_SEARCH("DuckDuckGo Search"):::external
        EXT_IMG("AI-based Image Generation Service"):::external
    end

    UI -->|"submitActions"| AC

    AC -->|"pdfProcess"| PDF
    AC -->|"imgProcess"| IMG
    AC -->|"weatherCall"| WEATHER
    AC -->|"queryCall"| QUERY
    AC -->|"webSearch"| SEARCH
    AC -->|"storeFiles"| TEMP
    AC -->|"configSetup"| SEC
    AC -->|"loadDependencies"| LIB

    WEATHER -->|"calls"| EXT_WEATHER
    QUERY -->|"calls"| EXT_ROUTER
    SEARCH -->|"calls"| EXT_SEARCH
    IMG -->|"calls"| EXT_IMG

    classDef ui fill:#ffcccc,stroke:#333,stroke-width:2px;
    classDef core fill:#ccffcc,stroke:#333,stroke-width:2px;
    classDef module fill:#ccccff,stroke:#333,stroke-width:2px;
    classDef storage fill:#ffffcc,stroke:#333,stroke-width:2px;
    classDef config fill:#ffccff,stroke:#333,stroke-width:2px;
    classDef external fill:#d9d9d9,stroke:#333,stroke-width:2px;

    click UI "https://github.com/swagatade/custom-ai/blob/main/main.py"
    click AC "https://github.com/swagatade/custom-ai/blob/main/main.py"
    click PDF "https://github.com/swagatade/custom-ai/blob/main/main.py"
    click IMG "https://github.com/swagatade/custom-ai/blob/main/main.py"
    click WEATHER "https://github.com/swagatade/custom-ai/blob/main/main.py"
    click QUERY "https://github.com/swagatade/custom-ai/blob/main/main.py"
    click SEARCH "https://github.com/swagatade/custom-ai/blob/main/main.py"
    click LIB "https://github.com/swagatade/custom-ai/blob/main/requirements.txt"
    click SEC "https://github.com/swagatade/custom-ai/blob/main/.devcontainer/devcontainer.json"
```
