# Reverse-Engineering Provenance & License Service (SQLAlchemy + httpx)

## PURPOSE
The video pauses to make a point that is easy to skip: *"Whenever you get into kind of reverse
engineering stuff, there's a lot of different legal things you need to consider... I wouldn't
try to sell anything that you've reverse engineered, but for little experiments and personal
use, it's a fun tool to experiment with."* The creator keeps his own work explicitly personal:
Garage Studio is built on the open-source **Recordly** and is "only for personal use, not
commercial." This service makes that policy machine-enforceable. It stores every analysis
target, the artifacts produced (Ghidra projects, decompiled sources, WSL copies), the source
project each finding came from, and the declared **use intent** — then blocks the steps that
cross the line.

## WHY THIS MATTERS
It teaches that an agentic reverse-engineering pipeline needs a provenance and policy layer,
not just tools. REA analyzes *third-party* software (Loom); the resulting hints feed a
*different* open-source project (Recordly). Recording that chain — target, evidence, derived
work, license, intent — is what keeps the workflow defensible.

## HOW TO BUILD
1. `pip install sqlalchemy httpx`.
2. Define three SQLAlchemy 2.0 models: `Target` (name, kind, size_mb, license), `Artifact`
   (target_id, category, size_mb), `DerivedWork` (name, base_project, intent).
3. Seed the real entities from the video: `loom_recorder` (third-party), `recordly`
   (open-source base), `garage_studio` (derived, intent=`personal`).
4. Add a `POST /analysis-jobs` endpoint built on **httpx** that calls the local analysis
   provider, then writes an `Artifact` row for each result.
5. Enforce a policy rule: a `DerivedWork` whose `intent` is `commercial` and whose base is a
   reverse-engineered third-party target is refused with `409`.

```python
stmt = select(Artifact).where(Artifact.target_id == target.id)
for artifact in session.scalars(stmt):
    ...  # provenance chain: target -> artifact -> derived work
```

## WHEN TO USE IN PRODUCTION
Use it in any team pipeline that mines third-party software for ideas, or that mixes
open-source bases with proprietary derivatives: it gives you an auditable "where did this
knowledge come from" trail and a hard block on commercialising reverse-engineered output. Do
**not** use it as legal advice or as a substitute for reading the actual licenses — it encodes
policy, it does not interpret law.

## HOW IT HELPS STUDENTS
They learn SQLAlchemy 2.0 relationships, session management, async HTTP calls with httpx, and
designing a policy guardrail as a first-class part of a data model — a production skill far
beyond writing the happy path.

## STARTER CODE
See `starter/main.py` for the models, an in-memory SQLite seed, the httpx provider client, and
the policy check that refuses commercial derivatives.
