Backend — pipeline nodes - xxriny/KNU-PROJECT GitHub Wiki

22개 파일, 노드 함수 15개 스키마 유틸로 구성돠어있습니다.

1. backend/pipeline/nodes/init.py

라인 코드 설명
(빈 파일) 패키지 초기화

2. backend/pipeline/nodes/atomizer.py

라인 코드 설명
3–6 AtomicRequirement Pydantic 스키마 — REQ_ID, category, description
8–13 AtomizerMetadata project_name, action_type, status, total_requirements
15–19 AtomizerOutput thinking_process, metadata, clarification_questions, atomic_requirements
22–30 PM_SYSTEM_PROMPT MECE 기반 요구사항 분해 지시 상수
32–42 REVERSE_SYSTEM_PROMPT 역공학 모드 — 환각 방지 가드레일 포함

3. backend/pipeline/nodes/pm_phase1.py

라인 코드 설명
7–9 PM_SYSTEM_PROMPT CREATE/UPDATE 모드 PM 프롬프트 상수
36–65 REVERSE_SYSTEM_PROMPT REVERSE 모드 가드레일 프롬프트
68–138 atomizer_node() action_type 감지 → 모드별 프롬프트 선택 → call_structured(AtomizerOutput) LLM 호출 → requirements_rtm 저장

4. backend/pipeline/nodes/pm_phase2.py

라인 코드 설명
7–10 SYSTEM_PROMPT MoSCoW 우선순위 분류 지시
13–54 prioritizer_node() LLM에 Must/Should/Could 분류 지시, 실패 시 기본 우선순위 할당

5. backend/pipeline/nodes/pm_phase3.py

라인 코드 설명
20–27 SYSTEM_PROMPT 의존성 매핑 규칙 상수
30–62 _validate_dependency_quality() 자기참조, 존재하지 않는 ID, 빈 의존성 >20%, 순환참조 검출
65–184 rtm_builder_node() Self-Correction 루프 — 1차 LLM 호출 → 검증 → 불합격 시 피드백 포함 재시도

6. backend/pipeline/nodes/pm_phase4.py

라인 코드 설명
13–24 GRAPH_SYSTEM_PROMPT 시맨틱 그래프 생성 지시
27–35 _dedupe_semantic_edges() 양방향 관계 정규화 + 중복 엣지 제거
41–52 코드 매핑 스키마 _FuncMapping, _CodeMappingOutput — REQ_ID↔함수 매핑
54–59 CODE_MAPPING_SYSTEM_PROMPT 코드↔요구사항 시맨틱 링킹 지시
62–211 semantic_indexer_node() 지식 그래프 생성 + ast_scanner 소스 스캔 → 요구사항-코드 매핑 + ChromaDB 저장

7. backend/pipeline/nodes/pm_phase5.py

라인 코드 설명
15–19 SYSTEM_PROMPT 컨텍스트 명세서 생성 지시
22–48 _build_tech_stack_details() manifest 증거 기반 기술 스택 상세 빌드
50–97 _save_project_state_md() PROJECT_STATE.md 파일 → backend/Data/{timestamp}_{hash}_{name}_PROJECT_STATE.md 저장
100–392 context_spec_node() 롤링 컨텍스트 명세서 빌드 — 이전 SA 결과 + 사용자 프롬프트 합성

8. backend/pipeline/nodes/chat_revision.py

라인 코드 설명
9–54 Pydantic 스키마 RTMRevision(신규 항목), RTMRequirementPatch(부분 수정), ChatRevisionPatchOutput(added/modified/deleted 목록)
57–90 SYSTEM_PROMPT 패치 기반 수정 에이전트 지시(전체 재작성 금지)
93–149 chat_revision_node() 사용자 요청 → 범위 선택 → LLM 패치 생성 → RTM 인메모리 적용
160–317 내부 헬퍼 _normalize_rtm(), _normalize_semantic_graph(), _select_revision_context()(광범위/타겟 분기), _extract_req_ids(), _tokenize_request(), _build_adjacency(), _is_broad_revision_request()
320–407 패치 적용 _apply_revision_patch()(추가/수정/삭제 병합), _merge_context_spec()

