Skip to content

Linkenite Hackathon Challenge : Create a website that automatically fetch gmail and outlook mails everyday specifically focused on support, complaint, request, help related querry and try geting context and summarized draft automatically generated which helps makes stuffs easier

Notifications You must be signed in to change notification settings

teche74/EmailAutomationLinkeniteChallenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ง AI-Augmented Email Automation Platform

An end-to-end AI-powered business automation system that ingests emails, extracts insights, and generates context-aware drafts to empower customer support agents.
Built for the Linkenite Hackathon.


โœจ Features

  • Email ingestion from Gmail & Outlook (via IMAP/MSAL)
  • Shared relational data model in PostgreSQL for consistency across services
  • NLP pipelines:
    • Named Entity Recognition (spaCy + regex for phones, invoices, tickets)
    • Sentiment analysis (HuggingFace)
    • Classification (impact/urgency/type)
  • Draft generation with RAG:
    • Uses HuggingFace text-generation models
    • Fetches relevant knowledge base chunks
  • Streamlit UI:
    • Displays threads, messages, attachments, and insights
    • Agents can generate, edit, and send drafts
    • Simple analytics dashboard (priority, sentiment, type)
  • Audit & Stats:
    • Every action logged (audit_events)
    • Daily KPIs (daily_email_stats)

๐Ÿงญ Design Principles

We strictly follow:

  • KISS: Keep services simple & modular
  • DRY: One shared data model across fetchers, APIs, UI
  • YAGNI: Only build what is needed โ€” avoid over-engineering

The shared data model is the backbone โ€” guaranteeing consistency, traceability, and scalability.


โš™๏ธ Architecture

High-Level Flow

[External Email Providers]
      โ”‚
      โ–ผ (IMAP/OAuth)
[Fetcher Service] โ”€โ”€> (NER, Sentiment, Classification) โ”€โ”€> Normalized msg_dict
      โ”‚
      โ–ผ (save_processed_message)
[Postgres DB]
  - email_threads, email_messages, email_extractions,
  - email_insights, email_attachments, ai_drafts, kb_chunks...
      โ–ฒ
      โ”‚ reads
[Streamlit UI] โ”€โ”€ POST /generate-draft/{id} โ”€โ”€> [Draft API]
                                                  โ”‚
                                                  โ–ผ (Generator + KB lookup)
                                              [ai_drafts row persisted]

Data Flow

  1. Fetch & Parse

    • Connect to Gmail/Outlook โ†’ fetch headers & body
    • Extract entities, classify, sentiment
    • Normalize into msg_dict
  2. Persist

    • Save into Postgres:
      • email_threads
      • email_messages
      • email_extractions, email_insights, email_attachments
  3. UI Read

    • Streamlit reads from DB (SQLAlchemy)
    • Displays enriched messages + analytics
  4. Draft Generation

    • UI calls Draft API โ†’ loads message + KB chunks
    • Runs HuggingFace generator โ†’ saves draft in ai_drafts
    • Draft editable & sendable by agent

๐Ÿ—„๏ธ Data Model (ER Diagram)

+----------------------+       1         N       +----------------------+
|   email_threads      |<------------------------|    email_messages    |
| PK id                |    thread_id FK         | PK id                |
| thread_key (unique)  |                         | provider             |
| subject_canonical    |                         | provider_uid (uniq)  |
| created_at           |                         | message_id_hdr (uniq)|
| last_msg_at          |                         | thread_id (FK)       |
+----------------------+                         | body_text, urls JSON |
                                                 | attachments_meta JSON|
                                                 +----------------------+
                                                         |
                 +---------------------------------------+---------------------------------+
                 |                                       |                                 |
                 v                                       v                                 v
    +--------------------------+            +---------------------------+           +----------------------+
    | email_attachments        |            | email_extractions         |           | email_insights       |
    | PK id                   |            | PK id                    |           | PK id                |
    | message_id FK           |            | message_id FK            |           | message_id FK        |
    | filename, content_type  |            | phone, ticket_id         |           | impact, urgency, ... |
    +--------------------------+            +---------------------------+           +----------------------+

                                           ^
                                           |
                                           | 1 .. N
                                           |
                                   +--------------------+
                                   |     ai_drafts      |
                                   | PK id              |
                                   | message_id FK      |
                                   | thread_id FK       |
                                   | model, prompt      |
                                   | draft_text         |
                                   | status             |
                                   | sent_message_id FK |
                                   +--------------------+
                                           |
                                           v
                                   1 .. N   [rag_citations]
                                   +---------------------+
                                   | rag_citations       |
                                   | draft_id FK         |
                                   | chunk_id FK         |
                                   | score               |
                                   +---------------------+
                                           ^
                                           |
                                  N .. 1   |
                                   +----------------+
                                   |   kb_chunks    |
                                   | document_id FK |
                                   | chunk_index    |
                                   | text           |
                                   +----------------+
                                           |
                                           v
                                   N .. 1
                                   +----------------+
                                   |  kb_documents  |
                                   | source, title  |
                                   | metadata_json  |
                                   +----------------+

Other tables:

  • thread_status โ†’ lifecycle of a thread
  • audit_events โ†’ logs user/system actions
  • daily_email_stats โ†’ aggregated KPIs
  • latest_thread_messages โ†’ materialized view for fast thread queries

๐Ÿš€ Getting Started

1. Clone & Install

git clone https://github.com/your-repo/email-automation.git
cd email-automation
pip install -r requirements.txt

2. Setup Postgres

  • Run migrations:
psql $DATABASE_URL -f migration.sql

3. Environment Variables

export DATABASE_URL=postgresql://user:pass@localhost:5432/emaildb
export GMAIL_USER=...
export OUTLOOK_CLIENT_ID=...
export OUTLOOK_CLIENT_SECRET=...

4. Start APIs

uvicorn emails_api:app --reload --port 8000
uvicorn ai_draft_api:app --reload --port 8001

5. Run Streamlit UI

streamlit run app.py

๐Ÿ“Š Example Workflow

  1. Fetch emails โ†’ parsed & saved into DB
  2. View emails in Streamlit โ†’ insights & entities visible
  3. Generate draft โ†’ calls Draft API, AI draft created & editable
  4. Send draft โ†’ agent approves & sends, audit logged
  5. Track KPIs โ†’ dashboard with sentiment, urgency, daily stats

๐Ÿ”ฎ Future Improvements

  • Semantic KB search with pgvector
  • Async job queue for fetching/drafting at scale
  • Outbound email sending integration
  • Advanced analytics (agent performance, SLA compliance)
  • Role-based access control for multi-team usage

๐Ÿ—๏ธ Tech Stack

  • Backend: FastAPI
  • Frontend: Streamlit
  • Database: PostgreSQL + SQLAlchemy
  • NLP/ML: HuggingFace pipelines, spaCy
  • Infra: Docker, Uvicorn
  • Design principles: KISS, DRY, YAGNI

๐Ÿ“œ License

MIT License


๐Ÿค Acknowledgements

  • Linkenite Hackathon
  • HuggingFace & spaCy for amazing NLP tooling
  • PostgreSQL for robust relational backbone

About

Linkenite Hackathon Challenge : Create a website that automatically fetch gmail and outlook mails everyday specifically focused on support, complaint, request, help related querry and try geting context and summarized draft automatically generated which helps makes stuffs easier

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages