LifeAutomationPortal
A Personal Ad Intelligence & Life Automation Portal backend service that monitors AdGuard DNS logs, enriches blocked domains with WHOIS data, and logs incidents to Notion.
๐ Quick Start
Prerequisites
- Node.js (v16+ recommended)
- Redis server (for deduplication)
- AdGuard Home (with control interface enabled)
- Notion account with API access
Installation
-
Clone the repository:
git clone https://github.com/Sharv619/LifeAutomationPortal.git cd LifeAutomationPortal -
Navigate to the backend and install dependencies:
cd backend npm install -
Configure environment variables:
cp .env.example .env # Edit .env with your actual configuration values -
Build the project:
npm run build
Running the Application
Development mode:
npm run dev
Production mode:
npm start
The server will start on http://localhost:3000 (or the port specified in your .env file).
๐ Environment Configuration
Copy .env.example to .env and configure:
| Variable | Description | Default |
|---|---|---|
NOTION_TOKEN | Your Notion integration token | Required |
NOTION_DB_ID | Notion database ID for storing incidents | Required |
ADGUARD_BASE_URL | AdGuard Home control interface URL | http://localhost:80 |
POLL_INTERVAL_MS | How often to check for new blocked domains | 60000 (1 minute) |
REDIS_URL | Redis connection URL | redis://localhost:6379 |
DEDUP_TTL_SECONDS | How long to remember seen domains | 300 (5 minutes) |
PORT | Server port | 3000 |
Notion Setup
- Create a new integration in Notion Developers
- Get your integration token
- Create a database with these properties:
- Name (Title)
- Category (Select)
- Blocks Detected (Number)
- Last Seen (Date)
- Registrar (Text)
- Organization (Text)
- Country (Text)
- Share the database with your integration
- Copy the database ID and add it to your
.env
๐๏ธ Architecture
Components
- Fastify Server (
src/index.ts) - REST API server with health endpoint - Domain Poller (
src/poller.ts) - Monitors AdGuard query logs for blocked domains - Deduplication (
src/dedup.ts) - Prevents duplicate processing using Redis - Domain Enrichment (
src/enrich.ts) - Enriches domains with WHOIS data - Notion Integration (
src/notion.ts) - Logs incidents to Notion database
Data Flow
- Polling: Every minute, the system fetches blocked domains from AdGuard
- Deduplication: Each domain is checked against Redis to avoid duplicates
- Enrichment: New domains are enriched with WHOIS information
- Logging: Enriched data is stored in your Notion database
- Cleanup: Processed domains are remembered for 5 minutes to prevent duplicates
API Endpoints
GET /health- Health check endpoint
๐งช Testing
Run the test suite:
npm test
Run tests with coverage:
npm test -- --coverage
๐ Monitoring
The application provides structured logging for monitoring:
- Server startup - Logs when the server starts and which port
- Polling activity - Logs when checking for new blocked domains
- Processing - Logs when processing new domains
- Notion logging - Logs when incidents are saved to Notion
- Errors - Comprehensive error logging for troubleshooting
๐ง Troubleshooting
Common Issues
-
Redis Connection Error
- Ensure Redis server is running:
redis-server - Check
REDIS_URLin your.envfile
- Ensure Redis server is running:
-
AdGuard Connection Error
- Verify AdGuard Home control interface is enabled
- Check
ADGUARD_BASE_URLpoints to the correct AdGuard instance
-
Notion Integration Error
- Ensure integration token is correct and has database access
- Verify database ID is correct
-
No Domains Being Processed
- Check AdGuard is actually blocking domains
- Verify query log endpoint is accessible
Logs
Check the application logs for detailed error information. In development mode, logs appear in the console.
๐ฆ Health Checks
Use the health endpoint to monitor service status:
curl http://localhost:3000/health
Expected response:
{
"status": "ok"
}
๐ Project Structure
backend/
โโโ src/
โ โโโ index.ts # Main server entry point
โ โโโ poller.ts # AdGuard monitoring logic
โ โโโ dedup.ts # Redis deduplication
โ โโโ enrich.ts # WHOIS enrichment
โ โโโ notion.ts # Notion integration
โโโ package.json
โโโ tsconfig.json
โโโ jest.config.js
โโโ .env.example
๐ค Contributing
- Follow TypeScript best practices
- Add tests for new functionality
- Update documentation as needed
- Use conventional commit messages
๐ License
This project is part of the Personal Ad Intelligence & Life Automation Portal system.