9. backend/pipeline/nodes/idea_chat.py

라인 코드 설명
6–36 SYSTEM_PROMPT PM AI 어시스턴트 — 아이디어 발전 + 분석 준비 감지
39–100 idea_chat_node() 대화형 아이디어 발산 → parse_json_safe() 응답 파싱 + 텍스트 폴백 → idea_ready 플래그 반환

10. backend/pipeline/nodes/sa_phase1.py

라인 코드 설명
8–15 SAPhase1LLMOutput 코드 분석 출력 스키마(thinking, status, confidence, assessment, modules, concerns)
17–29 SYSTEM_PROMPT SA 아키텍트 코드 구조 분석 지시
32–42 _safe_read_text() 인코딩 오류 방어 파일 읽기
45–163 _detect_framework_evidence() package.json/requirements.txt/pyproject.toml 파싱 → 프레임워크 감지
166–194 _build_representative_function_sample() 대표 함수 샘플 선발(LLM 입력 크기 제한)
197–354 sa_phase1_node() 프로젝트 전체 AST 스캔 → 프레임워크 감지 → LLM 아키텍처 평가

11. backend/pipeline/nodes/sa_phase2.py

라인 코드 설명
7–17 스키마 RequirementImpact(req_id, impact_level, change_type, side_effects), GapReportOutput
19–23 IMPACT_SYSTEM_PROMPT 요구사항별 영향 분석 지시
25–91 sa_phase2_node() 시맨틱 그래프에서 touched files 추출 → 갭 리포트(충족 불가 요구사항 식별)

12. backend/pipeline/nodes/sa_phase3.py

라인 코드 설명
12–17 FeasibilityOutput 타당성 스키마(status, complexity_score, reasons, alternatives, high_risk_reqs)
19–75 시스템 프롬프트 CREATE/REVERSE 모드별 타당성 평가 지시문
78–92 _validate_rtm_schema() RTM 구조 + REQ_ID 존재 검증
97–199 핸들러 + 노드 _handle_reverse()(역분석 위임), _handle_create_update()(LLM 타당성), sa_phase3_node()(디스패처)

13. backend/pipeline/nodes/sa_phase3_reverse.py

라인 코드 설명
18–55 스키마 ReverseEvidence(scanned_files, frameworks, test 존재, observability 등), ReverseAssessment
59–174 내부 헬퍼 _validate_phase1_readiness(), _safe_read_text(), _path_exists(), _grep_any(root, tokens)(임의 토큰 검색), _detect_tests(), _clamp_score(), _append_unique()
177–309 증거 수집 + 평가 _collect_reverse_evidence()(코드 시그널 수집), _assess_reverse_maintainability()(규칙 기반 점수화)
312–397 assess_reverse() 역공학 유지보수성 평가 메인 함수

14. backend/pipeline/nodes/sa_phase4.py

라인 코드 설명
8–10 PackageExtractionOutput 패키지 추출 스키마(thinking, proposed_packages)
24–60 PyPI 검증 _verify_pypi_package()(HEAD 요청), _verify_pypi_packages_parallel()(ThreadPoolExecutor 4워커, 4초 타임아웃)
63–118 sa_phase4_node() 기술 스택 → PyPI 패키지 추출 + 존재 검증

15. backend/pipeline/nodes/sa_phase5.py

라인 코드 설명
10–102 sa_phase5_node() Clean Architecture 4레이어(Presentation/Application/Domain/Infrastructure) 매핑 — LLM 매핑 + score_layers() 휴리스틱 폴백

16. backend/pipeline/nodes/sa_phase5_schemas.py

라인 코드 설명
7–18 매핑 스키마 RequirementMapping(REQ_ID, layer, reason), ArchitectureMappingOutput(thinking, pattern_name, mapped_requirements)
21–32 모듈 라벨 스키마 ModuleFunctionalLabel(canonical_id, functional_name), ModuleLabelBatchOutput
36–73 시스템 프롬프트 MAPPING_SYSTEM_PROMPT(레이어 매핑), MODULE_LABEL_SYSTEM_PROMPT(한국어 기능명)

