A data-driven insurance underwriting engine built with PostgreSQL and exposed through a FastAPI API.
The project demonstrates how complex business rules can be modeled as data rather than hard-coded application logic, making products and underwriting rules easier to change without modifying the application layer.
Insurance products often contain large numbers of underwriting questions and rules.
A traditional implementation can place these rules directly in application code, making changes expensive and difficult to audit.
This project explores a different approach:
What if underwriting rules were data?
Products, questions, conditions, outcomes and evaluation behavior are stored in PostgreSQL. The database evaluates the rules and records the resulting decision.
The system supports an end-to-end quote workflow:
- Select an insurance product
- Retrieve its questions
- Capture applicant answers
- Validate answers
- Evaluate underwriting rules
- Produce an underwriting outcome
- Record the evaluation for auditability
Possible outcomes include:
acceptincrease_premiumrefer_to_insurerdecline
A live demo of the engine is available at paco-uw-web.vercel.app.
View the full architecture diagram interactively
The solution is divided into two major layers:
PostgreSQL Rules Engine
Contains the data model, business rules and evaluation functions.
FastAPI API
Provides HTTP endpoints for products, questions, quotes, answers and evaluations.
The API intentionally contains minimal business logic. The underwriting decision remains in the database layer.
- Data-driven business rules
- Compound rule conditions
- Full evaluation and short-circuit evaluation strategies
- Evaluation history and auditability
- Input validation at the database level
- Quote access tokens
- API rate limiting
- CORS controls
- Automated API tests
- Dockerized PostgreSQL environment
- Interactive architecture documentation
The PostgreSQL rules engine includes an 80-assertion test suite covering the rule engine and demonstration scenarios.
The FastAPI layer includes contract and integration tests covering health checks, products, quotes, evaluation, CORS, rate limiting, request limits and administrative endpoints.
Python · FastAPI · PostgreSQL · asyncpg · Docker · pytest · SQL
For the full data model, the two evaluation strategies, the core SQL functions, and local setup, see the Technical Reference.
