Calculator App FastAPI
deypadma2020/CalculatorApp
Calculadora modular FastAPI com CLI, REST API e Docker
Ver no GitHubAplicação de calculadora production-ready construída com FastAPI, oferecendo tanto CLI quanto REST API para operações aritméticas. Inclui logging robusto, tratamento de exceções customizadas, testes automatizados e suporte a Docker, pronta para ambientes de produção.
Instalação
npx convez-ai deypadma2020/CalculatorApp1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.
Métricas
Casos de uso
- Criar APIs de cálculo escaláveis e testadas
- Exemplo de projeto FastAPI production-ready
- Base para ferramentas que precisam de operações aritméticas
Veredito

Projeto bem estruturado que demonstra boas práticas de desenvolvimento Python com FastAPI, incluindo testes, Docker e documentação clara. Útil como referência ou base para APIs simples, mas o escopo é limitado a operações aritméticas básicas.
README
A tradução para o português deste README ainda está na fila.
# 🧮 Calculator API
A production-ready, modular FastAPI-based calculator project that supports both command-line interface (CLI) and REST API operations. It includes logging, custom exceptions, test automation, and Docker deployment.
---
## 📌 Project Overview
This project is a robust calculator that:
- Performs basic arithmetic operations (add, subtract, multiply, divide)
- Exposes a REST API via FastAPI
- Includes full logging and error handling
- Can be run via CLI or HTTP
- Is modular, scalable, and test-driven
- Provides health check, Docker support, and full API documentation
---
## 📁 Project Structure
calculator_project/ │ ├── app/ # Application code │ ├── api/ # FastAPI routes │ ├── service/ # Business logic │ └── utils/ # Exceptions, logger │ ├── api_test/ # API tests using pytest ├── func_tests/ # Unit tests using unittest │ ├── main.py # FastAPI app entry point ├── setup.py # Packaging config ├── pyproject.toml # Modern build config ├── Makefile # Dev automation commands ├── Dockerfile # Image build config ├── docker-compose.yaml # Compose config ├── requirements.txt └── README.md # You are here
---
## 🚀 Functionality
### ✅ API Endpoints
| Operation | Endpoint | Method | Example Payload |
|--------------|------------------|--------|--------------------------|
| Add | `/api/v1/add` | POST | `{ "a": 10, "b": 5 }` |
| Subtract | `/api/v1/sub` | POST | `{ "a": 10, "b": 5 }` |
| Multiply | `/api/v1/mul` | POST | `{ "a": 10, "b": 5 }` |
| Divide | `/api/v1/div` | POST | `{ "a": 10, "b": 2 }` |
| Health Check | `/api/v1/health` | GET | — |
### ✅ Sample Response
```json
{
"result": 15
}
🧰 How to Use
📦 Install Dependencies
pip install -r requirements.txt
▶️ Run Locally
make run
Then open:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
⚙️ CLI Usage (Optional)
To run calculator interactively from terminal:
python main.py
This mode supports step-by-step number and operator inputs via CLI.
🐳 Docker Usage
🔨 Build Docker Image
make docker
🚀 Run via Docker Compose
make docker-up
Your app will be available at: http://localhost:8000
To stop:
make docker-down
🧪 Running Tests
✅ Run All Tests
make test
🧪 Run Unit (Function) Tests
make unit-test
🌐 Run API (Endpoint) Tests
make api-test
📬 Postman Testing Example
- Open Postman or REST client.
- Send a
POSTrequest:
POST http://127.0.0.1:8000/api/v1/add
Content-Type: application/json
{
"a": 5,
"b": 10
}
- Response:
{
"result": 15
}
- Try
/sub,/mul,/div,/healthas well.
🛠️ Developer Shortcuts via Makefile
make run # Start API server locally
make test # Run all tests with coverage
make unit-test # Run function/unit tests only
make api-test # Run API tests only
make lint # Run flake8 linter
make format # Format code with black
make clean # Remove __pycache__ and logs
make docker # Build Docker image
make docker-up # Run with Docker Compose
make docker-down # Stop Docker Compose
📄 API Docs (via Swagger & ReDoc)
After running the app:
- 📘 Swagger UI: http://localhost:8000/docs
- 📕 ReDoc UI: http://localhost:8000/redoc
🔐 Error Handling
Handled with custom exception logic for clarity.
Example: Division by zero
{
"detail": "Error occurred in python script name [core.py] line number [10] error message[Division by zero is not allowed]"
}
🧱 Future Improvements
- ✅ Add exponentiation/modulus support
- 🔒 JWT authentication for API
- 🚀 Auto-deploy to AWS/Render
- 🔁 CI/CD pipeline via GitHub Actions
- 📊 Add Prometheus
/metricsendpoint
👨💻 Author
Padma Dey 📧 deypadma2022@gmail.com 🌐 GitHub Profile
🪪 License
This project is licensed under the MIT License. See LICENSE file for details.