How hectorta1989/test works
1. Purpose and Runtime Shape
SkillTwin VN is a factory knowledge-transfer MVP: capture expert know-how into versioned SOPs, approve them, then deliver RAG Q&A and guided checklist execution with photo evidence and expert review. It is a Next.js client dashboard backed by a FastAPI API and SQLite/SQLAlchemy persistence.
Entry points: backend/app/main.py starts FastAPI and wires routers; frontend/pages/_app.tsx initializes the Pages Router client; backend/seed.py provisions demo data.
2. API, Identity, and Organization Boundary
FastAPI routers provide the system boundary for the frontend and enforce authenticated, role-based workflows. JWT/password handling and RBAC dependencies establish organization- and role-scoped access for admin, expert, and worker actions.
Paths: backend/app/api/routers/auth.py, backend/app/core/security.py, backend/app/core/deps.py.
The frontend uses a typed API client and auth context rather than server-side Next.js actions: frontend/lib/api.ts, frontend/lib/auth.tsx.
3. Core Domain and Approval Lifecycle
The relational domain models organizations, users, processes, SOPs/SOP versions, chat, learning, audit events, kill switches, and execution runs. SOPs are created as drafts, edited/versioned, submitted, then explicitly approved or rejected by experts. Only approved SOP content becomes operational knowledge.
Paths: backend/app/models/models.py, backend/app/api/routers/sops.py, backend/app/api/routers/processes.py.
The SOP UI is split between the library and per-SOP editor: frontend/pages/sops/index.tsx, frontend/pages/sops/[id].tsx, frontend/components/RecipeEditor.tsx.
4. Knowledge Capture and Generation Boundary
Capture converts technician transcript/audio input into a structured draft SOP. Generation uses a transparent provider chain—Gemini, then Groq, then deterministic templates—and records generation method/model rather than presenting fallback output as AI-generated.
Paths: backend/app/api/routers/capture.py, backend/app/services/capture_service.py, backend/app/services/llm_service.py.
This boundary also supports SOP-derived quizzes, avoiding unsupported external knowledge: backend/app/services/quiz_service.py, backend/app/api/routers/quiz.py.
5. Approved-SOP RAG and AI Governance
Chat retrieves only approved SOP material using local TF-IDF and returns citations plus an escalation path when no source, low confidence, or AI disablement applies. It does not depend on an embeddings service.
Paths: backend/app/services/rag_service.py, backend/app/api/routers/chat.py, frontend/pages/chat.tsx.
An admin kill switch can disable AI generation per process or organization; audit logging captures AI recommendations and human decisions as append-only events.
Paths: backend/app/api/routers/admin.py, backend/app/services/audit_service.py, backend/app/models/models.py.
6. Guided Execution and Evidence Review
Workers execute an approved SOP as a stateful checklist, complete or skip steps, and upload required photo evidence. Evidence analysis is deliberately limited to classical image-quality checks—blur, brightness, and resolution—not defect detection. Expert reviewers make the actual accept/reject/invalid/needs-review decision.
Paths: backend/app/api/routers/execution.py, backend/app/services/execution_service.py, backend/app/services/evidence_service.py.
Corresponding worker and reviewer surfaces: frontend/pages/execution/index.tsx, frontend/pages/execution/review.tsx.
7. Learning and Operational Reporting
Quiz grading feeds skill-matrix updates using EMA-style scoring, with expert sign-off/override. Dashboard endpoints aggregate pilot KPIs and workflow activity rather than acting as a separate analytics platform.
Paths: backend/app/services/skill_service.py, backend/app/api/routers/skills.py, backend/app/api/routers/dashboard.py.
Material infrastructure: SQLite via backend/app/core/database.py; local-disk evidence storage for the MVP; optional Gemini and Groq external LLM APIs configured through backend/app/core/config.py.
Main entry points: models.py Versioned Domain Models · security.py JWT & RBAC · capture_service.py Draft SOP Capture · execution_service.py Stateful Checklist Runs
Components 21
Next.js Dashboard
- Pages Router App
frontend/pages/_app.tsx - Auth Context & API Client
frontend/lib/auth.tsx - SOP Library & Editor
frontend/pages/sops/[id].tsx - RAG Chat
frontend/pages/chat.tsx - Worker & Review Screens
frontend/pages/execution/review.tsx
FastAPI Boundary
- FastAPI App · Wires workflow routers.
backend/app/main.py - JWT & RBAC · Scopes actions by organization and role.
backend/app/core/security.py - SOP & Process API
backend/app/api/routers/sops.py - Capture API
backend/app/api/routers/capture.py - Chat API
backend/app/api/routers/chat.py - Execution API
backend/app/api/routers/execution.py - Admin & Reporting API
backend/app/api/routers/admin.py
Domain Services
- Draft SOP Capture · Turns transcript or audio input into structured drafts.
backend/app/services/capture_service.py - Provider Fallback Chain · Gemini, then Groq, then deterministic templates.
backend/app/services/llm_service.py - Approved-SOP RAG · Cites approved SOPs and escalates uncertain answers.
backend/app/services/rag_service.py - Stateful Checklist Runs
backend/app/services/execution_service.py - Image Quality Checks · Checks blur, brightness, and resolution only.
backend/app/services/evidence_service.py
Persistence & External
- Versioned Domain Models · Contains SOP lifecycle, runs, skills, audit events, and kill switches.
backend/app/models/models.py - SQLite Database
backend/app/core/database.py - Local Evidence Storage
- Gemini & Groq · Optional providers configured for generation.
backend/app/core/config.py
Connections 22
- Pages Router App → Auth Context & API Client: initializes
- Auth Context & API Client → FastAPI App: typed authenticated calls
- SOP Library & Editor → SOP & Process API: manage drafts and approval
- RAG Chat → Chat API: ask cited questions
- Worker & Review Screens → Execution API: run and review evidence
- FastAPI App → JWT & RBAC: enforces access
- JWT & RBAC → SOP & Process API: authorizes roles
- JWT & RBAC → Execution API: authorizes roles
- SOP & Process API → Versioned Domain Models: versions and approves SOPs
- Capture API → Draft SOP Capture: creates draft
- Draft SOP Capture → Provider Fallback Chain: generates structured content
- Provider Fallback Chain → Gemini & Groq: uses when available
- Draft SOP Capture → Versioned Domain Models: stores draft and method
- Chat API → Approved-SOP RAG: answers questions
- Approved-SOP RAG → Versioned Domain Models: retrieves approved SOPs only
- Admin & Reporting API → Versioned Domain Models: sets kill switches and audits
- Execution API → Stateful Checklist Runs: advances checklist state
- Stateful Checklist Runs → Image Quality Checks: validates uploads
- Image Quality Checks → Local Evidence Storage: stores photos
- Stateful Checklist Runs → Versioned Domain Models: records runs and decisions
- Versioned Domain Models → SQLite Database: persists through
- Admin & Reporting API → Provider Fallback Chain: controls AI availability