Skip to content

AI-powered quotation intelligence microservice leveraging FastAPI, Pydantic schema enforcement, decimal-accurate pricing and tax computation, and bilingual (EN/AR) AI-driven email generation via an LLM abstraction layer. Features OpenAPI contracts, pytest-based CI validation, and Dockerized, cloud-native deployment for scalable CRM and sales automa

Notifications You must be signed in to change notification settings

bitsandbrains/ai-quotation-intelligence-microservice

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿท๏ธ Project Title

AI-Driven Quotation Microservice (FastAPI + Decimal Finance Engine + Bilingual AI Email Generator)

๐Ÿงฉ Project Overview

This project is a production-grade quotation computation and communication microservice designed for B2B sales, procurement, and CRM automation systems. It accepts structured quotation requests via a REST API, performs precise financial calculations using decimal-safe arithmetic, and generates professional bilingual (English & Arabic) quotation emails through a controlled AI abstraction layer.

The service is built using FastAPI and Pydantic, making it fully OpenAPI compliant, strongly typed, and enterprise-ready for integration with CRMs, ERP systems, and sales automation pipelines.

๐Ÿ“‘ Table of Contents

  • ๐Ÿท๏ธ Project Title
  • ๐Ÿงพ Executive Summary
  • ๐Ÿ“‘ Table of Contents
  • ๐Ÿงฉ Project Overview
  • ๐ŸŽฏ Objectives & Goals
  • โœ… Acceptance Criteria
  • ๐Ÿ’ป Prerequisites
  • โš™๏ธ Installation & Setup
  • ๐Ÿ”— API Documentation
  • ๐Ÿ–ฅ๏ธ UI / Frontend
  • ๐Ÿ”ข Status Codes
  • ๐Ÿš€ Features
  • ๐Ÿงฑ Tech Stack & Architecture
  • ๐Ÿ› ๏ธ Workflow & Implementation
  • ๐Ÿงช Testing & Validation
  • ๐Ÿ” Validation Summary
  • ๐Ÿงฐ Verification Testing Tools
  • ๐Ÿงฏ Troubleshooting & Debugging
  • ๐Ÿ”’ Security & Secrets
  • โ˜๏ธ Deployment
  • โšก Quick-Start Cheat Sheet
  • ๐Ÿงพ Usage Notes
  • ๐Ÿง  Performance & Optimization
  • ๐ŸŒŸ Enhancements & Features
  • ๐Ÿงฉ Maintenance & Future Work
  • ๐Ÿ† Key Achievements
  • ๐Ÿงฎ High-Level Architecture
  • ๐Ÿ—‚๏ธ Project Structure
  • ๐Ÿงญ How to Demonstrate Live
  • ๐Ÿ’ก Summary, Closure & Compliance

๐Ÿงฉ Project Overview

This system exposes a REST API endpoint POST /quote that accepts a structured quotation request containing customer details and line items. It performs decimal-safe pricing calculations, applies taxes, computes totals, and generates bilingual professional email drafts using a deterministic mock AI layer.

๐ŸŽฏ Objectives & Goals

  • Provide accurate financial calculations using decimal arithmetic
  • Generate professional quotation emails in English and Arabic
  • Expose a clean OpenAPI-compliant REST interface
  • Ensure validation, testing, and containerized deployment
  • Enable enterprise-ready extensibility for real LLM integration

โœ… Acceptance Criteria

CriteriaDescription
API ValidityPOST /quote must accept and validate structured JSON
AccuracyAll totals must be decimal-safe and reproducible
EmailsBoth English and Arabic drafts must be generated
TestingAll pytest tests must pass
DocsSwagger docs must be available at /docs

๐Ÿ’ป Prerequisites

  • Python 3.11+
  • pip
  • Docker (optional)
  • Postman or curl

โš™๏ธ Installation & Setup

  • Create virtual environment
  • Install dependencies from requirements.txt
  • Run uvicorn app.main:app
  • Access http://127.0.0.1:8000/docs

๐Ÿ”— API Documentation

MethodEndpointDescription
POST/quoteAccepts quotation JSON, returns totals and bilingual email drafts

