-
Notifications
You must be signed in to change notification settings - Fork 0
Code Overview
Version: 2.0
Quick reference guide for navigating the PATAS codebase.
PATAS/
├── app/ # Main application code
│ ├── api/ # HTTP API layer (FastAPI)
│ ├── models.py # SQLAlchemy domain models
│ ├── repositories.py # Data access layer
│ ├── v2_*.py # Core v2 services
│ ├── config.py # Configuration
│ └── cli.py # Command-line interface
├── integration/ # Platform-specific integration layer
│ ├── adapters.py # Message adapters
│ ├── backends.py # Rule backends
│ └── cli.py # PoC CLI
├── tests/ # Test suite
├── legacy/ # Legacy v1 components (reference only)
├── docs/ # Additional documentation
└── scripts/ # Utility scripts
-
Message- Normalized message storage -
Pattern- Discovered spam patterns -
Rule- SQL blocking rules with lifecycle -
RuleEvaluation- Rule evaluation metrics
-
MessageRepository- Message CRUD operations -
PatternRepository- Pattern management -
RuleRepository- Rule management -
RuleEvaluationRepository- Evaluation metrics access
Ingestion (v2_ingestion.py)
-
TASLogIngester- Ingest logs from API/storage
Pattern Mining (v2_pattern_mining.py)
-
PatternMiningPipeline- Discover patterns from messages
Rule Lifecycle (v2_rule_lifecycle.py)
-
RuleLifecycleService- Manage rule state machine
Shadow Evaluation (v2_shadow_evaluation.py)
-
ShadowEvaluationService- Evaluate rules safely
Promotion (v2_promotion.py)
-
PromotionService- Promote/deprecate rules automatically
Rule Backend (v2_rule_backend.py)
-
RuleBackend- Abstract interface for rule export -
SqlRuleBackend- SQL export -
RolRuleBackend- ROL format export
LLM Engine (v2_llm_engine.py)
-
PatternMiningEngine- Abstract interface for LLM -
OpenAIPatternMiningEngine- OpenAI implementation
SQL Safety (v2_sql_safety.py)
- SQL validation and sanitization
Semantic Mining (v2_semantic_mining.py)
- Semantic clustering and pattern discovery
Embedding Engine (v2_embedding_engine.py)
- Embedding generation for semantic similarity
Safety Mode (v2_safety_mode.py)
- Safety profile management
Pattern Quality (v2_pattern_quality.py, v2_pattern_quality_tiers.py)
- Pattern quality assessment and tier assignment
SQL LLM Validator (v2_sql_llm_validator.py)
- LLM-based SQL rule validation
Main App (api/main.py)
- FastAPI application with all endpoints
- Thin orchestration layer over Core services
Models (api/models.py)
- Pydantic request/response models
Entry Point (api/run.py)
- Server startup script
-
Settings- Pydantic settings with environment variable support - All configuration via environment variables or
.envfile
-
patas ingest-logs- Ingest logs -
patas mine-patterns- Run pattern mining -
patas eval-rules- Evaluate shadow rules -
patas promote-rules- Promotion/rollback -
patas safety-eval- Run safety evaluation -
patas explain-rule- Explain a single rule -
patas demo-tg- Run your platform demo
- Generic Core - No client-specific logic in core
- Extension Points - Interfaces for backends, engines, adapters
- Thin API Layer - No business logic, just orchestration
- Explicit Flows - Clear, testable, understandable
- Safety First - SQL validation, rule validation, metrics
uvicorn app.api.main:app --host 0.0.0.0 --port 8000
# or
patas-apipatas <command> [options]All tests in tests/ directory:
-
test_v2_*.py- Core v2 component tests -
test_api.py- API endpoint tests -
test_*.py- Other component tests
Run tests:
pytest tests/To extend PATAS Core:
-
Rule Backend - Implement
RuleBackendinterface -
LLM Engine - Implement
PatternMiningEngineinterface -
Message Adapter - Extend
MessageRepositoryor create adapter - Pattern Profile - Add pattern types/extraction logic
See Architecture for detailed extension guide.
Start here:
- Read Architecture for high-level understanding
- Review
app/models.pyfor domain models - Check
app/api/main.pyfor API endpoints - Look at
app/v2_pattern_mining.pyfor core service example
Key files to understand:
-
app/models.py- Data structures -
app/repositories.py- Data access -
app/v2_pattern_mining.py- Pattern discovery -
app/v2_promotion.py- Rule lifecycle -
app/api/main.py- API layer
- Architecture - High-level architecture
- Configuration - Configuration options
- API Reference - API endpoint documentation