How keyfive5/cmpmapper works
1. What this repo is
CMP Mapper is a Python prototype for detecting cookie-consent platforms on websites and turning those findings into Consent O Matic rules. The architecture is centered on a pipeline that goes from page collection, to banner analysis, to rule generation, to validation.
2. Main runtime surfaces
There are several entrypoints for the same core capability: command-line scripts like main.py, cmp_mapper_pro.py, web_ui.py, and demo_ui.py, plus a small API surface under api/index.py. The presence of templates/, Procfile, runtime.txt, railway.json, render.yaml, and vercel.json shows it is designed to run as a Python web service and also be deployed in serverless or PaaS environments.
3. Data collection boundary
src/collectors/ contains the ingestion layer: web_scraper.py and banner_collector.py gather HTML, JS, and banner-related page content from target sites. This is the boundary between external websites and the internal analysis pipeline.
4. Feature extraction layer
src/extractors/ turns raw page content into structured signals, such as banner structure, button labels, and CSS selectors. This layer isolates DOM parsing and selector discovery from downstream detection logic.
5. Detection and fingerprinting
src/detectors/ is the core inference subsystem. It includes banner detection, CMP fingerprinting, confidence scoring, and pattern matching, which together decide whether a page contains a consent manager and what kind it is.
6. Pattern analysis
src/analyzers/pattern_analyzer.py and top-level scripts like pharmacy_pattern_analyzer.py appear to support deeper heuristic analysis of consent UI patterns across sites. This is where reusable fingerprints and site-specific variants are identified before rule generation.
7. LLM-assisted enrichment
src/llm/ adds optional AI support for selector extraction and banner interpretation through prompt_builder.py, banner_analyzer.py, and selector_extractor.py. This is an assistive layer, not the primary pipeline, and likely helps recover selectors or interpret ambiguous banners.
8. Rule generation
src/generators/ converts detection output into Consent O Matic-compatible rules. rule_generator.py, consent_o_matic_json_generator.py, consent_o_matic_adapter.py, and template_builder.py form the transformation boundary from analysis results into deployable JSON rule templates.
9. Rule storage and artifact layout
Generated and curated outputs live in data/rules/, data/consent_o_matic_rules/, and custom-consent-o-matic-rules/rules/. The rules.schema.json file and the repo of custom rules indicate a structured rule format that is validated and reused across sites, while data/examples/ and data/consent_o_matic_research/ hold sample inputs and research artifacts.
10. Validation and test harness
src/testers/ contains the verification layer: rule testing, banner validation, and test orchestration. This is supported by many top-level test_*.py and debug_*.py scripts, which suggests the project is heavily exploratory and relies on site-specific regression testing.
11. UI and operator workflow
The web UI files (templates/index.html, web_ui.py, web_ui_fixed.py, web_ui_working.py, demo_ui.py) indicate an operator-facing workflow for single-site analysis, batch URL testing, Excel/CSV upload, and rule management. The docs in UI_README.md, QUICK_START.md, TESTING_GUIDE.md, and WORKFLOW_DIAGRAM.txt reinforce that the UI is a control plane around the same analysis engine.
12. Persistence and utilities
src/database/rule_database.py suggests a lightweight local rule store or index, while src/utils/error_handler.py provides shared error handling across the pipeline. The many one-off helper scripts (create_*, fix_*, improve_*, restore_original.py) show a repo optimized for iterative rule creation and correction rather than a single fixed production workflow.
13. External integration and deployment
The project depends on standard Python packaging (requirements.txt, requirements-vercel.txt) and is prepared for multiple deployment targets. The architecture is therefore split between a local analysis engine and a deployable web layer, with the generated Consent O Matic rules as the main output artifact consumed outside the repo.
Main entry points: rule_generator.py Rule generator · web_scraper.py Web scraper · banner_extractor.py Banner extractor · consent_o_matic_json_generator.py JSON builder
Components 31
Entry points
CLI, API, and UI surfaces that start the workflow
- Main CLI · Primary command-line entry for running the mapper workflow
main.py - Pro CLI · Alternative command-line runner for the core pipeline
cmp_mapper_pro.py - API · Minimal API surface for remote triggering or integration
api/index.py - Web UI · Operator-facing web interface for site analysis and rule work
web_ui.py - Demo UI · Secondary UI surface for demonstrations or simplified runs
demo_ui.py - UI template · Main rendered page for the web interface
templates/index.html
Analysis pipeline
Core collection, extraction, detection, and generation stages
- Web scraper · Fetches page content from target sites
src/collectors/web_scraper.py - Banner collector · Collects banner-related DOM and page evidence
src/collectors/banner_collector.py - Banner extractor · Turns raw page content into banner structure signals
src/extractors/banner_extractor.py - Button extractor · Finds consent button labels and related actions
src/extractors/button_extractor.py - Selector extractor · Derives CSS selectors and targeting signals
src/extractors/selector_extractor.py - Banner detector · Identifies consent banners and their presence
src/detectors/banner_detector.py - Fingerprinting · Classifies CMP patterns and platform signatures
src/detectors/cmp_fingerprinter.py - Confidence · Scores detection certainty and rule reliability
src/detectors/confidence_calculator.py - Pattern matcher · Matches extracted signals against known consent patterns
src/detectors/pattern_matcher.py - Pattern analyzer · Heuristic analysis of reusable consent UI patterns
src/analyzers/pattern_analyzer.py - Prompt builder · Builds prompts for AI-assisted selector and banner interpretation
src/llm/prompt_builder.py - LLM banner · Optional AI-assisted banner interpretation
src/llm/banner_analyzer.py - LLM selector · Optional AI-assisted selector recovery
src/llm/selector_extractor.py - Rule generator · Converts detection output into Consent O Matic rules
src/generators/rule_generator.py - COM adapter · Maps internal results into Consent O Matic structure
src/generators/consent_o_matic_adapter.py - JSON builder · Builds final Consent O Matic JSON artifacts
src/generators/consent_o_matic_json_generator.py - Template builder · Creates reusable rule templates from findings
src/generators/template_builder.py
Review and validation
Validation, testing, and iterative correction tools
- Test runner · Orchestrates validation and regression runs
src/testers/test_runner.py - Rule tester · Evaluates generated rules against pages or fixtures
src/testers/rule_tester.py - Banner validator · Checks whether detected banners and rules behave correctly
src/testers/banner_validator.py
Artifacts
Rule stores and generated Consent O Matic outputs
- Generated rules · Primary output directory for generated Consent O Matic rules
data/consent_o_matic_rules - Curated rules · Human-edited and research-backed rule set
data/rules - Custom repo · Custom Consent O Matic rule repository and schema
custom-consent-o-matic-rules/rules
Support
Shared storage, models, and utilities
- Rule store · Local persistence layer for rules and lookup data
src/database/rule_database.py - Error handler · Shared error handling across the pipeline
src/utils/error_handler.py
Connections 35
- Main CLI → Web scraper: collect · CLI starts by collecting target page content
- Main CLI → Banner collector: collect · CLI can gather banner evidence directly
- Pro CLI → Web scraper: collect · Alternative runner uses the same ingestion layer
- API → Rule generator: run pipeline · API exposes the analysis-to-rule workflow
- Web UI → UI template: renders · Web app serves the operator interface template
- Web UI → Web scraper: analyze · UI triggers site collection and inspection
- Demo UI → Web scraper: analyze · Demo UI reuses the collection stage
- Web scraper → Banner extractor: raw html · Scraped pages feed structured banner extraction
- Banner collector → Banner extractor: evidence · Collected banner data is normalized for extraction
- Banner extractor → Button extractor: signals · Banner structure informs button discovery
- Banner extractor → Selector extractor: selectors · Extraction produces selector candidates
- Button extractor → Pattern matcher: labels · Button labels contribute to pattern matching
- Selector extractor → Pattern matcher: selectors · Selector signals feed matching and fingerprinting
- Pattern matcher → Banner detector: match · Matched patterns help confirm banner detection
- Banner detector → Fingerprinting: classify · Detected banners are fingerprinted into CMP types
- Fingerprinting → Confidence: score · Fingerprint results are scored for reliability
- Pattern analyzer → Rule generator: heuristics · Pattern analysis informs rule creation
- Prompt builder → LLM banner: prompts · Prompt construction supports banner interpretation
- Prompt builder → LLM selector: prompts · Prompt construction supports selector recovery
- LLM banner → Rule generator: enrich · Optional AI findings refine generation inputs
- LLM selector → Rule generator: enrich · Recovered selectors improve generated rules
- Confidence → COM adapter: confidence · Confidence values accompany generation output
- Rule generator → COM adapter: transform · Core generation hands off to Consent O Matic adaptation
- COM adapter → JSON builder: serialize · Adapted structure becomes final JSON
- JSON builder → Template builder: template · JSON output can be wrapped into reusable templates
- Rule generator → Generated rules: writes · Primary output is stored as generated rule artifacts
- Rule generator → Curated rules: updates · Curated rule files capture refined variants
- JSON builder → Custom repo: exports · Generated JSON can be exported to the custom rule repository
- Test runner → Rule tester: orchestrates · Test runner coordinates rule validation
- Test runner → Banner validator: orchestrates · Test runner coordinates banner checks
- Rule tester → Generated rules: verifies · Tester evaluates stored generated rules
- Banner validator → Banner detector: checks · Validation compares detector output with observed banners
- Rule store → Rule generator: lookup · Local store supplies existing rules and prior findings
- Error handler → Web scraper: shared · Shared error handling supports the ingestion boundary
- Error handler → Rule generator: shared · Shared error handling supports generation and export