A powerful, production-ready scientific calculator web application built with React, Vite, and Flask. Features a modern responsive UI, comprehensive mathematical functions, unit conversions, and a RESTful API.
Perfect for: Students, Engineers, Data Scientists, and Developers
- Unit Conversions: 50+ units across distance, mass, temperature, volume, and more
- Scientific Functions: Trigonometric, logarithmic, exponential, and statistical functions
- Expression Evaluator: Advanced mathematical expression parsing with full operator support
- Copy to Clipboard: Quick results sharing and data export
- Responsive Design: Works seamlessly on Mobile, Tablet, and Desktop
- ⚡ Fast Computation: <100ms for most operations
- 🔒 Secure: Safe expression evaluation, no
eval() - ♿ Accessible: WCAG 2.1 AA compliant
- 📱 Mobile Optimized: Responsive multi-column layout
- 🎨 Modern UI: Clean, intuitive interface
- 📊 Production Ready: Error handling, validation, logging
- 💾 Stateless API: RESTful endpoints for easy integration
scientific-calculator/
├── src/
│ └── scientific_calculator/
│ ├── __init__.py # Package initialization
│ ├── expression_evaluator.py # AST-based expression evaluator
│ ├── units.py # Pint integration and unit registry
│ ├── functions.py # Scientific function registry
│ ├── exceptions.py # Custom exception classes
│ └── api.py # REST/GraphQL API layer
├── frontend/
│ ├── index.html # Entry point
│ ├── src/
│ │ ├── main.js # Application entry
│ │ ├── components/ # UI components
│ │ ├── styles/ # CSS with accessibility focus
│ │ ├── services/ # API client
│ │ └── utils/ # Utilities and helpers
│ └── tests/
│ ├── unit/ # Component unit tests
│ └── accessibility/ # WCAG 2.1 AA compliance tests
├── tests/
│ ├── unit/ # Backend unit tests
│ ├── integration/ # Integration tests
│ └── conftest.py # Pytest configuration and fixtures
├── pyproject.toml # Python project configuration
├── frontend/package.json # Node.js dependencies
└── README.md # This file
- Python 3.8+
- Node.js 16+
- Clone the repository
git clone https://github.com/codemohandis/scientific-calculator-.git
cd scientific-calculator-- Backend Setup (Flask)
# Install Python dependencies
pip install flask flask-cors
# Run Flask API server
python server.py
# API runs on http://localhost:8000- Frontend Setup (React/Vite)
cd frontend
npm install
npm start
# Frontend runs on http://localhost:5173- Access the app
http://localhost:5173
# Run all backend tests
pytest
# Run with coverage
pytest --cov=src/scientific_calculator --cov-report=html
# Run specific test file
pytest tests/unit/test_conversions.py
# Run with verbose output
pytest -vcd frontend
# Run unit tests
npm test
# Run accessibility tests
npm run test:a11y
# Run with coverage
npm run test:coverage# Format code with black
black src/ tests/
# Lint with ruff
ruff check src/ tests/
# Type check with mypy
mypy src/
# Run all checks
black src/ tests/ && ruff check src/ tests/ && mypy src/cd frontend
# Format code
npm run format
# Lint
npm run lint
# Check formatting
npm run format:check- Red: Write a failing test that describes the desired behavior
- Green: Write minimal code to make the test pass
- Refactor: Clean up the implementation while keeping tests passing
All features must follow TDD discipline:
- Write tests first
- Implement functionality
- Verify ≥85% test coverage
- Maintain type safety (mypy --strict)
All UI components must:
- Follow WCAG 2.1 AA standards
- Include proper ARIA labels and roles
- Support keyboard navigation
- Maintain color contrast ratios (4.5:1 for normal text)
- Be testable with axe-core
- 100% type hints required for Python code
mypy --strictcompliance mandatory- No
Anytypes without explicit justification
The backend uses a custom AST-based expression evaluator integrated with Pint for unit-aware computation:
- Expression Evaluator: Safe evaluation using Python's
astmodule (noeval()) - Unit System: Pint
UnitRegistryfor dimensional analysis - Function Registry: Whitelisted mathematical and statistical functions
- Error Handling: Custom exception hierarchy with domain validation
The frontend provides an accessible, responsive UI:
- Components: Reusable calculator, input, and results display components
- Accessibility: WCAG 2.1 AA compliance with ARIA labels and keyboard support
- API Client: Axios-based service for backend communication
- Styling: CSS with accessible color contrasts and responsive design
Evaluate an expression.
Request:
{
"expression": "5 km in miles"
}Response:
{
"result": 3.10686,
"unit": "miles",
"error": null
}List available units.
Response:
{
"distance": ["km", "miles", "meter", "foot"],
"mass": ["kg", "pounds", "gram"],
"temperature": ["celsius", "fahrenheit", "kelvin"],
"volume": ["liter", "gallon"],
"derived": ["velocity", "force", "pressure", "energy", "power"]
}List available functions.
Response:
{
"trigonometric": ["sin", "cos", "tan"],
"logarithmic": ["log", "ln"],
"exponential": ["exp", "pow"],
"statistical": ["mean", "median", "stdev"]
}- Expression evaluation: <100ms
- Typical case: <5ms
- UI response time: <200ms
- Memory footprint: <10MB
This project follows the Scientific Calculator Constitution (v1.1.0), which mandates:
- Type Safety (NON-NEGOTIABLE): All code must use explicit type hints with
mypy --strict - Test-First Development (NON-NEGOTIABLE): TDD discipline with ≥85% coverage
- Pure Functions & Immutability: AST processing with no global state
- Explicit Error Handling: Custom exception hierarchy with context
- UI/UX-First Design: Responsive, accessible interface (WCAG 2.1 AA)
- Semantic Versioning: Version tracking in
pyproject.toml
POST /api/convert
Content-Type: application/json
{
"value": 10,
"from_unit": "kilometer",
"to_unit": "mile"
}POST /api/evaluate
Content-Type: application/json
{
"expression": "2 + 3 * 4"
}POST /api/functions
Content-Type: application/json
{
"function": "sin",
"arguments": [30]
}GET /api/unitsGET /api/functionsGET /api/healthcd frontend
npm install
# Connect repository to https://vercel.com
# Automatic deployment on every push- Push code to GitHub
- Connect repository to Railway or Render
- Set Python version to 3.8+
- Deploy automatically on every push
Create .env file in project root:
FLASK_ENV=production
FLASK_DEBUG=False
CORS_ORIGINS=https://your-domain.com
We welcome contributions! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open a Pull Request
MIT License - See LICENSE file for details
- GitHub Issues: Report issues
- Email: mohammad.mehdi.prof@gmail.com
- Author: Code Mohandis
- Flask and React communities
- Pint for unit conversions
- Open source contributors
- WCAG for accessibility guidelines
Made with ❤️ by Code Mohandis
⭐ If you find this project useful, please give it a star!