๐Ÿ–ฅ๏ธ UI / Frontend

This microservice is API-first and UI-agnostic. The interactive Swagger UI at /docs serves as the reference interface for clients and testers.

๐Ÿ”ข Status Codes

CodeMeaning
200Quotation generated successfully
422Invalid input schema
500Internal processing error

๐Ÿš€ Features

  • Decimal-Safe Financial Engine โ€“ Eliminates floating-point rounding errors for real-world pricing and taxation.
  • Multi-Item Quotation Processing โ€“ Supports unlimited line items with quantity, unit price, and tax.
  • Bilingual AI Communication Layer โ€“ Generates English and Arabic quotation emails using a deterministic AI engine.
  • Enterprise-Grade API Validation โ€“ Uses Pydantic schemas to enforce strict data integrity.
  • OpenAPI / Swagger Interface โ€“ Automatically generated interactive API documentation.
  • Mock LLM Abstraction โ€“ Allows safe offline testing while keeping architecture ready for real OpenAI or Claude.
  • Dockerized Microservice โ€“ Portable deployment across cloud, on-premise, or CI/CD pipelines.
  • Automated Testing Suite โ€“ Financial correctness verified using Pytest.

๐Ÿงฑ Tech Stack & Architecture

LayerTechnologyPurpose
API LayerFastAPIHigh-performance REST API and OpenAPI generation
ValidationPydanticStrong typing, schema enforcement, email validation
Finance EngineDecimalAccurate currency and tax calculations
AI LayerMock LLMBilingual email generation engine
TestingPytestBusiness logic verification
DeploymentDockerContainerized execution
Client
  |
  | POST /quote
  v
FastAPI Gateway
  |
  v
Pydantic Validation
  |
  v
Financial Engine (Decimal)
  |
  v
AI Draft Generator (Mock LLM)
  |
  v
Structured JSON Response

๐Ÿ› ๏ธ Workflow & Implementation

  1. Client submits a quotation request with customer data and line items.
  2. FastAPI validates all inputs using Pydantic models.
  3. Each line item is processed using Decimal arithmetic to compute taxed totals.
  4. The grand total is calculated from all validated line totals.
  5. The Mock LLM engine generates professional quotation emails in English and Arabic.
  6. The API returns a structured JSON response containing totals and both email drafts.

๐Ÿงช Testing & Validation

IDAreaCommandExpected OutputExplanation
T1MathpytestPassVerifies line and grand totals
T2APIPOST /quote200Validates full pipeline

๐Ÿ” Validation Summary

All inputs are validated using Pydantic and all arithmetic uses Decimal to prevent rounding errors.

๐Ÿงฐ Verification Testing Tools & Command Examples

  • pytest
  • curl
  • FastAPI Swagger UI

๐Ÿงฏ Troubleshooting & Debugging

  • 422 Unprocessable Entity โ€“ Input JSON does not match Pydantic schema (email format, missing fields, wrong types).
  • 500 Internal Server Error โ€“ Logic or AI layer failure; check Uvicorn logs.
  • Incorrect totals โ€“ Indicates Decimal conversion issue or invalid numeric input.
  • Swagger not loading โ€“ Ensure FastAPI is running on port 8000 and no firewall is blocking it.

๐Ÿ”’ Security & Secrets

No API keys are required. The Mock LLM ensures zero data leakage and full offline execution.

โ˜๏ธ Deployment

The microservice is containerized using Docker and can be deployed to any cloud or on-premise infrastructure including AWS ECS, Azure Container Apps, GCP Cloud Run, or a private VPS.

  • Stateless microservice โ€“ horizontally scalable
  • No external API dependencies in Mock LLM mode
  • Ready for CI/CD pipelines

โšก Quick-Start Cheat Sheet

  • Install โ†’ Run โ†’ Open /docs โ†’ Send POST /quote

๐Ÿงพ Usage Notes

Clients must submit valid email addresses and numeric prices. Currency precision is preserved via Decimal.

๐Ÿง  Performance & Optimization

  • FastAPI provides asynchronous request handling.
  • Decimal ensures correctness over raw float performance.
  • Stateless design allows horizontal scaling.
  • Docker image is lightweight (Python slim base).

