# Technical Context ## Development Environment - macOS Application - Swift & SwiftUI - Xcode 14+ - Target: macOS 12.3+ ## Core Technologies 1. Vision Framework - VNDetectRectanglesRequest for board detection - VNCoreMLRequest for piece classification - VNImageRequestHandler for image processing 2. Core ML Model - Name: ChessPieceClassifier.mlmodel - Input: RGB/RGBA images - Output: Classification label - Categories (exact names): ```swift white_pawn, white_knight, white_bishop, white_rook, white_queen, white_king, black_pawn, black_knight, black_bishop, black_rook, black_queen, black_king ``` 3. ScreenCaptureKit - Window capture at 30 FPS - Configurable cursor visibility - Chess.com window detection ## Image Processing 1. Preprocessing Pipeline - Contrast enhancement (1.3x) - Edge sharpening - Noise reduction - Color normalization 2. Square Extraction - Aspect ratio validation - Size normalization - Center crop ## Model Integration 1. Loading ```swift let config = MLModelConfiguration() config.computeUnits = .all let model = try MLModel(contentsOf: modelURL) let vnModel = try VNCoreMLModel(for: model) ``` 2. Classification ```swift let request = VNCoreMLRequest(model: vnModel) request.imageCropAndScaleOption = .centerCrop ``` 3. Result Handling - Confidence threshold: 0.75 - Empty square fallback - Direct category mapping ## Dependencies - Foundation - Vision - CoreML - CoreImage - ScreenCaptureKit - SwiftUI ## Error Handling - Invalid dimensions - Model loading failures - Recognition errors - Low confidence results ## File Organization ``` ChessPrism/ ├── Models/ │ ├── SquareClassification.swift # Model output mapping │ └── ChessPosition.swift # Board state ├── Recognition/ │ ├── PieceRecognizer.swift # ML integration │ ├── FenGenerator.swift # Position encoding │ └── MoveDetector.swift # Move analysis └── Core/ ├── BoardDetector.swift # Square extraction └── ScreenCapture.swift # Window capture