Development Quick Start¶
Purpose¶
Set up a Readur development environment in 10 minutes. This guide helps developers contribute to Readur or build custom integrations.
Prerequisites¶
- Python 3.10+ installed
- Node.js 18+ and npm installed
- PostgreSQL 14+ running locally
- Redis server installed
- Git configured with GitHub access
- 8GB RAM recommended for development
Step 1: Clone and Setup¶
Clone the repository and create a virtual environment:
# Clone repository
git clone https://github.com/readur/readur.git
cd readur
# Create Python virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install Python dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt
Step 2: Database Setup¶
Create and initialize the database:
# Create database
createdb readur_dev
# Set environment variables
export DATABASE_URL=postgresql://localhost/readur_dev
export REDIS_URL=redis://localhost:6379
# Run migrations
alembic upgrade head
# Create test user
python scripts/create_user.py --username dev --password dev123 --admin
Step 3: Frontend Setup¶
Install and build frontend assets:
# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Start development server
npm run dev
Keep this terminal running - the frontend will auto-reload on changes.
Step 4: Backend Development Server¶
In a new terminal, start the backend:
# Activate virtual environment
source venv/bin/activate
# Set development environment
export FLASK_ENV=development
export FLASK_DEBUG=1
# Start backend server
python run.py
Step 5: Start Background Workers¶
In another terminal, start the OCR worker:
# Activate virtual environment
source venv/bin/activate
# Start Celery worker
celery -A readur.worker worker --loglevel=info --concurrency=2
Step 6: Access Development Instance¶
Your development environment is now running:
- Frontend: http://localhost:3000 (with hot reload)
- Backend API: http://localhost:5000
- API Documentation: http://localhost:5000/api/docs
Login with: - Username: dev
- Password: dev123
Development Workflow¶
Code Structure¶
readur/
├── backend/ # Python Flask application
│ ├── api/ # REST API endpoints
│ ├── models/ # Database models
│ ├── services/ # Business logic
│ └── workers/ # Background tasks
├── frontend/ # React application
│ ├── src/
│ │ ├── components/
│ │ ├── pages/
│ │ └── services/
│ └── public/
├── tests/ # Test suites
└── scripts/ # Development utilities
Making Changes¶
-
Create feature branch:
-
Backend changes:
- Edit Python files
- Backend auto-reloads with Flask debug mode
-
Run tests:
pytest tests/
-
Frontend changes:
- Edit React components
- Frontend auto-reloads with webpack dev server
-
Run tests:
npm test
-
Database changes:
Testing¶
Run All Tests¶
# Backend tests
pytest tests/ -v
# Frontend tests
cd frontend && npm test
# End-to-end tests
pytest tests/e2e/ --browser chromium
Test Coverage¶
Linting¶
# Python linting
flake8 readur/
black readur/ --check
mypy readur/
# JavaScript linting
cd frontend
npm run lint
npm run format:check
Debugging¶
Backend Debugging¶
Using VS Code:
// .vscode/launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Flask",
"type": "python",
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "readur:create_app",
"FLASK_ENV": "development"
},
"args": ["run", "--no-debugger", "--no-reload"],
"jinja": true
}
]
}
Using pdb:
Frontend Debugging¶
React Developer Tools: 1. Install browser extension 2. Open Developer Tools → Components tab 3. Inspect component state and props
Redux DevTools: 1. Install browser extension 2. View action history and state changes
Database Debugging¶
Local Development Tools¶
Mock Data¶
Generate test documents:
Performance Profiling¶
# Profile API endpoint
python -m cProfile -o profile.stats run.py
# Analyze results
python -m pstats profile.stats
API Testing¶
Using httpie:
# Login
http POST localhost:5000/api/auth/login username=dev password=dev123
# Upload document
http POST localhost:5000/api/documents [email protected] \
"Authorization: Bearer $TOKEN"
Common Development Tasks¶
Add New API Endpoint¶
- Create route in
backend/api/
- Add service logic in
backend/services/
- Write tests in
tests/api/
- Update OpenAPI schema
Add Frontend Feature¶
- Create component in
frontend/src/components/
- Add route in
frontend/src/routes.js
- Create API service in
frontend/src/services/
- Write component tests
Add Background Task¶
- Define task in
backend/workers/tasks.py
- Add to task queue in service layer
- Write worker tests
- Update worker documentation
Troubleshooting¶
Dependencies Won't Install¶
# Update pip and setuptools
pip install --upgrade pip setuptools wheel
# Clear pip cache
pip cache purge
# Use specific Python version
python3.10 -m venv venv
Database Connection Failed¶
# Check PostgreSQL is running
pg_isready
# Check connection
psql -U postgres -c "SELECT 1"
# Reset database
dropdb readur_dev
createdb readur_dev
alembic upgrade head
Frontend Build Errors¶
# Clear node modules
rm -rf node_modules package-lock.json
npm install
# Clear build cache
npm run clean
npm run build
OCR Worker Not Processing¶
# Check Redis connection
redis-cli ping
# Monitor worker logs
celery -A readur.worker worker --loglevel=debug
# Purge task queue
celery -A readur.worker purge
Contributing¶
Before Submitting PR¶
- Run all tests: Ensure all tests pass
- Check linting: Fix any style issues
- Update documentation: Document new features
- Add tests: Cover new functionality
- Test migrations: Verify database changes
Code Style¶
Follow project conventions: - Python: PEP 8 with Black formatting - JavaScript: ESLint + Prettier - Commits: Conventional commits format - Documentation: Markdown with proper headings
Related Documentation¶
- Architecture Overview - System design and components
- API Reference - Complete API documentation
- Testing Guide - Comprehensive testing strategies
- Contributing Guide - Contribution guidelines