๐ŸŒŸ Enhancements & Features

  • Replace Mock LLM with OpenAI or Claude
  • Add PDF quotation generation
  • CRM integration

๐Ÿงฉ Maintenance & Future Work

  • Add database persistence
  • Add authentication
  • Add async LLM support

๐Ÿ† Key Achievements

  • Built a finance-grade pricing engine using Decimal.
  • Implemented bilingual AI-driven business communication.
  • Delivered a fully documented OpenAPI microservice.
  • Packaged the entire system for cloud deployment.

๐Ÿงฎ High-Level Architecture

The Quotation Microservice is designed as a clean, stateless, API-driven financial and AI communication engine. It follows a layered microservice architecture that separates input validation, business logic, and AI-based content generation, ensuring scalability, security, and auditability.

๐Ÿ”น Architectural Layers

LayerResponsibilityKey Components
Client LayerSubmits quotation requestsPostman, CRM, Web App, Swagger UI
API GatewayRequest routing & validationFastAPI
Validation LayerSchema & data integrity enforcementPydantic Models
Business Logic LayerFinancial computation enginelogic.py (Decimal pricing)
AI Communication LayerBilingual email generationmock_llm.py
Response LayerStructured JSON outputFastAPI Serializer

๐Ÿ”น High-Level System Flow

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Client Applications โ”‚
โ”‚ (CRM, Swagger, API)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚  POST /quote (JSON)
            โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚       FastAPI API          โ”‚
โ”‚   app.main : /quote        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
            โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Pydantic Validation   โ”‚
โ”‚  Email, Items, Price, Tax โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚ Validated Data
            โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Financial Engine         โ”‚
โ”‚  logic.py (Decimal Math)  โ”‚
โ”‚  - Line Totals            โ”‚
โ”‚  - Tax Calculation        โ”‚
โ”‚  - Grand Total            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚ Calculated Quote
            โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   AI Communication Layer  โ”‚
โ”‚  mock_llm.py              โ”‚
โ”‚  - English Email          โ”‚
โ”‚  - Arabic Email           โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
            โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Structured API Response โ”‚
โ”‚  Totals + Email Drafts    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
            โ”‚
            โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Client Receives  โ”‚
โ”‚   Final Quotation    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”น Why This Architecture Is Enterprise-Grade

  • Stateless microservice โ€“ horizontally scalable
  • Strict data validation before any computation
  • Financial-grade decimal arithmetic
  • AI layer isolated for safe testing and future LLM integration
  • API-first design for CRM, ERP, and SaaS integrations
  • Container-ready for cloud deployment

๐Ÿ—‚๏ธ Project Structure

Quotation Microservice/
โ”‚
โ”œโ”€ app/
โ”‚   โ”œโ”€ main.py
โ”‚   โ”œโ”€ models.py
โ”‚   โ”œโ”€ logic.py
โ”‚   โ””โ”€ mock_llm.py
โ”‚
โ”œโ”€ tests/
โ”‚   โ””โ”€ test_quote.py
โ”‚
โ”œโ”€ Dockerfile
โ”œโ”€ requirements.txt
โ”œโ”€ README.md
โ””โ”€ technical_project_detail.pdf

๐Ÿงญ How to Demonstrate Live

  • Run uvicorn
  • Open /docs
  • Submit POST /quote
  • Show totals + bilingual email output

๐Ÿ’ก Summary, Closure & Compliance

This project demonstrates enterprise-grade API engineering, financial computation accuracy, and AI-assisted business communication in a single microservice. It is compliant with modern backend standards including OpenAPI, containerization, test automation, and clean architecture, making it suitable for production, SaaS platforms, and CRM-driven sales automation.

About

AI-powered quotation intelligence microservice leveraging FastAPI, Pydantic schema enforcement, decimal-accurate pricing and tax computation, and bilingual (EN/AR) AI-driven email generation via an LLM abstraction layer. Features OpenAPI contracts, pytest-based CI validation, and Dockerized, cloud-native deployment for scalable CRM and sales automa

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published