Add initial MVP documentation for DMARQ platform, detailing backend architecture, frontend implementation, and deployment structure
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class Domain(Base):
|
||||
"""Domain model representing a monitored domain"""
|
||||
|
||||
__tablename__ = "domains"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String, unique=True, index=True, nullable=False)
|
||||
description = Column(Text, nullable=True)
|
||||
active = Column(Boolean, default=True)
|
||||
|
||||
# DMARC policy information
|
||||
dmarc_policy = Column(String, nullable=True)
|
||||
spf_record = Column(String, nullable=True)
|
||||
dkim_selectors = Column(String, nullable=True) # Comma-separated list of DKIM selectors
|
||||
|
||||
# DNS verification status
|
||||
verified = Column(Boolean, default=False)
|
||||
verification_token = Column(String, nullable=True)
|
||||
|
||||
# Date fields
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
reports = relationship("DMARCReport", back_populates="domain", cascade="all, delete-orphan")
|
||||
user_domains = relationship("UserDomain", back_populates="domain", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Domain {self.name}>"
|
||||
|
||||
|
||||
class UserDomain(Base):
|
||||
"""Association table for users and domains"""
|
||||
|
||||
__tablename__ = "user_domains"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
domain_id = Column(Integer, ForeignKey("domains.id"), nullable=False)
|
||||
|
||||
# Access level (admin, viewer, etc)
|
||||
role = Column(String, default="viewer", nullable=False)
|
||||
|
||||
# Date fields
|
||||
created_at = Column(DateTime, default=datetime.utcnow)
|
||||
|
||||
# Relationships
|
||||
user = relationship("User", back_populates="user_domains")
|
||||
domain = relationship("Domain", back_populates="user_domains")
|
||||
@@ -0,0 +1,73 @@
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class DMARCReport(Base):
|
||||
"""DMARC Aggregate Report model"""
|
||||
|
||||
__tablename__ = "dmarc_reports"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
domain_id = Column(Integer, ForeignKey("domains.id"), nullable=False)
|
||||
|
||||
# Report metadata
|
||||
report_id = Column(String, index=True, nullable=False)
|
||||
org_name = Column(String, nullable=False)
|
||||
begin_date = Column(Integer, nullable=False) # Unix timestamp
|
||||
end_date = Column(Integer, nullable=False) # Unix timestamp
|
||||
source_email = Column(String, nullable=True)
|
||||
|
||||
# Policy information
|
||||
policy = Column(String, nullable=True) # none, quarantine, reject
|
||||
subdomain_policy = Column(String, nullable=True)
|
||||
adkim = Column(String(1), nullable=True) # r (relaxed) or s (strict)
|
||||
aspf = Column(String(1), nullable=True) # r (relaxed) or s (strict)
|
||||
percentage = Column(Integer, nullable=True)
|
||||
|
||||
# Processing metadata
|
||||
processed_at = Column(DateTime, default=datetime.utcnow)
|
||||
raw_data = Column(Text, nullable=True) # Original XML content (optional)
|
||||
|
||||
# Relationships
|
||||
domain = relationship("Domain", back_populates="reports")
|
||||
records = relationship("ReportRecord", back_populates="report", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<DMARCReport {self.report_id} for {self.domain_id}>"
|
||||
|
||||
|
||||
class ReportRecord(Base):
|
||||
"""Individual record within a DMARC report"""
|
||||
|
||||
__tablename__ = "report_records"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
report_id = Column(Integer, ForeignKey("dmarc_reports.id"), nullable=False)
|
||||
|
||||
# Source information
|
||||
source_ip = Column(String, nullable=False, index=True)
|
||||
count = Column(Integer, nullable=False, default=0)
|
||||
|
||||
# Policy evaluation
|
||||
disposition = Column(String, nullable=False) # none, quarantine, reject
|
||||
dkim = Column(String, nullable=True) # pass, fail
|
||||
spf = Column(String, nullable=True) # pass, fail
|
||||
|
||||
# Identifiers
|
||||
header_from = Column(String, nullable=True)
|
||||
envelope_from = Column(String, nullable=True)
|
||||
|
||||
# Authentication details (optional JSON fields)
|
||||
dkim_auth_details = Column(Text, nullable=True) # JSON array of DKIM results
|
||||
spf_auth_details = Column(Text, nullable=True) # JSON array of SPF results
|
||||
|
||||
# Relationships
|
||||
report = relationship("DMARCReport", back_populates="records")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<ReportRecord {self.id} ({self.source_ip})>"
|
||||
@@ -0,0 +1,25 @@
|
||||
from typing import List, Optional
|
||||
from sqlalchemy import Boolean, Column, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from app.core.database import Base
|
||||
|
||||
|
||||
class User(Base):
|
||||
"""User model"""
|
||||
|
||||
__tablename__ = "users"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
email = Column(String, unique=True, index=True, nullable=False)
|
||||
hashed_password = Column(String, nullable=False)
|
||||
is_active = Column(Boolean, default=True)
|
||||
is_superuser = Column(Boolean, default=False)
|
||||
is_verified = Column(Boolean, default=False)
|
||||
|
||||
# Additional fields
|
||||
full_name = Column(String, nullable=True)
|
||||
organization = Column(String, nullable=True)
|
||||
|
||||
# Relationships
|
||||
user_domains = relationship("UserDomain", back_populates="user", cascade="all, delete-orphan")
|
||||
Reference in New Issue
Block a user