# DMARQ โ€“ Architecture & Tech Stack Overview **Project:** DMARQ **Host:** https://app.dmarq.org **Purpose:** Self-hosted, full-featured DMARC monitoring tool with support for Cloudflare integration, alerting, and visual dashboards. --- ## ๐Ÿงฑ System Architecture DMARQ uses an integrated architecture with: - **Unified Backend** (FastAPI with Jinja2 templates) - **Modern UI** (Jinja2 + Tailwind CSS + shadcn/ui) The application is deployed via Docker with a PostgreSQL database storing parsed reports, domain configurations, DNS snapshots, and user information. Optional services (e.g., Apprise for alerts) are included via container or integrated via API calls. --- ## ๐Ÿงฉ Tech Stack | Component | Stack / Tooling | |--------------------|---------------------------------------------| | **Frontend** | Jinja2 Templates + HTMX + Tailwind CSS + shadcn/ui | | **Charts** | Chart.js with Alpine.js integration | | **Routing/Auth** | FastAPI routing + JWT auth (FastAPI Users) | | **Backend** | FastAPI + SQLAlchemy | | **ORM & DB** | SQLAlchemy ORM, PostgreSQL | | **IMAP** | `imap-tools`, `aioimaplib` | | **DMARC Parsing** | `defusedxml`, `lxml`, `zipfile`, `mail-parser` | | **Cloudflare API** | `cloudflare` Python SDK or raw REST client | | **DNS Resolution** | `dnspython` | | **Authentication** | FastAPI Users (JWT + optional OAuth later) | | **Alerting** | [Apprise](https://github.com/caronc/apprise) | | **Testing** | `pytest`, `coverage`, `pytest-mock` | | **CI/CD (optional)**| GitHub Actions, Docker Hub | | **Deployment** | Docker, Docker Compose | | **Config Mgmt** | `dynaconf` (ENV + DB integration) | --- ## ๐Ÿ“ฆ Application Structure ``` dmarq/ โ”œโ”€โ”€ app/ โ”‚ โ”œโ”€โ”€ api/ # REST API endpoints (v1) โ”‚ โ”œโ”€โ”€ core/ # App config, security, constants โ”‚ โ”œโ”€โ”€ models/ # SQLAlchemy ORM models โ”‚ โ”œโ”€โ”€ services/ # Mail parsing, DNS, CF integrations โ”‚ โ”œโ”€โ”€ static/ # CSS (Tailwind), JS, images โ”‚ โ”‚ โ”œโ”€โ”€ css/ # Generated Tailwind styles โ”‚ โ”‚ โ”œโ”€โ”€ js/ # Alpine.js and other frontend scripts โ”‚ โ”‚ โ””โ”€โ”€ img/ # Images and icons โ”‚ โ”œโ”€โ”€ tasks/ # Scheduled tasks (polling, DNS sync) โ”‚ โ”œโ”€โ”€ templates/ # Jinja2 templates โ”‚ โ”‚ โ”œโ”€โ”€ components/ # Reusable UI components โ”‚ โ”‚ โ”œโ”€โ”€ dashboard/ # Dashboard views โ”‚ โ”‚ โ”œโ”€โ”€ layouts/ # Base layouts โ”‚ โ”‚ โ”œโ”€โ”€ reports/ # Report-specific templates โ”‚ โ”‚ โ””โ”€โ”€ wizard/ # Setup wizard templates โ”‚ โ”œโ”€โ”€ tests/ # Unit + integration tests โ”‚ โ””โ”€โ”€ main.py # FastAPI application entrypoint โ”œโ”€โ”€ Dockerfile โ”œโ”€โ”€ docker-compose.yml โ”œโ”€โ”€ config/ โ”‚ โ””โ”€โ”€ seed_env.py # Load ENV vars into DB โ”œโ”€โ”€ .env.example โ”œโ”€โ”€ README.md โ””โ”€โ”€ ARCHITECTURE.md ``` --- ## ๐ŸŒ Functional Modules ### 1. **Config Wizard (Web-Based)** - First step of app usage - Collects: - Admin user creation - IMAP mailbox login - Cloudflare API token - Optional alert channels - Saves config into DB - Optionally seeded from `.env` --- ### 2. **Email Processing** - IMAP polling for inbox (e.g. `dmarc@yourdomain.com`) - Download zipped aggregate XML or forensic reports - Parse with validation and deduplication - Store: - Reporting org - Source IPs, volume - SPF/DKIM result - Applied disposition (none, quarantine, reject) - Forensics: failed messages, sample data --- ### 3. **Cloudflare DNS Sync** - List zones and domains via API - Pull DNS records: - DMARC - SPF - DKIM - MX - BIMI (optional) - Validate correctness and format - Generate actionable **fix suggestions** - DNS updates require manual user approval --- ### 4. **Alerting (via Apprise)** - Alert on: - New forensic reports - New source IPs failing SPF/DKIM - Compliance drops (configurable) - Supports: - Email - Slack - Discord - Webhooks - Matrix - Configurable via web wizard and/or user dashboard --- ### 5. **User Authentication** - FastAPI Users backend - JWT token auth - Server-side sessions with secure cookies - Admin-only access to DNS fix or config modules --- ## ๐Ÿงช Testing Strategy - **Unit Tests:** All parsing, validation, config, services - **Mock External Services:** IMAP, Cloudflare, DNS - **Frontend:** Testing Jinja templates with pytest-html - **E2E (later):** Playwright or Selenium Run with: ```bash docker compose exec app pytest ``` --- ## ๐Ÿง‘โ€๐ŸŽจ UI Implementation ### Frontend Technology DMARQ uses an integrated approach with: 1. **Jinja2 Templates**: Server-side rendering of HTML 2. **Tailwind CSS**: Utility-first CSS framework for styling 3. **shadcn/ui**: Component library adapted for server-rendered templates 4. **Alpine.js**: Minimal JavaScript framework for enhanced interactivity 5. **HTMX**: For AJAX requests without writing JavaScript 6. **Chart.js**: For data visualization components This approach offers several advantages: - Eliminates API-related complexity - Reduces JavaScript bundle size - Improves initial page load performance - Simplifies deployment (single container) - Server-side rendering improves SEO ### UI Components Structure - **Layouts**: Base templates that define the page structure - **Components**: Reusable UI elements like cards, tables, and forms - **Pages**: Full page templates for dashboard, reports, settings, etc. The components follow shadcn/ui design patterns but are implemented as Jinja2 macros or includes rather than React components. --- ## ๐Ÿง‘โ€๐ŸŽจ Branding & UI Design - **Logo:** Stylized shield with "Q" + monogram "D+Q" - **Colors:** - Deep Blue `#1A237E` - Teal `#00ACC1` - Orange `#FF7043` - Light Gray `#F5F5F5`, Dark Gray `#212121` - **Fonts:** Montserrat (headings), Open Sans (body) - **Style:** Minimal, modern, flat icons โ€” inspired by EasyDMARC --- ## ๐Ÿšง Known Constraints - Single-instance deployment (no horizontal scaling) - Target performance: 50โ€“100 domains per instance - Database optimization is secondary - Multitenancy is not supported (yet) --- ## ๐Ÿ“˜ License Apache License 2.0 โ€” Free for personal or commercial use with attribution. **License Compatibility:** All major dependencies and tools used in DMARQ (including FastAPI, SQLAlchemy, Tailwind CSS, shadcn/ui, Alpine.js, HTMX, Chart.js, Apprise, and others) are distributed under permissive licenses (MIT, BSD, Apache 2.0, ISC, or similar) and are compatible with the Apache 2.0 license. --- This document serves as the technical foundation for the implementation of DMARQ.