1. Dokument-Upload & OCR
Unterstützt Bilddateien (PNG, JPG). PDFs können vorbereitet werden (PDF‑OCR‑Hook vorhanden, Demo: Hinweis).
# Juristische OCR- & Problemklassifikationsplattform – XXL Monolith ## Developer Documentation & Technical Architecture --- ## Table of Contents 1. [Project Overview](#project-overview) 2. [Technical Architecture](#technical-architecture) 3. [Technology Stack](#technology-stack) 4. [Module Structure](#module-structure) 5. [Data Models](#data-models) 6. [Complete Source Code](#complete-source-code) 7. [API & External Dependencies](#api--external-dependencies) 8. [Deployment & Setup](#deployment--setup) 9. [Testing & Validation](#testing--validation) 10. [Future Extensions](#future-extensions) --- ## Project Overview **Project Name:** Juristische OCR- & Problemklassifikationsplattform – XXL Monolith **Version:** 1.0 **Language:** German (DE) **Type:** Single-Page Application (SPA) **Purpose:** Legal document OCR processing, problem classification, and automated legal analysis ### Core Features - Document upload (PNG, JPG, PDF support planned) - OCR text extraction using Tesseract.js - Legal problem category detection (25+ categories) - A-Z problem type classification - Legal rule engine with German law references - Notarial analysis module - Risk assessment scoring - Solution engine with actionable recommendations - Statistical overview and debug interface --- ## Technical Architecture ### System Architecture Diagram ``` ┌─────────────────────────────────────────────────────────────────┐ │ CLIENT BROWSER LAYER │ ├─────────────────────────────────────────────────────────────────┤ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ HTML UI │ │ CSS │ │ JavaScript │ │ │ │ (2-column) │ │ (Grid/Flex) │ │ (Logic) │ │ │ └──────────────┘ └──────────────┘ └──────────────┘ │ └─────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ EXTERNAL DEPENDENCIES │ ├─────────────────────────────────────────────────────────────────┤ │ ┌──────────────────────────────────────────────────────────┐ │ │ │ Tesseract.js (CDN) - OCR Engine │ │ │ │ - German + English language support │ │ │ │ - Browser-based text recognition │ │ │ └──────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ APPLICATION LOGIC LAYER │ ├─────────────────────────────────────────────────────────────────┤ │ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────┐ │ │ │ File Handler │ │ OCR Processor │ │ Text Analyzer│ │ │ │ - Upload │ │ - Tesseract │ │ - NLP (basic) │ │ │ │ - Validation │ │ - Text extraction│ │ - Pattern │ │ │ └──────────────────┘ └──────────────────┘ │ matching │ │ │ └──────────────┘ │ │ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────┐ │ │ │ Classifier │ │ Legal Rules │ │ Risk Engine │ │ │ │ - Categories │ │ - Law database │ │ - Scoring │ │ │ │ - Problem types │ │ - Actions │ │ - Assessment │ │ │ └──────────────────┘ └──────────────────┘ └──────────────┘ │ └─────────────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ DATA LAYER (In-Memory) │ ├─────────────────────────────────────────────────────────────────┤ │ - problemCategories (25+ legal categories) │ │ - legalRules (law references & actions) │ │ - problemTypePatterns (A-Z classification) │ │ - currentFile (uploaded file reference) │ │ - lastAnalysis (analysis results cache) │ └─────────────────────────────────────────────────────────────────┘ ``` ### Data Flow ``` User Upload File → File Validation → OCR Processing → Text Extraction │ ▼ Text Analysis → Category Detection → Problem Classification → Module Detection │ ▼ Risk Scoring → Legal Rule Lookup → Solution Generation → UI Rendering ``` --- ## Technology Stack ### Frontend - **HTML5**: Semantic markup, single-file architecture - **CSS3**: Grid layout, responsive design, modern styling - **Vanilla JavaScript (ES6+)**: No frameworks, pure DOM manipulation ### External Libraries - **Tesseract.js v5**: OCR engine (CDN: jsdelivr.net) - German + English language support - Browser-based, no server required ### Browser Requirements - Modern browser with ES6+ support - JavaScript enabled - Canvas support (for Tesseract.js) --- ## Module Structure ### 1. Data Models & Taxonomies (Lines 198-288) #### problemCategories Array 25+ legal problem categories with keyword matching: - Contract Law, Labor Law, Tenancy Law, Criminal Law - Data Protection, Corporate Law, Tax Law, Social Law - Family Law, Inheritance Law, Notarial Claims - Insolvency Law, Administrative Law, EU Law - IT Law, Competition Law, Trademark Law, Patent Law - Insurance Law, Environmental Law, Construction Law - Transport Law, Commercial Law, Constitutional Law, International Law #### legalRules Object Legal rule engine with: - **Laws**: Relevant German law references (BGB, StGB, DSGVO, etc.) - **Actions**: Recommended procedural steps for each category #### problemTypePatterns Array A-Z problem classification heuristics: - Calculation problems, Evaluation problems, Decision problems - Optimization problems, Analysis problems, Classification problems - Validation problems, Risk problems, Goal achievement problems - Transformation problems ### 2. DOM References & Validation (Lines 290-328) #### DOM Elements 14 required UI elements with validation: - Input: fileInput - Buttons: runOcrBtn, analyzeBtn - Status: ocrStatus, analyzeStatus - Output: ocrOutput, problemTags, legalAnalysis, notarialAnalysis - Views: solutionEngine, statsView, debugView, problemTypesView, problemList #### Validation Logic Runtime validation ensures all DOM elements exist before execution. ### 3. File Handling & OCR Module (Lines 330-377) #### File Input Handler - Accepts image/* and .pdf files - Validates file selection - Provides PDF conversion guidance (demo limitation) #### OCR Processor - Uses Tesseract.js with German+English language - Async/await pattern for worker management - Error handling with user feedback - Button state management during processing ### 4. Text Analysis Engine (Lines 379-514) #### analyzeText() Function Core analysis pipeline: 1. **Category Detection**: Keyword matching against 25+ legal categories 2. **Sentence Splitting**: Regex-based sentence segmentation 3. **Problem Extraction**: Pattern matching for task verbs (berechnen, prüfen, etc.) 4. **Type Classification**: A-Z problem type assignment 5. **Module Detection**: Context-aware module recommendation 6. **Risk Scoring**: Heuristic risk calculation (0-100 scale) #### Helper Functions - **splitIntoSentences()**: Text segmentation - **classifyProblemTypes()**: Pattern-based classification - **detectModulesForSentence()**: Context-aware module recommendation - **aggregateCounts()**: Statistical aggregation ### 5. Rendering Layer (Lines 516-703) #### renderAll() Function Orchestrates all UI updates: - Tag rendering for categories - Problem type display - Legal analysis output - Notarial assessment - Solution engine results - Statistical tables - Debug JSON view - Problem list table #### Individual Render Functions - **renderTags()**: Category tag display - **renderProblemTypes()**: A-Z type aggregation - **renderLegalAnalysis()**: Law reference lookup - **renderNotarialAnalysis()**: Notarial relevance check - **renderSolutionEngine()**: Actionable recommendations - **renderStats()**: Statistical overview - **renderDebug()**: JSON debug output - **renderProblemList()**: Detailed problem table --- ## Data Models ### Analysis Result Object ```javascript { detectedCategories: string[], // Detected legal categories problems: Problem[], // Extracted problem statements problemTypes: { [type: string ]: number }, // Type counts riskScore: number // 0-100 risk assessment } ``` ### Problem Object ```javascript { id: string, // "P1", "P2", etc. original: string, // Original sentence types: Type[], // Primary + secondary types modules: string[] // Recommended modules } ``` ### Type Object ```javascript { primary: string, // Main problem type secondary: string[] // Additional classifications } ``` --- ## Complete Source Code ### File: index.html (706 lines) ```html
Upload · OCR · Problemextraktion · A–Z-Problemtypen · Juristische/Notarielle Analyse · Gesetzgebung · Risiko · Lösungsengine
Unterstützt Bilddateien (PNG, JPG). PDFs können vorbereitet werden (PDF‑OCR‑Hook vorhanden, Demo: Hinweis).