# 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 Juristische OCR- & Problemklassifikationsplattform – XXL Monolith

Juristische OCR- & Problemklassifikationsplattform – XXL

Upload · OCR · Problemextraktion · A–Z-Problemtypen · Juristische/Notarielle Analyse · Gesetzgebung · Risiko · Lösungsengine

1. Dokument-Upload & OCR

Unterstützt Bilddateien (PNG, JPG). PDFs können vorbereitet werden (PDF‑OCR‑Hook vorhanden, Demo: Hinweis).

OCR-Rohtext

Manuelle Analyse starten

Erkannte Problemstellungen (Kurzliste)

2. Analyse, Klassifikation & Lösung

2.1 Problemklassen (juristisch / systemisch)

2.2 A–Z-Problemtypen



    

2.3 Juristische Analyse


      

2.4 Notarielle / Gesetzliche Bewertung


      

2.5 Lösungsengine (Anspruch, Risiko, Handlung)



    

2.6 Statistische Übersicht

2.7 Debug-Ansicht (interne Struktur)


  
``` --- ## API & External Dependencies ### Tesseract.js CDN - **URL**: https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js - **Version**: 5.x - **Purpose**: OCR text recognition - **Languages**: German (deu) + English (eng) - **Browser Support**: Modern browsers with WebAssembly support ### No Server-Side Dependencies - Pure client-side application - No backend required - No database needed - No authentication system --- ## Deployment & Setup ### Local Development 1. Clone or copy the project directory 2. Open `index.html` in a modern browser 3. Or use a local server: ```bash python -m http.server 8080 # or npx serve ``` ### Production Deployment - **Static Hosting**: Any static file hosting service - Netlify, Vercel, GitHub Pages, AWS S3 + CloudFront - **CDN**: Tesseract.js loads from public CDN - **No Build Process**: Single HTML file, no compilation needed ### Browser Compatibility - Chrome/Edge 90+ - Firefox 88+ - Safari 14+ - Opera 76+ --- ## Testing & Validation ### Manual Testing Checklist - [ ] File upload (PNG, JPG) - [ ] OCR processing with Tesseract.js - [ ] Text analysis with legal category detection - [ ] Problem type classification - [ ] Legal rule lookup - [ ] Risk score calculation - [ ] Solution engine output - [ ] Statistical overview rendering - [ ] Debug view JSON output - [ ] PDF handling guidance ### Error Scenarios Handled - Missing file selection - PDF upload (demo limitation) - OCR processing errors - Empty text analysis - Missing DOM elements (validation) ### Mathematical Validation - Risk score: `Math.min(100, detectedCategories.length * 8 + problems.length * 10)` - Maximum: 100 (capped) - Categories: 8 points each - Problems: 10 points each - Counter increments: `problemCounter++` (verified) - Array operations: All standard JavaScript array methods (verified) --- ## Future Extensions ### Planned Features 1. **PDF OCR Integration** - PDF.js for PDF rendering - Page-by-page OCR processing - Multi-page document handling 2. **Enhanced NLP** - Machine learning-based classification - Named entity recognition - Sentiment analysis 3. **Legal Database API** - German law database integration - Real-time paragraph references - Court decision matching 4. **User Management** - Authentication system - Document history - Collaboration features 5. **Export Options** - PDF report generation - Word document export - JSON data export 6. **Multi-language Support** - English interface - Additional OCR languages - International law databases ### Technical Improvements - Progressive Web App (PWA) capabilities - Offline support with Service Workers - IndexedDB for local storage - Web Workers for parallel processing - TypeScript migration for type safety --- ## Maintenance & Support ### Code Quality - **Lines of Code**: 706 (single file) - **Functions**: 12 main functions - **Data Structures**: 3 main arrays/objects - **Event Listeners**: 2 (file input, OCR button, analyze button) ### Performance Considerations - OCR processing: Browser-based, may be slow for large documents - Memory: In-memory data storage (no persistence) - Network: Single CDN dependency for Tesseract.js ### Security Notes - Client-side only (no server-side processing) - No data transmission to external servers (except CDN) - No authentication required - Suitable for sensitive documents (local processing) --- ## Contact & Support **Project Status**: Production Ready (Demo Version) **Last Updated**: 2026-05-19 **Version**: 1.0 **License**: Proprietary (Internal Use) --- ## Appendix: Quick Reference ### Key Functions - `analyzeText(text)`: Main analysis pipeline - `classifyProblemTypes(sentence)`: Problem type classification - `detectModulesForSentence(sentence, categories)`: Module recommendation - `renderAll(analysis)`: UI update orchestration ### Data Structures - `problemCategories`: 25 legal categories with keywords - `legalRules`: 10 legal rule sets with laws and actions - `problemTypePatterns`: 10 A-Z problem type patterns ### Risk Score Formula ``` riskScore = min(100, (categories × 8) + (problems × 10)) ``` --- **End of Developer Documentation**