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.
- FastAPI app: API endpoints, OAuth flow, Gmail integration, and WebSocket gateways in main.py.
- Database layer: SQLAlchemy engine/session setup in database.py and ORM models in models.py.
- Task queue: Celery app and routing in celery_app.py.
- Email analysis tasks: URL, body, headers, and attachment processing in tasks/.
- Analysis service: External analysis API client stubs in services/analysis_service.py.
- Message queue producer: Celery task enqueue in message_queue/producer.py.
- Realtime updates: Redis Pub/Sub publisher in redis_pubsub.py and WebSocket manager in websocket/manager.py.
- API docs: Endpoint reference in API_doc.md.
- Python 3.10+ recommended
- RabbitMQ (Celery broker)
- Redis (Pub/Sub)
- Create and activate a virtual environment.
- Install dependencies:
pip install -r requirements.txt- Create a
.envfile in the project root with the variables below.
# 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-
Open Command Prompt in the project folder
-
Activate the virtual environment:
venv\Scripts\activate
-
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
-
Set up ngrok (in a separate command prompt):
- Navigate to the folder where ngrok is stored
- Run:
ngrok http 8000
-
Run the project (in the project terminal):
uvicorn main:app --reload
- OAuth login starts at
GET /auth/google/login, and Google redirects toGOOGLE_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.
See API_doc.md for endpoint details and examples.