Skip to content

AIEO Architecture

Overview

AIEO is a full-stack application for optimizing content to maximize AI engine citations. It consists of a FastAPI backend, React frontend, and Python CLI tool.

System Architecture

┌─────────────┐     ┌──────────────┐     ┌─────────────┐
│   Frontend  │────▶│    Backend   │────▶│  Database   │
│   (React)   │     │   (FastAPI)  │     │ (PostgreSQL)│
└─────────────┘     └──────────────┘     └─────────────┘
                            │
                            ├────▶ Redis (Cache)
                            ├────▶ Qdrant (Vectors)
                            └────▶ AI Services (OpenAI/Anthropic)

Components

Backend (backend/)

Framework: FastAPI (Python 3.9+)

Structure:

backend/
├── app/
│   ├── api/v1/          # API endpoints
│   │   ├── audit.py     # Content auditing
│   │   ├── optimize.py  # Content optimization
│   │   ├── citations.py # Citation tracking
│   │   └── patterns.py  # Pattern library
│   ├── core/            # Core utilities
│   │   ├── config.py    # Configuration
│   │   ├── database.py  # Database connection
│   │   ├── security.py  # Authentication
│   │   └── validation.py # Input validation
│   ├── models/          # Database models
│   ├── services/        # Business logic
│   │   ├── scoring_engine.py
│   │   ├── content_parser.py
│   │   ├── audit_service.py
│   │   └── optimize_service.py
│   └── tasks/           # Celery tasks
└── tests/               # Test suite

Key Services:

  1. Scoring Engine (scoring_engine.py)
  2. Detects 10 AIEO patterns with weighted scoring (total: 125 max raw → normalized to 100)
  3. Calculates composite score (0-100) and letter grade
  4. Identifies gaps (missing patterns) sorted by severity
  5. Detects anti-patterns (over-optimization, keyword stuffing, missing structure) and applies penalties
  6. Can run standalone without any external services (except optional spaCy for entity density)

  7. Content Parser (content_parser.py)

  8. Parses markdown and HTML via markdown + beautifulsoup4
  9. Extracts: headers, tables, lists, links, word count, content hash
  10. HTML-to-markdown conversion via html2text for URL-fetched content
  11. No external service dependencies

  12. Audit Service (audit_service.py)

  13. Orchestrates content analysis (URL fetching → parsing → scoring → benchmarking)
  14. Redis-based caching (content hash as cache key)
  15. Generates audit reports with benchmark percentiles
  16. Requires full backend stack (Redis, PostgreSQL, Qdrant)

  17. Optimize Service (optimize_service.py)

  18. Applies AIEO patterns via AI (OpenAI GPT-4 or Anthropic Claude)
  19. Uses AI for content optimization
  20. Generates change recommendations

Frontend (frontend/)

Framework: React + TypeScript + Vite

Structure:

frontend/
├── src/
│   ├── pages/           # Page components
│   │   ├── AuditPage.tsx
│   │   ├── OptimizePage.tsx
│   │   └── DashboardPage.tsx
│   ├── components/      # Reusable components
│   ├── services/        # API client
│   └── App.tsx          # Main app component
└── public/              # Static assets

Features: - Content auditing interface - Optimization interface - Dashboard for metrics - Pattern library browser

CLI (cli/)

Framework: Python Click

Commands: - aieo audit - Audit content - aieo optimize - Optimize content - aieo dashboard - View metrics

Operational Modes

Full Stack Mode (API + Services)

Requires: PostgreSQL, Redis, Docker (optional: Qdrant, OpenAI/Anthropic)

All features available: API endpoints, caching, optimization, citation tracking, benchmarking.

Standalone Mode (Scoring Engine Only)

Requires: httpx, beautifulsoup4, markdown, html2text (optional: spacy)

The run_audit.py script uses the scoring engine directly, bypassing the API stack. This is ideal for batch auditing URLs without running infrastructure services. The script:

  1. Reads URLs from sites.txt
  2. Fetches HTML content via httpx
  3. Passes content through ContentParser (HTML → structured data)
  4. Scores against all 10 AIEO patterns via ScoringEngine
  5. Outputs per-site JSON + summary to a temp directory

Limitations of standalone mode: - No caching (each run re-fetches and re-scores) - No AI-powered optimization (requires OpenAI/Anthropic keys + API) - No benchmark percentile (requires Qdrant vector DB) - No citation tracking - Entity density scoring requires separate spacy + en_core_web_sm install

Data Flow

Audit Flow

User Input (URL/Content)
    ↓
Content Parser (extract structure)
    ↓
Scoring Engine (detect patterns)
    ↓
Gap Analysis (identify improvements)
    ↓
Benchmark Comparison (percentile ranking)   ← skipped in standalone mode
    ↓
Audit Result (score + recommendations)

Optimization Flow

Original Content
    ↓
Audit (identify gaps)
    ↓
AI Service (apply patterns)
    ↓
Optimized Content
    ↓
Re-score (measure improvement)
    ↓
Optimization Result (before/after + changes)

Database Schema

Tables

  1. users
  2. User accounts and settings

  3. api_keys

  4. API key management
  5. Usage tracking

  6. audits

  7. Audit history
  8. Score tracking

  9. citations

  10. Citation records (TimescaleDB hypertable)
  11. Time-series data

External Services

Required

  • PostgreSQL - Primary database
  • Redis - Caching and Celery broker

Optional

  • Qdrant - Vector database for benchmarks
  • OpenAI - Content optimization
  • Anthropic - Alternative optimization provider

Security

Authentication

  • API key authentication
  • Key hashing (SHA256)
  • Rate limiting

Data Protection

  • Input validation
  • Content sanitization
  • SQL injection prevention
  • XSS prevention

Privacy

  • User-controlled data retention
  • Encrypted storage
  • TLS encryption in transit

Deployment

Development

  • Docker Compose for local services
  • Hot reload for development
  • Local database

Production

  • Containerized services
  • Environment-based configuration
  • Health checks
  • Monitoring and logging

Performance

Targets

  • Audit response: <15 seconds
  • API response: P99 < 15 seconds
  • Parsing: <100ms for typical content

Optimization

  • Redis caching
  • Database indexing
  • Async processing (Celery)
  • Connection pooling

Scalability

Horizontal Scaling

  • Stateless API servers
  • Load balancer support
  • Database replication

Vertical Scaling

  • Connection pooling
  • Caching strategies
  • Query optimization

Monitoring

Metrics

  • Request latency
  • Error rates
  • Cache hit rates
  • Database query performance

Logging

  • Structured logging
  • Request/response logging
  • Error tracking

PRD lineage (prd_lineage/)

Walks a product repo (not a website): classify spec sources, extract canonical PRD element hits and citations, then analyze completeness/drift. Prompt-driven; heuristic fallback. See PRD_LINEAGE.md.

Future Architecture

Planned Improvements

  • Microservices architecture (if needed)
  • Event-driven architecture for citations
  • GraphQL API option
  • Real-time updates via WebSockets

See PRD-aieo.md for detailed roadmap.