# supunhg/filo architecture

> Architecture diagram of the GitHub repository supunhg/filo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/supunhg/filo
- Repository: https://github.com/supunhg/filo

## Overview

1. **Repository purpose**
   Filo is an offline Python file-forensics toolkit. Its core job is to take an arbitrary blob, classify it into one or more formats, explain the evidence behind that decision, and optionally repair or extract hidden content.

2. **Primary entry points**
   The main user-facing boundary is the CLI in `filo/cli.py`, which exposes subcommands such as analyze, batch, teach, repair, pcap, stego, lineage, and reset operations. The Python API mirrors the same capabilities through classes and helpers exported from `filo/__init__.py`.

3. **Central orchestration layer**
   `filo/analyzer.py` is the hub of the system. It coordinates format detection, confidence scoring, evidence collection, contradiction checks, and downstream enrichments like metadata, fingerprints, embedded-object discovery, and ML-assisted classification.

4. **Format knowledge base**
   File-type knowledge is mostly data-driven. `filo/formats.py` and the `filo/formats/*.yaml` catalog encode signatures and structural rules for 60+ formats, including archives, documents, executables, images, network captures, and container formats. This is what lets the analyzer distinguish close cousins like DOCX vs ZIP or APK vs JAR.

5. **Evidence and confidence model**
   The repository is built around explainable detection rather than a single yes/no classifier. `filo/models.py` defines the structured results passed between modules, while `filo/architecture.py`, `filo/metadata.py`, `filo/fingerprint.py`, and `filo/contradictions.py` contribute evidence used to rank candidates and produce the confidence breakdown shown in the CLI.

6. **Specialized analysis subsystems**
   Several modules handle domain-specific inspections:
   - `filo/container.py` for ZIP-based/container formats
   - `filo/polyglot.py` for dual-format files
   - `filo/embedded.py` for hidden payloads and trailing data
   - `filo/crypto.py` for encrypted-data heuristics
   - `filo/stego.py` for image/document steganography
   - `filo/pcap.py` for network capture analysis
   - `filo/office.py` for Office macro/macros-in-OLE analysis
   - `filo/yarascanner.py` for YARA rule matching  
   These modules are mostly independent detectors that feed findings back into the main result object.

7. **Learning and profiling path**
   `filo/ml.py` and `filo/profiler.py` provide the offline learning layer. The pipeline learns discriminative byte patterns, statistical features, and n-gram profiles from known-good files, then uses those learned artifacts to improve later detections. This is explicitly local-state based, not cloud-backed.

8. **Repair and carving path**
   `filo/repair.py` and `filo/carver.py` are the remediation side of the tool. They focus on reconstructing damaged headers, recovering structure, and extracting embedded or recoverable content from corrupted files. This is separate from pure identification, so analysis can remain non-destructive unless repair is requested.

9. **Batching, export, and reporting**
   `filo/batch.py` handles directory-scale processing and parallelization. `filo/export.py` turns analysis results into machine-friendly outputs such as JSON or SARIF. The CLI’s default “top evidence” view is just one presentation layer over the same structured report.

10. **State, lineage, and persistence boundaries**
   `filo/lineage.py` tracks hash-based chain-of-custody and file transformation history. The README indicates user state lives under `~/.filo/`, including learned patterns and the lineage database, so the analyzer is stateless relative to file inputs but stateful across sessions for ML and provenance.

11. **Packaging and deployment shape**
   The repo supports multiple delivery modes: pip/PyPI, Docker, and Debian packaging. `Dockerfile`, `build-deb.sh`, and `packaging/DEBIAN/*` show that the runtime is still the same Python application, but wrapped for isolated installation and offline use.

12. **Test and demo corpus**
   `tests/` is the main regression boundary, covering each subsystem individually and in integration. `demo/` and `examples/` provide representative malicious, corrupted, polyglot, and stego samples, which are important because this architecture is validated primarily by analyzing real file specimens rather than synthetic unit-only cases.