17. backend/pipeline/nodes/sa_phase6.py — @pipeline_node 사용

라인 코드 설명
8–31 보안 스키마 RoleDefinition, AuthzMatrixItem(restriction_level: Public/Authenticated/Authorized/InternalOnly), TrustBoundary, SecurityDesignOutput
33–42 SECURITY_SYSTEM_PROMPT RBAC + Trust Boundary 설계 지시
46–133 sa_phase6_node() @pipeline_node("sa_phase6") 데코레이터, NodeContext 수신 — RBAC 역할 정의, AuthZ 매트릭스, Trust Boundaries 생성

18. backend/pipeline/nodes/sa_phase7.py

라인 코드 설명
7–22 스키마 InterfaceContract(contract_id, layer, interface_name, input_spec, output_spec, error_handling), Phase7Output(interface_contracts, guardrails)
24–35 INTERFACE_SYSTEM_PROMPT 모듈 간 통신 계약 + 개발 가드레일 지시
38–137 sa_phase7_node() phase5/6 결과 기반 인터페이스 계약 + 보안/무결성 가드레일 생성

19. backend/pipeline/nodes/sa_phase8.py

라인 코드 설명
10–41 상수 TOKEN_ALIASES, TOKEN_STOPWORDS, LOW_SIGNAL_TOKENS, MIN_CANONICAL_CONFIDENCE(0.65)
49–130 의존성 유틸 _extract_contract_tokens(), _collect_contract_token_frequency(), _is_cross_cutting_contract(), _calculate_dependency_confidence(), _parse_req_id_from_contract(), _normalize_module_path(), _module_aliases()
133–227 의존성 합성 _synthesize_import_dependencies()(코드 import 힌트), _synthesize_dependencies()(explicit + semantic + data-flow 통합)
230–266 _topo_sort_with_batches() BFS 기반 위상 정렬 + 병렬 배치 분리(Kahn's algorithm)
269–405 sa_phase8_node() 4종 의존성 소스 통합 → 위상 정렬 → 실행 순서 + sa_output 전체 SA 페이즈 집계

20. backend/pipeline/nodes/sa_reverse_context.py

라인 코드 설명
9–44 내부 헬퍼 _top_frameworks(), _layer_distribution(), _top_low_confidence_modules(), _module_name()
47–106 sa_reverse_context_node() REVERSE 전용 — 프레임워크·레이어·위상·리스크·다음 단계 통합 요약 생성

21. backend/pipeline/nodes/sa_reverse_module.py

라인 코드 설명
9–114 build_reverse_module_profiles() AST 스캔 기반 모듈 프로파일 생성(파일 수, 함수 수, import 관계)
117–143 batch_label_modules() LLM 일괄 호출 → 모듈별 한국어 기능 라벨 자동 부여
146–262 build_reverse_module_mapping() sa_phase1 프로파일 → 아키텍처 매핑 요구사항(MOD-001 등) + confidence 점수

22. backend/pipeline/nodes/sa_layer_heuristics.py

라인 코드 설명
6–31 상수 LAYER_ORDER(4레이어), LAYER_KEYWORDS(키워드→레이어), FRAMEWORK_LAYER_HINTS, BACKEND_FRAMEWORKS, FRONTEND_FRAMEWORKS, MODULE_SIGNAL_HINTS, LAYER_BY_CATEGORY
43–127 유틸 함수 infer_layer_from_path(), tokenize_text(), normalize_module_path(), canonical_module_id(), framework_scope_map(), module_family()(backend/frontend/electron 분류), _path_is_close(), scoped_frameworks_for_module()
181–282 score_layers() 30+ 시그널 기반 다중 점수화 → 최고 점수 레이어 + confidence + evidence 반환
285–297 fallback_mapping_info() LLM 실패 시 폴백 레이어 매핑 정보