Bounded, read-only intelligence layer for manufacturing defect root cause analysis.
This repository contains the backend API for IntelFactor's closed-loop defect analysis system. It provides AI-powered root cause analysis without mutating production systems.
- Intelligence, not automation - Provides insights; humans make decisions
- Read-only - No writes to production tables or equipment control
- Bounded queries - Time windows (1-30 days), row limits (10K events max)
- Evidence-first - All hypotheses backed by data citations
IntelBase (React) → Lambda/API Gateway → Bedrock + DynamoDB (read-only)
↓
S3 (PDF reports)
Full architecture: docs/architecture/MASTER_TECHNICAL_ARCHITECTURE.md
- Python 3.11+
- AWS CLI configured
- Virtual environment
# Clone repository
git clone git@github.com:tonesgainz/intelfactor-closedloop.git
cd intelfactor-closedloop
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r backend/requirements.txt
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your settings
# Run locally
./scripts/run_local.sh# Run tests
./scripts/test.sh
# Test API
curl http://localhost:8000/healthFull guide: docs/runbooks/LOCAL_DEV.md
.
├── backend/ # FastAPI backend
│ ├── app/ # Application package
│ │ ├── main.py # FastAPI entry point
│ │ ├── lambda_handler.py # Lambda adapter
│ │ ├── api/ # API routes
│ │ ├── closed_loop/ # Core logic (notifier, PDF, providers, trigger)
│ │ ├── streaming/ # Kafka library code
│ │ └── local/ # Mock providers for dev
│ ├── tests/ # Unit tests
│ └── requirements.txt # Python dependencies
├── intelfactor/ # Agent implementations
│ └── closed_loop/ # Agents, manager, providers
├── docs/ # Documentation
│ ├── architecture/ # System design docs
│ └── runbooks/ # Operational guides
├── scripts/ # Utility scripts
│ ├── run_local.sh # Run backend locally
│ ├── test.sh # Run tests
│ ├── format.sh # Format code
│ ├── deploy-staging.sh # Deploy to AWS Lambda
│ └── test-staging.sh # Test staging deployment
├── infrastructure/ # AWS SAM template
│ └── template.yaml # Lambda + Function URL
└── README.md # This file
Analyze defects and provide root cause analysis.
Request:
{
"workspace_id": "factory-1",
"start_time": "2026-02-10T00:00:00Z",
"end_time": "2026-02-11T00:00:00Z",
"defect_type": "scratch"
}Response:
{
"executive_summary": "Analysis of 47 scratch defects...",
"hypotheses": [
{
"title": "Material Quality Issue - Batch MB-2026-0211",
"confidence": 0.87,
"why": ["85% of scratches occurred on units from batch MB-2026-0211"],
"evidence_uris": ["s3://evidence/..."],
"tests_to_confirm": ["Visual inspection of remaining batch material"]
}
],
"action_plan": {
"immediate": ["Hold batch MB-2026-0211 for QA review"],
"short_term": ["Contact supplier about material specification"],
"preventive": ["Add automated surface roughness measurement"]
},
"pdf_url": "https://d123.cloudfront.net/reports/...",
"requires_human_review": true,
"metadata": { ... }
}Health check endpoint.
Full API docs: http://localhost:8000/docs (when running locally)
./scripts/deploy-staging.shDeploys to us-east-1 with mock provider (no production data).
Guide: docs/runbooks/STAGING_BACKEND.md
Production deployment uses API Gateway + Lambda in us-west-2 with real DynamoDB access.
Note: Production deployment is NOT part of this repo cleanup. See separate IaC repository.
IntelBase (React) consumes this API via feature flag:
const CLOSED_LOOP_API_BASE = import.meta.env.VITE_CLOSED_LOOP_API_BASE;Guide: docs/runbooks/INTEGRATION_WITH_INTELBASE.md
./scripts/run_local.sh./scripts/test.sh./scripts/format.shpython -m compileall backend/app-
Architecture
-
Runbooks
- No writes to production tables (Inspections, Defects, Evidence)
- No mutations of edge runtime configuration
- No direct equipment control
- Time windows: 1-30 days max
- Row limits: 10,000 events max per query
- No full table scans
- Bedrock: IAM role with
bedrock:InvokeModelonly - DynamoDB: IAM role with
dynamodb:Queryanddynamodb:GetItemonly - S3: IAM role with
s3:PutObjectfor reports bucket only
This system does NOT:
- ❌ Control equipment directly
- ❌ Modify production data
- ❌ Replace human decision-making
- ❌ Provide real-time alerts
- ❌ Store sensitive PII
- Format:
black+ruff - Type hints: Required for public APIs
- Docstrings: Google style
- Unit tests:
pytest - Coverage: > 80%
- Integration tests: Mock providers only
- Conventional commits:
feat:,fix:,docs:, etc. - Sign commits:
git commit -S
MIT-0 (see LICENSE)
- Issues: GitHub Issues
- Docs: docs/
- Slack: #intelfactor-closed-loop (internal)
Built with ❤️ for Manufacturing Excellence