Thank you for your interest in contributing to the SynthoraAI OCR system! This document provides guidelines and instructions for contributing.
- Code of Conduct
- Getting Started
- Development Setup
- Making Changes
- Pull Request Process
- Coding Standards
- Testing
- Documentation
This project follows the same code of conduct as the main SynthoraAI project. Please be respectful and constructive in all interactions.
-
Fork the Repository
# Click 'Fork' on GitHub git clone https://github.com/YOUR_USERNAME/Optical-Character-Recognition.git cd Optical-Character-Recognition
-
Set Up Development Environment
./scripts/install.sh
-
Create a Branch
git checkout -b feature/your-feature-name
cd ocr_backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
pip install -r requirements-dev.txt # Development dependenciescd ocr_api
npm install
npm install -D nodemon jest # Development dependenciesCreate a .env file from .env.example and configure for development:
cp .env.example .env
# Edit .env with your local configurationfeature/- New featuresfix/- Bug fixesdocs/- Documentation changesrefactor/- Code refactoringtest/- Adding or updating tests
Follow conventional commits:
<type>(<scope>): <subject>
<body>
<footer>
Types:
feat: New featurefix: Bug fixdocs: Documentationstyle: Formattingrefactor: Code refactoringtest: Adding testschore: Maintenance
Example:
feat(ocr): add support for TrOCR handwriting recognition
Implement TrOCR engine integration for handwritten text recognition.
Includes preprocessing pipeline and model loading.
Closes #123
-
Update Documentation
- Update README.md if needed
- Add/update code comments
- Update API documentation
-
Write Tests
- Add unit tests for new features
- Update existing tests if needed
- Ensure all tests pass
-
Run Linters
# Python cd ocr_backend black . flake8 . # Node.js cd ocr_api npm run lint npm run format
-
Create Pull Request
- Fill out the PR template
- Link related issues
- Request review from maintainers
-
Address Review Comments
- Make requested changes
- Reply to comments
- Request re-review
- Follow PEP 8 style guide
- Use type hints
- Write docstrings for functions and classes
- Maximum line length: 100 characters
Example:
def process_image(
image_data: bytes,
engine: str = "tesseract",
languages: List[str] = None
) -> Dict[str, Any]:
"""
Process image with OCR engine.
Args:
image_data: Input image bytes
engine: OCR engine name
languages: List of language codes
Returns:
Dict containing extracted text and metadata
Raises:
ValueError: If engine is not supported
"""
pass- Use ES6+ features
- Use async/await for asynchronous code
- Write JSDoc comments
- Use Prettier for formatting
Example:
/**
* Process image with OCR
* @param {Buffer} imageBuffer - Image data
* @param {string} engine - OCR engine name
* @returns {Promise<Object>} OCR result
*/
async function processImage(imageBuffer, engine = 'tesseract') {
// Implementation
}# Python backend
cd ocr_backend
pytest tests/ -v
pytest tests/ --cov=. # With coverage
# Node.js API
cd ocr_api
npm test
npm run test:coveragePython (pytest):
import pytest
from processors.ocr_processor import OCRProcessor
def test_ocr_processor_initialization():
processor = OCRProcessor()
assert processor is not None
assert len(processor.get_available_engines()) > 0
@pytest.mark.asyncio
async def test_image_processing():
processor = OCRProcessor()
# Mock image data
result = await processor.process_image(
image_data=b'...',
engine='tesseract'
)
assert 'text' in result
assert 'confidence' in resultJavaScript (Jest):
const request = require('supertest');
const app = require('../index');
describe('OCR API', () => {
test('GET /health returns 200', async () => {
const response = await request(app).get('/health');
expect(response.statusCode).toBe(200);
expect(response.body.status).toBe('healthy');
});
test('POST /api/ocr/image processes image', async () => {
const response = await request(app)
.post('/api/ocr/image')
.attach('file', 'tests/fixtures/test.jpg')
.field('engine', 'tesseract');
expect(response.statusCode).toBe(200);
expect(response.body.success).toBe(true);
});
});- All public functions must have docstrings/JSDoc
- Include parameter types and return types
- Document exceptions/errors
- Add usage examples for complex functions
Update API documentation when adding/changing endpoints:
- Request/response formats
- Status codes
- Example requests
- Error responses
Update README.md for:
- New features
- Changed dependencies
- New configuration options
- New API endpoints
- Open an issue for bugs or feature requests
- Join discussions on GitHub Discussions
- Contact maintainers: hoangson091104@gmail.com
Thank you for contributing to SynthoraAI OCR! 🎉