# slim-down (doc2mk)

> Universele document-naar-Markdown converter & AI context optimizer. Converteer PDF, Word (.docx, .doc), Excel (.xlsx), CSV, JSON, HTML en YAML naar compacte, gestructureerde Markdown geoptimaliseerd voor LLM prompts en RAG contextvensters.

slim-down (ook bekend als doc2mk) is een snelle en betrouwbare Go-applicatie ontworpen om documenten en datastructuren te transformeren naar gestructureerde Markdown. Het verwijdert visuele ruis, overbodige XML/HTML tags en metadata, waardoor tot wel 60% op LLM context tokens bespaard wordt met behoud van semantische structuur.

## Kernfunctionaliteiten
- **PDF naar Markdown**: Extraheert paginastructuur, koppen, alinea's, tabellen en lijsten uit complexe PDF-documenten (inclusief PostScript CMap ondersteuning).
- **Office Documenten**: Converteert DOCX, DOC en Excel (.xlsx spreadsheets naar Markdown tabellen).
- **Gestructureerde Data & Web**: Converteert CSV, JSON, YAML en HTML naar nette Markdown tabellen, lijsten en gestructureerde documenten.
- **AI Token Optimalisatie**: Minimaliseert contextgrootte voor AI-modellen (zoals Claude, ChatGPT, Gemini, Copilot en Llama) en verbetert accuraatheid bij RAG (Retrieval-Augmented Generation).
- **Web Workspace (`/app`)**: Dual-pane editor met realtime Markdown preview, bestandsuploads, syntax highlighting en tokenstatistieken.
- **REST API**: Krachtige en lichte endpoints voor geautomatiseerde pipelines, scripts en AI-agents.

## Ondersteunde Formaten

### Invoerformaten (Source Formats)
- `pdf`: Portable Document Format (.pdf)
- `docx` / `doc`: Microsoft Word documenten (.docx, .doc)
- `excel` / `xlsx`: Microsoft Excel werkbladen (.xlsx)
- `csv`: Comma-Separated Values (.csv)
- `json`: JSON gegevensstructuren (.json)
- `yaml`: YAML documenten (.yaml, .yml)
- `html`: Webpagina's en HTML snippets (.html, .htm)
- `markdown`: Markdown (.md, .markdown)

### Doelformaten (Target Formats)
- `markdown` (standaard)
- `json`
- `csv`
- `yaml`
- `html`
- `excel` (.xlsx)

---

## API Referentie

De REST API accepteert zowel JSON payloads als multipart file uploads.

### 1. Tekst / Data Converteren
- **Endpoint**: `POST /api/convert`
- **Content-Type**: `application/json`
- **Request Body**:
  ```json
  {
    "input": "# Voorbeeld\nData...",
    "source_format": "auto",
    "target_format": "markdown",
    "options": {
      "pretty": true
    }
  }
  ```
- **Response**:
  ```json
  {
    "success": true,
    "converted": "# Geconverteerde Markdown...",
    "source_format": "json",
    "target_format": "markdown",
    "original_size": 1250,
    "converted_size": 420,
    "token_saving_percent": 58.4
  }
  ```

### 2. Bestanden Converteren (PDF, DOCX, XLSX, etc.)
- **Endpoint**: `POST /api/convert-file`
- **Content-Type**: `multipart/form-data`
- **Parameters**:
  - `file`: Het binaire bestand om te converteren (verplicht).
  - `target_format`: Gewenst doelformaat (optioneel, standaard `markdown`).
  - `save`: `"true"` om het document op te slaan in het gebruikersprofiel (optioneel, vereist authenticatie).
  - `title`: Aangepaste documenttitel (optioneel).
- **Response**: JSON met geconverteerde inhoud en metadata.

### 3. Ondersteunde Formaten Opvragen
- **Endpoint**: `GET /api/formats`
- **Response**: Lijst met alle beschikbare bron- en doelformaten.

### 4. Systeemstatus
- **Endpoint**: `GET /api/health`
- **Response**: `{"status": "ok", "app": "slim-down", "database": "connected"}`

### 5. Authenticatie & Documentbeheer (Optioneel)
- `POST /api/auth/register`: Registreer nieuw account.
- `POST /api/auth/login`: Inloggen en sessietoken / API-sleutel ontvangen.
- `GET /api/documents`: Overzicht van opgeslagen documenten van de ingelogde gebruiker.
- `POST /api/documents`: Nieuw document opslaan.
- `GET /api/documents/{id}`: Specifiek document ophalen.
- `DELETE /api/documents/{id}`: Document verwijderen.

*Authenticatie header:* `Authorization: Bearer <API_KEY>` of `X-API-Key: <API_KEY>`.

---

## Belangrijke URLs
- [Homepage](/) - Informatie, voordelen en AI-context optimalisatie uitleg
- [Web Applicatie](/app) - Interactieve document converter en werkruimte
- [LLMs Specificatie](/llms.txt) - Dit bestand voor LLM integratie en context
- [Sitemap](/sitemap.xml) - Sitemap voor zoekmachines en web indexers
- [Robots.txt](/robots.txt) - Toegangsregels voor webcrawlers
