# dhairyagoel05/aiticketgenerator architecture

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

- Interactive diagram: https://gitdiagram.com/dhairyagoel05/aiticketgenerator
- Repository: https://github.com/dhairyagoel05/aiticketgenerator

## Overview

##### Project Type and Purpose
- This is a full-stack, Python-based customer support ticket management application with a Streamlit UI (“main.py”/“app.py”), AI-powered backend services, and integrations with external APIs (Gmail, Google Sheets).

##### Core Components (to include as distinct blocks)
a. Frontend (Streamlit)
- register_ticket.py: Ticket submission form
- main.py: Dashboard showing incoming tickets and AI responses
b. Business Logic / AI Services (tools/)
- classify_ticket.py: AI classification of ticket type
- generate_reply.py: AI-generated response content
- (Optionally) testeuri.py: Test harness or utility scripts
c. Integration Layer
- gmail_sender.py: Gmail API wrapper for sending emails
- sheet_connector.py: Google Sheets API wrapper for logging/tracking tickets
d. Configuration
- .env: Environment variables (GMAIL_USERNAME, GMAIL_PASSWORD, SPREADSHEET_ID)
- requirements.txt: Python dependencies (Streamlit, google-api-python-client, OpenAI/other AI SDK)

##### Data Flows and Interactions
- User → Streamlit Frontend (register_ticket.py)
- Submits form → Form data passed to business logic
- Business Logic →
- classify_ticket.py → returns category + sentiment
- generate_reply.py → returns reply text
- Logging → sheet_connector.py → writes ticket + classification + reply to Google Sheet
- Outbound Email → gmail_sender.py → sends AI reply to user’s email
- Monitoring → main.py dashboard pulls from Google Sheets (via sheet_connector.py) to display ticket queue, statuses, and responses

##### Architectural Patterns & Design Principles
- Separation of concerns: UI, AI processing, and external integrations are modular
- Single-responsibility modules: each script in tools/ focuses on one integration or AI task
- External service adapters: wrap Gmail and Sheets APIs behind simple function calls
- Environment abstraction: .env file keeps secrets/config out of code

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User
    User(("User")):::user

    %% Configuration
    ENV[".env"]:::config
    REQ["requirements.txt"]:::config

    %% Frontend Layer
    subgraph "Frontend (Streamlit)"
        RT["Register Ticket (register_ticket.py)"]:::frontend
        MD["Dashboard (main.py)"]:::frontend
    end

    %% AI Engine
    subgraph "AI Engine"
        CT["Ticket Classifier (classify_ticket.py)"]:::ai
        GR["Reply Generator (generate_reply.py)"]:::ai
        TU["Test Utilities (testeuri.py)"]:::utility
    end

    %% Integration Layer
    subgraph "Integration Layer"
        SC["Sheet Connector (sheet_connector.py)"]:::integration
        GS["Gmail Sender (gmail_sender.py)"]:::integration
    end

    %% External Services & Data Store
    DB[("Google Sheets")]:::database
    GAPI[(Gmail API)]:::external
    SAPI[(Google Sheets API)]:::external

    %% Flows
    User -->|submits ticket| RT
    RT -->|ticket payload| CT
    CT -->|classification + sentiment| GR
    GR -->|reply text| GS
    GR -->|reply + classification| SC
    SC -->|writes to sheet| DB
    GS -->|send email| GAPI
    MD -->|fetch tickets| SC
    SC -->|reads tickets| DB

    %% Config dependencies
    ENV --> CT
    ENV --> GR
    ENV --> SC
    ENV --> GS

    REQ --> RT
    REQ --> MD
    REQ --> CT
    REQ --> GR
    REQ --> SC
    REQ --> GS

    %% Click Events
    click RT "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/register_ticket.py"
    click MD "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/main.py"
    click CT "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/tools/classify_ticket.py"
    click GR "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/tools/generate_reply.py"
    click TU "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/testeuri.py"
    click GS "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/tools/gmail_sender.py"
    click SC "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/tools/sheet_connector.py"
    click ENV "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/.env"
    click REQ "https://github.com/dhairyagoel05/aiticketgenerator/blob/main/requirements.txt"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,color:#000
    classDef ai fill:#e8f5e9,stroke:#2e7d32,color:#000
    classDef integration fill:#fff3e0,stroke:#ef6c00,color:#000
    classDef database fill:#fce4ec,stroke:#c2185b,color:#000
    classDef external fill:#ede7f6,stroke:#5e35b1,color:#000
    classDef config fill:#eeeeee,stroke:#757575,color:#000
    classDef user fill:#ffffff,stroke:#000000,color:#000
    classDef utility fill:#f3e5f5,stroke:#8e24aa,color:#000
```
