# adhi1213/my-n8n-ai-agent architecture

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

- Interactive diagram: https://gitdiagram.com/adhi1213/my-n8n-ai-agent
- Repository: https://github.com/adhi1213/my-n8n-ai-agent

## Overview

##### Project type and purpose
- This is not a traditional code repo but an n8n “no-code” workflow export.
- Purpose: automatically read incoming Gmail threads, maintain conversational memory, generate AI-driven replies via Google Gemini, and post replies back to Gmail.

##### Main components
a. n8n Orchestration Platform
- Represents the runtime where all nodes execute.
b. Gmail Trigger Node
- Listens for new messages or replies in the user’s Gmail inbox via the Gmail API.
c. Simple Memory Node
d. Google Gemini Chat Node
- Invokes the Google Gemini Chat API, passing incoming message + memory context, and receives an AI-generated response.
e. Gmail Send Node
- Uses the Gmail API to post the generated response back into the same thread.
f. External Services
- Gmail API (with OAuth2 credentials)
- Google Gemini Chat API (with API key / OAuth credentials)

##### Relationships and data flows
- Trigger → Memory lookup → Chat request → Memory update → Send reply

##### Architectural patterns and design principles
- Event-driven workflow: Components react to incoming email events.
- Integration orchestration: n8n acts as the glue between Gmail and Gemini.
- Stateful vs stateless: Memory Node introduces minimal statefulness; other nodes remain stateless.
- No-code modularity: each piece of functionality is encapsulated in its own node.

##### Relevant technologies and frameworks
- n8n (workflow engine)
- Gmail API (trigger and send)
- Google Gemini Chat Model (AI service)
- Simple Memory Node (state storage)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "n8n Orchestration Platform"
        direction TB
        GmailTrigger["Gmail Trigger"]:::trigger
        SimpleMemory["Simple Memory"]:::processor
        GoogleGeminiChat["Google Gemini Chat"]:::processor
        GmailSend["Gmail Send"]:::trigger
    end

    GmailAPI["Gmail API\n(OAuth2)"]:::external
    GeminiAPI["Google Gemini Chat API\n(API Key)"]:::external
    README["Workflow Definition\nREADME.md"]:::doc

    GmailAPI -->|"New Email"| GmailTrigger
    GmailTrigger -->|"payload"| SimpleMemory
    SimpleMemory -->|"enriched payload"| GoogleGeminiChat
    GoogleGeminiChat -->|"AI reply"| SimpleMemory
    SimpleMemory -->|"updated payload"| GmailSend
    GmailSend -->|"Send Email"| GmailAPI
    GoogleGeminiChat -->|"Chat Request"| GeminiAPI

    click GmailTrigger "https://github.com/adhi1213/my-n8n-ai-agent/blob/main/my_first_ai_agent (1).json"
    click SimpleMemory "https://github.com/adhi1213/my-n8n-ai-agent/blob/main/my_first_ai_agent (1).json"
    click GoogleGeminiChat "https://github.com/adhi1213/my-n8n-ai-agent/blob/main/my_first_ai_agent (1).json"
    click GmailSend "https://github.com/adhi1213/my-n8n-ai-agent/blob/main/my_first_ai_agent (1).json"
    click README "https://github.com/adhi1213/my-n8n-ai-agent/blob/main/README.md"
    
    classDef trigger fill:#a2f5a2,stroke:#333,stroke-width:1px
    classDef processor fill:#add8e6,stroke:#333,stroke-width:1px
    classDef external fill:#d3d3d3,stroke:#333,stroke-width:1px
    classDef doc fill:#fff2a8,stroke:#333,stroke-width:1px
```
