A powerful document conversion system that transforms any document into AI-friendly text formats, designed for seamless integration with Large Language Models and AI workflows, with document storage and management capabilities.
- Universal Document Conversion: Transform documents (PDF, DOCX, LaTeX, Markdown, etc.) into AI-optimized text formats
- AI-Ready Output: Structured text output specifically formatted for LLM consumption and analysis
- Document Storage: Securely store and manage documents in Azure Data Lake Storage Gen2
- Permission-Based Access: Fine-grained user permissions for document access and conversion
- LaTeX to PDF Conversion: Convert LaTeX documents to PDF format with error handling
- Repository Integration: Batch convert entire project documentation into single AI-friendly files
- Smart Context Preservation: Maintain document structure and relationships for better AI understanding
- API-First Design: RESTful API designed for AI tool integration and automation workflows
- Proper Package Structure: Follows Python packaging best practices
- Type Hints: Full type annotation support
- CLI Interface: Easy-to-use command-line tool
- Modular Design: Separate core, utils, and workflow modules
xtox/
├── xtox/ # Main package
│ ├── __init__.py # Package initialization
│ ├── core/ # Core conversion functionality
│ │ ├── __init__.py
│ │ ├── document_converter.py # Main converter class
│ │ ├── markdown_to_latex.py # Markdown to LaTeX conversion
│ │ └── latex_to_pdf.py # LaTeX to PDF conversion
│ ├── utils/ # Utility functions
│ │ ├── __init__.py
│ │ └── image_handler.py
│ ├── workflows/ # High-level workflows
│ │ ├── __init__.py
│ │ └── md_to_pdf.py
│ ├── cli/ # Command-line interface
│ │ ├── __init__.py
│ │ └── main.py
│ ├── api/ # API routes
│ ├── backend/ # Backend services
│ ├── azure-functions/ # Azure Functions
│ └── frontend/ # React frontend
├── tests/ # Test files
├── infra/ # Infrastructure code
├── setup.py # Package setup
├── pyproject.toml # Modern Python project config
├── requirements.txt # Dependencies
├── Makefile # Development tasks
└── README.md # This file
This project consists of:
- Backend: Azure Functions for serverless document processing, storage, retrieval, and conversion
- Frontend: React application with AI-focused conversion interfaces
- Storage: Azure Data Lake Storage Gen2 for document and converted text storage
- Database: MongoDB for metadata, conversion history, and AI context mapping
- AI Conversion Engine: Specialized pipeline for creating LLM-optimized text outputs
- Repository Processor: Batch conversion system for entire codebases and documentation sets
- Azure subscription (for cloud deployment)
- Azure CLI or PowerShell Az module
- Node.js 14+
- MongoDB
- Python 3.9+
- AI conversion dependencies (transformers, tiktoken, etc.)
# Clone the repository
git clone <repository-url>cd xtox
# Install in development mode with all dependencies
make setup
# Or manually:
pip install -e ".[dev,azure,api]"pip install -e .# Convert Markdown to PDF
xtotext input.md -o output_dir -r 2
# Convert LaTeX to PDF
xtotext document.tex -o output_dir
# Show help
xtotext --helpfromxtox.coreimportDocumentConverter# Initialize converterconverter=DocumentConverter(output_dir="./output")
# Convert Markdown to PDFresult=converter.markdown_to_pdf(
"document.md", refinement_level=2
)
# Convert LaTeX to PDFpdf_path=converter.latex_to_pdf("document.tex")fromxtox.workflowsimportprocess_markdown_to_pdfresult=process_markdown_to_pdf(
"document.md",
output_dir="./output",
refinement_level=1
)POST /api/ai/convert- Convert document for AI consumptionPOST /api/ai/repository- Process entire repository for AIGET /api/ai/context/{id}- Get document with full contextPOST /api/ai/optimize- Optimize existing text for specific AI models
POST /api/documents/upload- Upload a documentGET /api/documents- List documents available to the userGET /api/documents/{id}- Get document metadataGET /api/documents/{id}/download- Download documentPOST /api/documents/{id}/permissions- Update document permissionsDELETE /api/documents/{id}- Delete a document
POST /api/convert- Convert LaTeX to PDFGET /api/conversion/{id}- Get conversion resultGET /api/download/{id}- Download converted PDFGET /api/documents/{id}/ai-text- Get AI-optimized text outputPOST /api/batch/repository- Repository-wide batch conversion
importrequests# Convert document for AI consumptionwithopen('technical_doc.pdf', 'rb') asf:
response=requests.post(
'https://yourfunctionapp.azurewebsites.net/api/ai/convert',
files={'file': f},
json={
'target_model': 'gpt-4',
'preserve_structure': True,
'include_metadata': True
},
headers={'Authorization': 'Bearer your_token'}
)
ai_ready_text=response.json()['ai_text']# Convert entire project documentation for AIresponse=requests.post(
'https://yourfunctionapp.azurewebsites.net/api/ai/repository',
json={
'repository_path': '/path/to/project',
'include_code': True,
'include_docs': True,
'target_model': 'claude-3',
'output_format': 'contextual'
},
headers={'Authorization': 'Bearer your_token'}
)
# Get single AI-friendly file representing entire projectproject_context=response.json()['consolidated_text']make dev-installmake test
make test-cov # with coveragemake lint # Run linting
make format # Format codemake buildInstall Azure Functions Core Tools:
npm install -g azure-functions-core-tools@4
Run Functions locally:
cd azure-functions func startAI Model Integration:
# Install AI optimization tools pip install tiktoken transformers sentence-transformers # Configure model-specific tokenizers python scripts/setup_ai_models.py
# config/ai_optimization.yamlai_optimization:
token_limits:
gpt-4: 8192claude-3: 100000gpt-3.5: 4096formatting:
preserve_code_blocks: trueadd_context_headers: trueinclude_file_paths: truemaintain_hierarchy: truechunking:
strategy: "semantic"# or "fixed", "adaptive"overlap_tokens: 200respect_boundaries: true# config/repository.yamlrepository_processing:
include_patterns:
- "*.md"
- "*.rst" - "*.txt"
- "README*"
- "docs/**"exclude_patterns:
- "node_modules/**"
- ".git/**"
- "*.log"
- "build/**"ai_enhancements:
add_file_context: truepreserve_directory_structure: trueinclude_git_info: false- ✅ JWT secret key management via environment variables and Azure Key Vault
- ✅ Removed mock authentication bypass
- ✅ CORS origin restrictions
- ✅ File path sanitization to prevent path traversal attacks
- ✅ Input validation for all endpoints
- ✅ Database connection pooling
- ✅ Rate limiting middleware
- ✅ Database indexes for faster queries
- ✅ Centralized file validation
- ✅ Accessibility components (ARIA labels, keyboard navigation)
- ✅ Design token integration
- ✅ Responsive design support
- ✅ Error handling improvements
- Fork the repository
- Create a feature branch focused on AI optimization
- Add tests for AI-specific functionality
- Ensure compatibility with major LLM providers
- Submit a pull request
- API Documentation - Complete API reference
- Architecture - System architecture and design
- Deployment Guide - Deployment instructions
- Contributing - Contribution guidelines
- Testing Guide - Testing documentation
- Design System - Design tokens and components
See .env.example for all configuration options.
Required for Production:
JWT_SECRET_KEY- Minimum 32 charactersMONGO_URL- MongoDB connection stringALLOWED_ORIGINS- Comma-separated frontend URLsENVIRONMENT- Set toproductionALLOW_MOCK_AUTH- Set tofalse
MIT License - see LICENSE file for details