Main entry points: [`filo/analyzer.py`](https://github.com/supunhg/filo/blob/main/filo/analyzer.py) (Analyzer), [`filo/cli.py`](https://github.com/supunhg/filo/blob/main/filo/cli.py) (CLI), [`filo/repair.py`](https://github.com/supunhg/filo/blob/main/filo/repair.py) (Repair), [`filo/formats.py`](https://github.com/supunhg/filo/blob/main/filo/formats.py) (Format catalog)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_entry["Entry points"]
  node_filo_cli["CLI<br/>command interface<br/>[cli.py]"]
  node_filo_init["Python API<br/>public API<br/>[__init__.py]"]
end

subgraph group_g_core["Core analysis"]
  node_filo_analyzer{{"Analyzer<br/>orchestrator<br/>[analyzer.py]"}}
  node_filo_models["Result models<br/>data model<br/>[models.py]"]
  node_filo_formats["Format catalog<br/>signature rules<br/>[formats.py]"]
  node_filo_yaml_catalog["YAML rules<br/>format corpus"]
  node_filo_architecture["Architecture<br/>evidence source<br/>[architecture.py]"]
  node_filo_metadata["Metadata<br/>evidence source<br/>[metadata.py]"]
  node_filo_fingerprint["Fingerprinting<br/>evidence source<br/>[fingerprint.py]"]
  node_filo_contradictions["Contradictions<br/>validator<br/>[contradictions.py]"]
end

subgraph group_g_detectors["Specialized detectors"]
  node_filo_container["Containers<br/>detector<br/>[container.py]"]
  node_filo_polyglot["Polyglots<br/>detector<br/>[polyglot.py]"]
  node_filo_embedded["Embedded data<br/>detector<br/>[embedded.py]"]
  node_filo_crypto["Crypto heuristics<br/>detector<br/>[crypto.py]"]
  node_filo_stego["Steganography<br/>detector<br/>[stego.py]"]
  node_filo_pcap["PCAP analysis<br/>detector<br/>[pcap.py]"]
  node_filo_office["Office analysis<br/>detector<br/>[office.py]"]
  node_filo_yara["YARA scan<br/>rule matcher<br/>[yarascanner.py]"]
end

subgraph group_g_learning["Learning and state"]
  node_filo_ml["ML learning<br/>local learning<br/>[ml.py]"]
  node_filo_profiler["Profiling<br/>feature extractor<br/>[profiler.py]"]
  node_filo_lineage["Lineage<br/>provenance<br/>[lineage.py]"]
end

subgraph group_g_remediation["Repair and output"]
  node_filo_repair["Repair<br/>remediation<br/>[repair.py]"]
  node_filo_carver["Carving<br/>remediation<br/>[carver.py]"]
  node_filo_batch["Batch<br/>pipeline<br/>[batch.py]"]
  node_filo_export["Export<br/>reporting<br/>[export.py]"]
end

node_filo_cli -->|"analyze"| node_filo_analyzer
node_filo_cli -->|"batch"| node_filo_batch
node_filo_cli -->|"repair"| node_filo_repair
node_filo_cli -->|"lineage"| node_filo_lineage
node_filo_init -->|"API"| node_filo_analyzer
node_filo_analyzer -->|"results"| node_filo_models
node_filo_analyzer -->|"classify"| node_filo_formats
node_filo_formats -->|"rules"| node_filo_yaml_catalog
node_filo_analyzer -->|"evidence"| node_filo_architecture
node_filo_analyzer -->|"evidence"| node_filo_metadata
node_filo_analyzer -->|"evidence"| node_filo_fingerprint
node_filo_analyzer -->|"validate"| node_filo_contradictions
node_filo_analyzer -->|"inspect"| node_filo_container
node_filo_analyzer -->|"inspect"| node_filo_polyglot
node_filo_analyzer -->|"inspect"| node_filo_embedded
node_filo_analyzer -->|"inspect"| node_filo_crypto
node_filo_analyzer -->|"inspect"| node_filo_stego
node_filo_analyzer -->|"inspect"| node_filo_pcap
node_filo_analyzer -->|"inspect"| node_filo_office
node_filo_analyzer -->|"scan"| node_filo_yara
node_filo_analyzer -->|"learned signals"| node_filo_ml
node_filo_ml -->|"profiles"| node_filo_profiler
node_filo_lineage -->|"persist"| node_filo_export
node_filo_batch -->|"fan out"| node_filo_analyzer
node_filo_repair -->|"recover"| node_filo_carver
node_filo_repair -->|"verify"| node_filo_analyzer
node_filo_analyzer -->|"report"| node_filo_export

click node_filo_cli "https://github.com/supunhg/filo/blob/main/filo/cli.py"
click node_filo_init "https://github.com/supunhg/filo/blob/main/filo/__init__.py"
click node_filo_analyzer "https://github.com/supunhg/filo/blob/main/filo/analyzer.py"
click node_filo_models "https://github.com/supunhg/filo/blob/main/filo/models.py"
click node_filo_formats "https://github.com/supunhg/filo/blob/main/filo/formats.py"
click node_filo_yaml_catalog "https://github.com/supunhg/filo/tree/main/filo/formats"
click node_filo_architecture "https://github.com/supunhg/filo/blob/main/filo/architecture.py"
click node_filo_metadata "https://github.com/supunhg/filo/blob/main/filo/metadata.py"
click node_filo_fingerprint "https://github.com/supunhg/filo/blob/main/filo/fingerprint.py"
click node_filo_contradictions "https://github.com/supunhg/filo/blob/main/filo/contradictions.py"
click node_filo_container "https://github.com/supunhg/filo/blob/main/filo/container.py"
click node_filo_polyglot "https://github.com/supunhg/filo/blob/main/filo/polyglot.py"
click node_filo_embedded "https://github.com/supunhg/filo/blob/main/filo/embedded.py"
click node_filo_crypto "https://github.com/supunhg/filo/blob/main/filo/crypto.py"
click node_filo_stego "https://github.com/supunhg/filo/blob/main/filo/stego.py"
click node_filo_pcap "https://github.com/supunhg/filo/blob/main/filo/pcap.py"
click node_filo_office "https://github.com/supunhg/filo/blob/main/filo/office.py"
click node_filo_yara "https://github.com/supunhg/filo/blob/main/filo/yarascanner.py"
click node_filo_ml "https://github.com/supunhg/filo/blob/main/filo/ml.py"
click node_filo_profiler "https://github.com/supunhg/filo/blob/main/filo/profiler.py"
click node_filo_lineage "https://github.com/supunhg/filo/blob/main/filo/lineage.py"
click node_filo_repair "https://github.com/supunhg/filo/blob/main/filo/repair.py"
click node_filo_carver "https://github.com/supunhg/filo/blob/main/filo/carver.py"
click node_filo_batch "https://github.com/supunhg/filo/blob/main/filo/batch.py"
click node_filo_export "https://github.com/supunhg/filo/blob/main/filo/export.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_filo_cli,node_filo_init toneBlue
class node_filo_analyzer,node_filo_models,node_filo_formats,node_filo_yaml_catalog,node_filo_architecture,node_filo_metadata,node_filo_fingerprint,node_filo_contradictions toneAmber
class node_filo_container,node_filo_polyglot,node_filo_embedded,node_filo_crypto,node_filo_stego,node_filo_pcap,node_filo_office,node_filo_yara toneMint
class node_filo_ml,node_filo_profiler,node_filo_lineage toneRose
class node_filo_repair,node_filo_carver,node_filo_batch,node_filo_export toneIndigo
```

## Components

### Entry points

User-facing CLI and Python API boundaries

- [CLI](https://github.com/supunhg/filo/blob/main/filo/cli.py): command interface · Subcommands for analyze, batch, teach, repair, pcap, stego, lineage, and reset · `filo/cli.py`
- [Python API](https://github.com/supunhg/filo/blob/main/filo/__init__.py): public API · Package exports that mirror the CLI capabilities · `filo/__init__.py`

### Core analysis

Main orchestration, evidence, and format knowledge

- [Analyzer](https://github.com/supunhg/filo/blob/main/filo/analyzer.py): orchestrator · Coordinates detection, scoring, evidence collection, and enrichments · `filo/analyzer.py`
- [Result models](https://github.com/supunhg/filo/blob/main/filo/models.py): data model · Structured analysis results and shared objects passed between modules · `filo/models.py`
- [Format catalog](https://github.com/supunhg/filo/blob/main/filo/formats.py): signature rules · Data-driven format knowledge and structural signatures · `filo/formats.py`
- [YAML rules](https://github.com/supunhg/filo/tree/main/filo/formats): format corpus · Per-format signatures and constraints for many file types · `filo/formats`
- [Architecture](https://github.com/supunhg/filo/blob/main/filo/architecture.py): evidence source · Structural evidence used to identify and explain files · `filo/architecture.py`
- [Metadata](https://github.com/supunhg/filo/blob/main/filo/metadata.py): evidence source · Extracts metadata signals for ranking and explanation · `filo/metadata.py`
- [Fingerprinting](https://github.com/supunhg/filo/blob/main/filo/fingerprint.py): evidence source · Build and tool fingerprints used in confidence breakdowns · `filo/fingerprint.py`
- [Contradictions](https://github.com/supunhg/filo/blob/main/filo/contradictions.py): validator · Checks evidence conflicts and suppresses bad matches · `filo/contradictions.py`

### Specialized detectors

Domain-specific inspection modules feeding analysis

- [Containers](https://github.com/supunhg/filo/blob/main/filo/container.py): detector · Inspects ZIP-based and other container formats · `filo/container.py`
- [Polyglots](https://github.com/supunhg/filo/blob/main/filo/polyglot.py): detector · Detects dual-format and overlapping file identities · `filo/polyglot.py`
- [Embedded data](https://github.com/supunhg/filo/blob/main/filo/embedded.py): detector · Finds hidden payloads, overlays, and trailing content · `filo/embedded.py`
- [Crypto heuristics](https://github.com/supunhg/filo/blob/main/filo/crypto.py): detector · Flags encrypted or key-protected content patterns · `filo/crypto.py`
- [Steganography](https://github.com/supunhg/filo/blob/main/filo/stego.py): detector · Looks for hidden content in images and documents · `filo/stego.py`
- [PCAP analysis](https://github.com/supunhg/filo/blob/main/filo/pcap.py): detector · Analyzes packet-capture files and network evidence · `filo/pcap.py`
- [Office analysis](https://github.com/supunhg/filo/blob/main/filo/office.py): detector · Special handling for Office and macro-bearing documents · `filo/office.py`
- [YARA scan](https://github.com/supunhg/filo/blob/main/filo/yarascanner.py): rule matcher · Matches rule-based indicators against file contents · `filo/yarascanner.py`

### Learning and state

Local profiling, lineage, and persistent state

- [ML learning](https://github.com/supunhg/filo/blob/main/filo/ml.py): local learning · Learns discriminative byte patterns and feature models offline · `filo/ml.py`
- [Profiling](https://github.com/supunhg/filo/blob/main/filo/profiler.py): feature extractor · Builds byte statistics and n-gram profiles from known files · `filo/profiler.py`
- [Lineage](https://github.com/supunhg/filo/blob/main/filo/lineage.py): provenance · Tracks hash-based chain of custody and transformation history · `filo/lineage.py`

### Repair and output

Batch processing, repair, carving, and export

- [Repair](https://github.com/supunhg/filo/blob/main/filo/repair.py): remediation · Reconstructs damaged structure and fixes corrupted files · `filo/repair.py`
- [Carving](https://github.com/supunhg/filo/blob/main/filo/carver.py): remediation · Extracts recoverable or embedded content from damaged inputs · `filo/carver.py`
- [Batch](https://github.com/supunhg/filo/blob/main/filo/batch.py): pipeline · Directory-scale processing and parallel execution · `filo/batch.py`
- [Export](https://github.com/supunhg/filo/blob/main/filo/export.py): reporting · Serializes results to JSON, SARIF, and other machine formats · `filo/export.py`

## Connections

- CLI → Analyzer: analyze · CLI drives the main analysis flow
- CLI → Batch: batch · CLI submits directory-scale jobs
- CLI → Repair: repair · CLI invokes remediation mode
- CLI → Lineage: lineage · CLI exposes provenance operations
- Python API → Analyzer: API · Package exports analysis helpers
- Analyzer → Result models: results · Produces structured result objects
- Analyzer → Format catalog: classify · Consults format knowledge during detection
- Format catalog → YAML rules: rules · Loads per-format YAML signatures
- Analyzer → Architecture: evidence · Uses structural evidence in scoring
- Analyzer → Metadata: evidence · Uses metadata signals in ranking
- Analyzer → Fingerprinting: evidence · Uses fingerprinting signals in ranking
- Analyzer → Contradictions: validate · Checks for conflicting evidence
- Analyzer → Containers: inspect · Delegates container-specific analysis
- Analyzer → Polyglots: inspect · Delegates polyglot detection
- Analyzer → Embedded data: inspect · Delegates hidden-payload discovery
- Analyzer → Crypto heuristics: inspect · Delegates encryption heuristics
- Analyzer → Steganography: inspect · Delegates steganography checks
- Analyzer → PCAP analysis: inspect · Delegates packet-capture analysis
- Analyzer → Office analysis: inspect · Delegates Office-specific inspection
- Analyzer → YARA scan: scan · Uses YARA rule matching as an auxiliary signal
- Analyzer → ML learning: learned signals · Consumes learned classification artifacts
- ML learning → Profiling: profiles · Builds learned features from known samples
- Lineage → Export: persist · Stores provenance for reporting and reuse
- Batch → Analyzer: fan out · Runs the analyzer across many inputs
- Repair → Carving: recover · Uses carving to extract recoverable content
- Repair → Analyzer: verify · Re-analyzes repaired files to confirm outcome
- Analyzer → Export: report · Feeds structured results into exporters
