# krishavrajsingh/automailer architecture

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

- Interactive diagram: https://gitdiagram.com/krishavrajsingh/automailer
- Repository: https://github.com/krishavrajsingh/automailer

## Overview

##### Main Components

a) Client Layer:
- Google OAuth Authentication endpoint
- Email handling endpoints

b) Application Layer:
- Express.js Server
- Controllers (Google Controllers)
- Services (Gemini Service, Google Service)
- Queue System (BullMQ)

c) External Services:
- Google Gmail API
- Google OAuth
- Gemini AI API
- Redis Server

##### Component Relationships

- Authentication flow with Google OAuth
- Email processing flow
- Queue management flow
- AI analysis flow

**┌─────────────────────────────────────────────────────────────┐**
- AutoMailer System                        │

- ┌─────────┐    ┌──────────┐    ┌────────────────────┐     │
- Express │────│Controllers│────│     Services       │     │
- Server │    │          │    │                    │     │
- ┘    └──────────┘    └────────────────────┘     │

- ┌──────┴───────┐         │
- Queue System │         │
- ┘         │
- ┼──────────────┼─────────────────┼──────────────────┘

- ▼              ▼                 ▼
- ┌─────────┐    ┌──────────┐    ┌──────────┐
- Google  │    │  Gemini  │    │  Redis   │
- APIs    │    │   API    │    │  Server  │
- ┘    └──────────┘    └──────────┘

##### Specific Flows

a) Authentication Flow:
**Client → Express Server → Google OAuth → Token Storage**

b) Email Processing Flow:
**Gmail API → Google Service → Email Queue → Gemini Service → Response Queue → Gmail API**

##### Important Details

- BullMQ queue system with separate queues for:
- Email processing queue
- Response generation queue
- Error handling queue

- Service layer components:
- geminiService.ts
- googleService.ts

- Controller layer:
- googleControllers.ts

##### Technical Stack Indicators

- Node.js/Express.js environment
- TypeScript implementation
- Redis for queue management
- OAuth2 authentication
- AI integration points

Remember to indicate:
- Security boundaries
- Data persistence points
- Asynchronous processing zones
- External service integration points

This will provide a complete picture of how the AutoMailer system works while maintaining clarity and usefulness for development and maintenance purposes.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        Browser["Web Browser"]
    end

    subgraph "Application Server"
        Express["Express Server"]:::server
        AuthController["Authentication Controller"]:::controller
        EmailController["Email Processing Controller"]:::controller
    end

    subgraph "Service Layer"
        GoogleService["Google Service"]:::service
        GeminiService["Gemini Service"]:::service
    end

    subgraph "Queue System"
        EmailQueue["Email Queue"]:::queue
        Redis[(Redis Server)]:::database
    end

    subgraph "External Services"
        GoogleAPI["Google OAuth/Gmail API"]:::external
        GeminiAPI["Gemini AI API"]:::external
    end

    %% Connections
    Browser --> Express
    Express --> AuthController
    Express --> EmailController
    AuthController --> GoogleService
    EmailController --> GoogleService
    GoogleService --> EmailQueue
    EmailQueue --> Redis
    EmailQueue --> GeminiService
    GoogleService --> GoogleAPI
    GeminiService --> GeminiAPI

    %% Return flows
    GoogleAPI -.-> GoogleService
    GeminiAPI -.-> GeminiService
    GeminiService -.-> EmailQueue
    EmailQueue -.-> GoogleService
    GoogleService -.-> EmailController

    %% Styles
    classDef server fill:#3498db
    classDef controller fill:#2ecc71
    classDef service fill:#e74c3c
    classDef queue fill:#f39c12
    classDef database fill:#95a5a6
    classDef external fill:#9b59b6

    %% Legend
    subgraph Legend
        L1["Application Components"]:::server
        L2["Controllers"]:::controller
        L3["Services"]:::service
        L4["Queue Components"]:::queue
        L5["Database"]:::database
        L6["External Services"]:::external
    end

    %% Click events
    click Express "https://github.com/KrishavRajSingh/Automailer/blob/main/src/app.ts"
    click AuthController "https://github.com/KrishavRajSingh/Automailer/blob/main/src/controllers/googleControllers.ts"
    click GoogleService "https://github.com/KrishavRajSingh/Automailer/blob/main/src/services/googleService.ts"
    click GeminiService "https://github.com/KrishavRajSingh/Automailer/blob/main/src/services/geminiService.ts"
    click EmailQueue "https://github.com/KrishavRajSingh/Automailer/blob/main/src/queues/emailQueue.ts"
```
