# PROJECT_CONTEXT.md ## 🎯 Project Overview **ExperionCrawler**λŠ” μ‹ μ•”μ •μœ  전곡μž₯의 μ œμ–΄ μ‹œμŠ€ν…œμΈ **Honeywell Experion HS R530**μœΌλ‘œλΆ€ν„° μ‹€μ‹œκ°„ 데이터λ₯Ό μˆ˜μ§‘, μ €μž₯, λΆ„μ„ν•˜μ—¬ μ§€λŠ₯ν˜• 운영 ν™˜κ²½μ„ μ œκ³΅ν•˜λŠ” μ‹œμŠ€ν…œμž…λ‹ˆλ‹€. OPC UAλ₯Ό 톡해 데이터λ₯Ό νšλ“ν•˜λ©°, RAG(Retrieval-Augmented Generation)와 MCP(Model Context Protocol)λ₯Ό κ²°ν•©ν•˜μ—¬ LLM이 곡정 데이터λ₯Ό μ΄ν•΄ν•˜κ³  운영 κ°€μ΄λ“œλ₯Ό μ œκ³΅ν•  수 μžˆλ„λ‘ μ„€κ³„λ˜μ—ˆμŠ΅λ‹ˆλ‹€. ## πŸ—οΈ System Architecture ν”„λ‘œμ νŠΈλŠ” **Clean Architecture** νŒ¨ν„΄μ„ λ”°λ₯΄λ©°, `src/` 디렉토리 λ‚΄μ˜ μ„Έ κ³„μΈ΅μœΌλ‘œ κ΅¬μ„±λ©λ‹ˆλ‹€. (`Core`와 `Infrastructure`λŠ” `Web` ν”„λ‘œμ νŠΈμ— ν¬ν•¨λ˜μ–΄ λΉŒλ“œλ©λ‹ˆλ‹€.) ### 1. Core Layer (`src/Core/`) * **Domain/Entities:** λ°μ΄ν„°λ² μ΄μŠ€ μ—”ν‹°ν‹° 및 도메인 λͺ¨λΈ. * **Application/Interfaces:** λͺ¨λ“  μ„œλΉ„μŠ€μ˜ 계약(`IExperionServices.cs`). * **Application/Services:** λΉ„μ¦ˆλ‹ˆμŠ€ 둜직 κ΅¬ν˜„ (예: `TextToSqlService`, `PidGraphService`). * **Application/DTOs:** API 및 μ„œλΉ„μŠ€ κ°„ 데이터 전솑 객체. ### 2. Infrastructure Layer (`src/Infrastructure/`) * **OpcUa/:** OPC UA ν΄λΌμ΄μ–ΈνŠΈ/μ„œλ²„ 둜직 및 μ‹€μ‹œκ°„ 데이터 처리. * **Database/:** Entity Framework Core 및 PostgreSQL/TimescaleDB 연동. * **Mcp/:** Python 기반 MCP μ„œλ²„μ™€μ˜ 톡신을 μœ„ν•œ λΈŒλ¦Ώμ§€ (JSON-RPC over HTTP). * **Kb/:** Qdrant 기반 지식 베이슀(Knowledge Base) 관리. ### 3. Web Layer (`src/Web/`) * **Program.cs:** μ˜μ‘΄μ„± μ£Όμž…(DI) 및 λ°±κ·ΈλΌμš΄λ“œ μ„œλΉ„μŠ€(HostedServices) μ˜€μΌ€μŠ€νŠΈλ ˆμ΄μ…˜. * **Controllers/:** 단일 파일(`ExperionControllers.cs`)둜 κ΅¬μ„±λœ API μ—”λ“œν¬μΈνŠΈ. * **wwwroot/:** λΉŒλ“œ 단계가 μ—†λŠ” Vanilla JS SPA. ## βš™οΈ Critical Operational Semantics ### ⏰ Timezone & Time Handling * **Storage:** λͺ¨λ“  λ°μ΄ν„°λ² μ΄μŠ€ νƒ€μž„μŠ€νƒ¬ν”„λŠ” **UTC**둜 μ €μž₯λ©λ‹ˆλ‹€. * **Presentation:** LLM 및 μ‚¬μš©μžμ—κ²Œ 전달될 λ•ŒλŠ” λ°˜λ“œμ‹œ **KST (UTC+9)**둜 λ³€ν™˜λ˜μ–΄μ•Ό ν•©λ‹ˆλ‹€. ### ⏳ Event Duration Semantics * **`event_history_table.duration_seconds`**: 이 ν•„λ“œλŠ” **"직전 μƒνƒœκ°€ μœ μ§€λœ μ‹œκ°„(초)"**을 μ˜λ―Έν•©λ‹ˆλ‹€. ν˜„μž¬ 이벀트의 지속 μ‹œκ°„μ΄ μ•„λ‹˜μ— μ£Όμ˜ν•˜μ‹­μ‹œμ˜€. ### πŸ”‘ JSON Naming Convention (CRITICAL) * **Backend:** `PropertyNamingPolicy = null` μ„€μ •μœΌλ‘œ 인해 C#의 PascalCaseκ°€ JSON ν‚€λ‘œ κ·ΈλŒ€λ‘œ μ „λ‹¬λ©λ‹ˆλ‹€. * **Frontend:** ν”„λ‘ νŠΈμ—”λ“œλŠ” **camelCase**λ₯Ό κΈ°λŒ€ν•©λ‹ˆλ‹€. * **Rule:** λͺ¨λ“  Controller의 `Ok(...)` 응닡 μ‹œ, λ°˜λ“œμ‹œ **읡λͺ… 객체λ₯Ό μ‚¬μš©ν•˜μ—¬ λͺ…μ‹œμ μœΌλ‘œ camelCase ν‚€λ₯Ό μ§€μ •**ν•΄μ•Ό ν•©λ‹ˆλ‹€. * βœ… `return Ok(new { id = x.Id, tagName = x.TagName });` * ❌ `return Ok(new { x.Id, x.TagName });` ## πŸ”„ Background Services (HostedServices) | Service | Responsibility | | :--- | :--- | | `ExperionRealtimeService` | OPC UA ꡬ독 및 500ms λ‹¨μœ„ 데이터 DB ν”ŒλŸ¬μ‹œ | | `ExperionHistoryService` | 60초 μ£ΌκΈ° `realtime_table` β†’ `history_table` μŠ€λƒ…μƒ· | | `ExperionOpcServerService` | 둜컬 데이터λ₯Ό OPC UA μ„œλ²„(Port 4841)둜 λ…ΈμΆœ | | `McpServerHostedService` | Python MCP μ„œλ²„ ν”„λ‘œμ„ΈμŠ€ 생λͺ…μ£ΌκΈ° 관리 | | `ExperionFastService` | 고주파 데이터 캑처 μ„Έμ…˜ 관리 | | `ExperionFastCleanupService` | 만료된 Fast μ„Έμ…˜ 정리 | ## πŸ› οΈ Development & Deployment ### Build & Test * **Build:** `dotnet build src/Web/ExperionCrawler.csproj` * **Run (Dev):** `dotnet run` (Working Dir: `src/Web/`) * **Test:** `dotnet test` * **Lint/Typecheck:** (μ‚¬μš©μž 제곡 μ‹œ μ‹€ν–‰ ν•„μˆ˜) ### Deployment * **Command:** `sudo bash deploy.sh` * **Target:** `/opt/ExperionCrawler` * **Service:** `systemd` μ„œλΉ„μŠ€ `experioncrawler`둜 μ‹€ν–‰ (User: `www-data`) ## πŸ€– Agent Operational Guidelines 1. **Verification:** μ½”λ“œ μˆ˜μ • ν›„μ—λŠ” λ°˜λ“œμ‹œ ν”„λ‘œμ νŠΈμ˜ Lint 및 Typecheck λͺ…λ Ήμ–΄λ₯Ό μ‹€ν–‰ν•˜μ—¬ 무결성을 κ²€μ¦ν•˜μ‹­μ‹œμ˜€. 2. **Search First:** μƒˆλ‘œμš΄ κΈ°λŠ₯을 κ΅¬ν˜„ν•˜κ±°λ‚˜ 버그λ₯Ό μˆ˜μ •ν•˜κΈ° μ „, λ°˜λ“œμ‹œ `Grep`κ³Ό `Glob`을 μ‚¬μš©ν•˜μ—¬ κΈ°μ‘΄ νŒ¨ν„΄κ³Ό μ»¨λ²€μ…˜μ„ ν™•μΈν•˜μ‹­μ‹œμ˜€. 3. **Data Integrity:** DB 쿼리 μ‹œ `duration_seconds`의 μ˜λ―Έμ™€ μ‹œκ°„λŒ€ λ³€ν™˜ κ·œμΉ™μ„ 항상 염두에 λ‘μ‹­μ‹œμ˜€. 4. **Commit Policy:** μ‚¬μš©μžμ˜ λͺ…μ‹œμ  μš”μ²­μ΄ μ—†λŠ” ν•œ μ ˆλŒ€ `git commit`을 μˆ˜ν–‰ν•˜μ§€ λ§ˆμ‹­μ‹œμ˜€.