A streamlined FastAPI backend for email phishing detection, specifically optimized for Replit deployment and designed to work seamlessly with the Email Guard Vercel Frontend.
π Full Version Available: This is a lightweight version of the comprehensive Email Guard project (Dev 0.6.2). For enterprise deployments with advanced security features, see the full version.
Frontend: https://email-guard-cyan.vercel.app/
Backend: Deployed on Replit (URL configured via VITE_API_URL
environment variable)
- Replit deployment code: https://replit.com/@Richdaleintern0/EmailGuardLightweight
Feature | Lightweight (Dep 0.5.6 Mini) | Full Version (Dev 0.6.2) |
---|---|---|
Deployment | β Replit-optimized | π³ Docker + APISIX Gateway |
AI Models | β phishing-detection-py + Rule-based | π§ DistilBERT + Multiple ML Models |
Security | β JWT Authentication | π Enterprise Security Stack |
Rate Limiting | β‘ Application-level | π‘οΈ APISIX Gateway-level |
Dependencies | π¦ Minimal (11 packages) | π Comprehensive (50+ packages) |
Container Isolation | β Single deployment | β Isolated Docker containers |
Model Complexity | π― Lightweight ML | π§ Heavy transformer models |
Setup Time | β‘ < 5 minutes | β±οΈ 15-30 minutes |
- π€ AI-Powered Detection: Primary ML analysis using
phishing-detection-py
- π§ Rule-Based Fallback: Comprehensive pattern matching when ML models are unavailable
- π JWT Authentication: Secure token-based authentication with HTTP-only cookies
- π Scan History: Track and retrieve analysis results for authenticated users
- β‘ Replit-Optimized: Specifically configured for seamless Replit deployment
- Primary ML Model:
phishing-detection-py
for URL and content analysis - Rule-Based Analyzer: Pattern matching for suspicious indicators
- Metadata Extraction: Content analysis and risk scoring
- Confidence Scoring: Detailed confidence metrics for each analysis
POST /auth/token
- Authenticate and receive JWTPOST /scan/email
- Analyze email content for threatsGET /history
- Retrieve scan historyPOST /auth/logout
- Clear authenticationGET /health
- Health check endpoint
Frontend (Vercel) Backend (Replit)
βββββββββββββββββββ ββββββββββββββββββββ
β React + Vite βββββ HTTPS βββββ FastAPI App β
β β β β
β Dashboard UI β β βββββββββββββββ β
β Auth Flow β β β JWT Auth β β
β Results Displayβ β β Module β β
βββββββββββββββββββ β βββββββββββββββ β
β β
β βββββββββββββββ β
β β AI Analysis β β
β β Engine β β
β βββββββββββββββ β
β β
β βββββββββββββββ β
β β Scan β β
β β History β β
β βββββββββββββββ β
ββββββββββββββββββββ
- FastAPI: Modern Python web framework
- Uvicorn: ASGI server for production
- Python 3.11+: Latest Python features
- phishing-detection-py: Primary ML model for URL/content analysis
- Rule-based analyzer: Custom pattern matching engine
- Content analyzer: Metadata extraction and risk scoring
- python-jose: JWT token handling
- passlib: Secure password hashing
- HTTP-only cookies: XSS protection
fastapi
uvicorn[standard]
python-multipart
python-jose[cryptography]
passlib[bcrypt]
python-dotenv
pydantic
requests
aiofiles
phishing-detection-py
- Import Repository: Import this repository to Replit
- Install Dependencies: Replit auto-installs from
requirements.txt
- Set Environment Variables:
JWT_SECRET_KEY=your-super-secure-jwt-secret-key-here
- Run: Execute
python main.py
- Configure Frontend: Set
VITE_API_URL
in Vercel to your Replit URL
-
Clone Repository:
git clone https://github.com/Richdale04/Email-Guard-Lightweight.git cd Email-Guard-Lightweight
-
Install Dependencies:
pip install -r requirements.txt
-
Environment Setup:
# Create .env file JWT_SECRET_KEY=your-jwt-secret-key
-
Run Server:
python main.py
-
Access API: http://localhost:5000
Variable | Description | Required | Default |
---|---|---|---|
JWT_SECRET_KEY |
Secret key for JWT signing | β Yes | None |
PORT |
Server port (Replit auto-sets) | β No | 5000 |
Email-Guard-Lightweight/
βββ ai/ # AI Analysis Engine
β βββ email_guard.py # Main analyzer with multiple models
β βββ README.md # AI documentation
βββ backend/ # FastAPI Backend
β βββ app.py # Main FastAPI application
β βββ scan.py # Email scanning logic
β βββ modules/ # Backend modules
β β βββ authenticate.py # JWT authentication
β β βββ verify.py # Input validation
β βββ db/ # User database
β βββ users.csv # User tokens storage
βββ main.py # Replit entry point
βββ requirements.txt # Python dependencies
βββ pyproject.toml # Project configuration
βββ README.md # This file
# URL Analysis
urls = extract_urls(email_text)
result = detector.predict(urls[0])
decision = 'phishing' if result.prediction == 1 else 'safe'
# Pattern Detection
suspicious_patterns = ['urgent', 'account suspended', 'verify identity']
risk_score = calculate_risk_score(email_text, patterns)
decision = map_risk_to_decision(risk_score)
{
"results": [
{
"model_source": "PyPI",
"model_name": "phishing-detection-py",
"decision": "phishing|safe|spam|error",
"confidence": 0.85,
"description": "Detailed analysis description"
}
],
"timestamp": "2024-01-01T12:00:00",
"email_snippet": "Email content preview..."
}
# Sample tokens (backend/db/users.csv)
sample_token_1,user1,user # Standard user
sample_token_2,user2,admin # Admin user
- Frontend sends token to
/auth/token
- Backend validates token and creates JWT
- JWT stored in HTTP-only cookie
- Subsequent requests use JWT for authentication
- HTTP-only cookies (XSS protection)
- JWT expiration handling
- Input sanitization and validation
- CORS configuration for Vercel frontend
curl -X POST https://your-replit-url.repl.co/auth/token \
-H "Content-Type: application/json" \
-d '{"token": "sample_token_1"}'
curl -X POST https://your-replit-url.repl.co/scan/email \
-H "Content-Type: application/json" \
-b "auth_token=your-jwt-token" \
-d '{"email_text": "URGENT: Your account has been suspended..."}'
curl -X GET https://your-replit-url.repl.co/history?limit=5 \
-b "auth_token=your-jwt-token"
Subject: URGENT: Account Verification Required
Dear Customer,
Your bank account has been suspended due to suspicious activity.
Please verify your identity immediately by clicking the link below:
http://suspicious-bank-verify.com/urgent-verify
Failure to verify within 24 hours will result in permanent account closure.
Best regards,
Security Team
Expected Result: phishing
with high confidence
Subject: Meeting Reminder
Hi John,
Just a reminder about our team meeting tomorrow at 2 PM in the conference room.
Please bring the quarterly reports we discussed.
Thanks,
Sarah
Expected Result: safe
with high confidence
- Docker Containerization: Single Replit deployment
- APISIX Gateway: Direct FastAPI routing
- DistilBERT Models: Heavy transformer models removed
- Redis Caching: Simplified in-memory processing
- Advanced Rate Limiting: Application-level only
- Multiple Model Pipeline: Streamlined to essential models
- β API Response Format: Identical to full version
- β Authentication Flow: Same JWT implementation
- β Frontend Integration: No changes required
- β Core Analysis: Essential detection capabilities preserved
- Memory: ~100-200MB (vs 1GB+ for full version)
- CPU: Lightweight processing
- Storage: Minimal file system usage
- Startup Time: ~10-30 seconds (vs 2-5 minutes)
- Authentication: < 200ms
- Email Analysis: 1-3 seconds
- History Retrieval: < 100ms
- Health Check: < 50ms
- Concurrent Users: 50-100 on Replit
- Request Volume: 100-500 requests/hour
- Analysis Capacity: Suitable for small-medium deployments
- Model Accuracy: 80-90% (vs 95%+ in full version)
- Security Features: Basic vs enterprise-grade
- Scalability: Limited vs highly scalable
- Model Diversity: 2 analyzers vs 10+ in full version
- β Development/Testing: Perfect for prototyping
- β Small Teams: Up to 50 users
- β Educational: Learning and demonstration
- β Quick Deployment: Rapid setup requirements
- β Enterprise Production: Use full version instead
- β High Volume: > 1000 requests/hour
- β Critical Security: Mission-critical applications
- β Advanced Features: Complex workflow requirements
- Repository: Email Guard Full
- Version: Dev 0.6.2
- Deployment: Docker + APISIX
- Use Case: Enterprise production environments
- Live Demo: Email Guard Dashboard
- Technology: React + TypeScript + Vite
- Deployment: Vercel
- Integration: Works with both versions
Models Not Loading:
# Check if phishing-detection-py is installed
pip list | grep phishing-detection-py
# Reinstall if missing
pip install phishing-detection-py
CORS Errors:
# Verify CORS origins in backend/app.py
allow_origins=[
"https://email-guard-cyan.vercel.app",
"http://localhost:5173" # For local development
]
Authentication Failures:
# Check if JWT_SECRET_KEY is set
echo $JWT_SECRET_KEY
# Generate new secret key
python -c "import secrets; print(secrets.token_hex(32))"
Replit Deployment Issues:
- Ensure
main.py
is the entry point - Check that
requirements.txt
is in root directory - Verify environment variables are set in Replit secrets
- AI Models:
/ai/README.md
- API Reference: Built-in FastAPI docs at
/docs
- Authentication: See
backend/modules/authenticate.py
- FastAPI Documentation: https://fastapi.tiangolo.com/
- Phishing Detection Py: https://pypi.org/project/phishing-detection-py/
- Replit Deployment: https://docs.replit.com/
- Fork the repository
- Create feature branch:
git checkout -b feature/new-feature
- Test changes locally
- Submit pull request with description
- Python: Follow PEP 8 style guidelines
- Type Hints: Add type annotations
- Error Handling: Comprehensive exception handling
- Documentation: Update README for new features
This project is licensed under the AGPL-3.0 License - see the LICENSE file for details.
- Issues: GitHub Issues
- Documentation: This README and inline code documentation
- Full Version: See original repository for advanced features
- Current Version: Dep 0.5.6 Mini
- Full Version: Dev 0.6.2
- Compatibility: Frontend compatible with both versions
- Last Updated: 2024
Email Guard Lightweight - Streamlined email security analysis for rapid deployment and development environments.
For production enterprise deployments, consider the full version with advanced security features and comprehensive model pipeline.