Skip to content

Repository files navigation

Email Security Backend

Backend service for Gmail-integrated email ingestion, analysis, and realtime updates. It provides Google OAuth login, email fetch/send APIs, asynchronous analysis via Celery, and WebSocket push notifications via Redis Pub/Sub.

Components

Requirements

  • Python 3.10+ recommended
  • RabbitMQ (Celery broker)
  • Redis (Pub/Sub)

Installation

  1. Create and activate a virtual environment.
  2. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file in the project root with the variables below.

Environment Variables

# OAuth / Google
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
GOOGLE_REDIRECT_URI=http://localhost:8000/auth/google/callback
GCP_PUBSUB_SUBSCRIPTION=your-GCP_PUBSUB_SUBSCRIPTION
GCP_PUBSUB_TOPIC=your-GCP_PUBSUB_SUBSCRIPTION

# JWT
JWT_SECRET=change-this

# Database
DATABASE_URL=sqlite:///./test.db

# Celery / RabbitMQ
CELERY_BROKER_URL=amqp://guest:guest@localhost:5672//
CELERY_RESULT_BACKEND=cache+memory://

# Redis
REDIS_URL=redis://localhost:6379/0
REDIS_WS_CHANNEL=ws_updates

Running

  1. Open Command Prompt in the project folder

  2. Activate the virtual environment:

    venv\Scripts\activate
  3. Start Celery workers (in one terminal):

    celery -A celery_app.celery_app worker -Q url_queue,body_queue,headers_queue,attachments_queue --loglevel=info --pool=solo --concurrency=1 --without-mingle --without-gossip
  4. Set up ngrok (in a separate command prompt):

    • Navigate to the folder where ngrok is stored
    • Run:
      ngrok http 8000
  5. Run the project (in the project terminal):

    uvicorn main:app --reload

Notes

  • OAuth login starts at GET /auth/google/login, and Google redirects to GOOGLE_REDIRECT_URI.
  • WebSocket endpoints expect JWT in the query string, for example: /ws/emails?token=....
  • Analysis tasks currently use stubbed API calls in services/analysis_service.py. Replace them with your deployed analysis services if needed.

API Reference

See API_doc.md for endpoint details and examples.

About

back-end for the email app that authenticate with google

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages