Skip to content

Repository files navigation

ReachInbox Assignment - Backend Progress

Video Demo

Project Structure

  • Monorepo with /backend (Express + TypeScript) and /frontend (Vite + React)

🚀 Manual Installation Guide

Prerequisites

  • Node.js (v18 or later)
  • Docker and Docker Compose
  • npm or yarn
  • Git

Backend Setup

  1. Clone the repository

    git clone https://github.com/sahil-009/reachinbox.git
    cd reachinbox-main
  2. Set up environment variables

    cd backend
    cp .env.local .env

    Update the .env file with your configuration:

    # Server
    PORT=3000
    NODE_ENV=development
    
    # IMAP Configuration
    IMAP_HOST=ethereal.email
    IMAP_PORT=993
    IMAP_SECURE=true
    IMAP_USER=your-email@ethereal.email
    IMAP_PASSWORD=your-ethereal-password
    
    # Elasticsearch
    ELASTICSEARCH_NODE=http://localhost:9200
    
  3. Start Elasticsearch using Docker

    docker compose up -d
  4. Install dependencies

    npm install
    # or
    yarn install
  5. Start Elasticsearch using Docker

    docker compose up -d
  6. Run the backend server

    npm run dev
    # or
    yarn dev

Frontend Setup

  1. Navigate to frontend directory

    cd ../frontend
  2. Install dependencies

    npm install
    
  3. Start the development server

    npm run dev
    

🏗️ System Architecture

High-Level Architecture

┌─────────────────┐     ┌───────────────────┐     ┌──────────────────┐
│                 │     │                   │     │                  │
│  Email Service  │<--->│  Backend Server   │<--->│  Elasticsearch   │
│   (IMAP/IDLE)   │     │   (Node.js/TS)    │     │                  │
│                 │     │                   │     │                  │
└─────────────────┘     └────────┬──────────┘     └──────────────────┘
                                 │
                                 │
                         ┌───────▼───────┐
                         │               │
                         │   Frontend    │
                         │  (React/TS)   │
                         │               │
                         └───────────────┘

Component Breakdown

  1. Email Service

    • Handles IMAP connections using imapflow
    • Implements IDLE mode for real-time email notifications
    • Parses incoming emails using mailparser
  2. Backend Server

    • API Layer: RESTful endpoints for client communication
    • Service Layer: Business logic for email processing
    • Data Access Layer: Handles Elasticsearch operations
    • Worker Processes: Background jobs for email syncing
  3. Elasticsearch

    • Stores and indexes all emails
    • Enables fast full-text search and filtering
    • Handles large volumes of email data efficiently
  4. Frontend

    • Built with React and TypeScript
    • State management with React Query
    • Real-time updates via WebSockets

Features Implemented So Far

1. Backend Setup

  • Express server with TypeScript
  • Health check endpoint at /health
  • Environment variables managed with .env

2. Real-Time IMAP Email Sync

  • Uses imapflow for persistent IMAP (IDLE mode) connections
  • Connects to Ethereal Email IMAP test account
  • Fetches last 30 days of emails on startup
  • Listens for new emails in real-time
  • Parses emails using mailparser

3. Elasticsearch Integration

  • Elasticsearch set up via Docker Compose (local, single-node)
  • Backend connects to Elasticsearch using official Node.js client
  • Every fetched/received email is indexed into Elasticsearch with fields:
    • subject, from, to, date, text, html, messageId, folder, account
  • Type/linter issues fixed for robust, type-safe indexing

Next Steps

  • Build backend API endpoints for searching/filtering emails
  • Add AI categorization (Gemini API)
  • Integrate Slack/webhook notifications
  • Build frontend to display/search emails

How to Run So Far

  1. Install dependencies in /backend and /frontend
  2. Add .env file in /backend with IMAP and Elasticsearch config
  3. Start Elasticsearch: docker compose up -d
  4. Start backend: npm run dev in /backend
  5. Backend will sync and index emails automatically

Releases

Packages

Contributors

Languages