Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
848d385
REST - Refactor endpoint to use marshmallow schemas. Added makefile t…
pinkfloydsito Feb 21, 2025
bcd5725
feat:fintech api (#2)
naveenkumarkk Feb 26, 2025
cb77d44
💪 Suggestions Microservice (#4)
pinkfloydsito Mar 1, 2025
6ac30d3
transection_verification
Joyon2393 Mar 2, 2025
d87490f
transaction verification called, using Luhn algorithm to verify the p…
pinkfloydsito Mar 3, 2025
809e521
removed unused file
pinkfloydsito Mar 3, 2025
f3aa0fc
Documentation (#6)
pinkfloydsito Mar 5, 2025
e684602
fraud detection
Joyon2393 Mar 5, 2025
2aff4d1
Integration of fraud detection with orchestrator
pinkfloydsito Mar 5, 2025
cef9fbf
removing unused files
pinkfloydsito Mar 5, 2025
05c1b1f
feat: fraud detection micro services
naveenkumarkk Mar 6, 2025
9db07b3
feat: changing the package name
naveenkumarkk Mar 6, 2025
804fdeb
feat: fraud detection micro service fix
naveenkumarkk Mar 7, 2025
9c1b2e2
fraud-detection: Fixed microservice / v1 working fine
pinkfloydsito Mar 7, 2025
5614895
fraud-detection: setup v2 of model
pinkfloydsito Mar 7, 2025
07b1cc0
Added logging
pinkfloydsito Mar 22, 2025
0a41adb
added order_ID
Joyon2393 Mar 30, 2025
5374cf4
added initialization
Joyon2393 Mar 30, 2025
0a18922
added billing address check
Joyon2393 Apr 5, 2025
1a427b1
feature: leader election
naveenkumarkk Apr 7, 2025
e98e749
Refactor / Impl of vector clocks (#12)
pinkfloydsito Apr 8, 2025
36d6165
Merge branch 'main' into feature/leaderelection
naveenkumarkk Apr 8, 2025
a6bd344
Create __init__.py
naveenkumarkk Apr 8, 2025
11b5dea
Update app.py
naveenkumarkk Apr 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# PostgreSQL
# ------------------------------------------------------------------------------
POSTGRES_HOST=postgres
POSTGRES_PORT=5432
POSTGRES_DB=bookstore
POSTGRES_USER=debug
POSTGRES_PASSWORD=debug
DATABASE_URL="postgresql+psycopg2://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
MODEL_NAME="all-MiniLM-L6-v2"
ORDER_EXECUTOR_REPLICAS=3
REDIS_HOST=redis
REDIS_PORT=6379


8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
__pycache__
__pycache__
.env
books.csv
postgres_data/
ai/
.vscode/
logs/
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
test_bookstore_post:
curl 'http://localhost:8081/checkout' \
-H 'Accept: */*' \
-H 'Accept-Language: en-US,en;q=0.9' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'DNT: 1' \
-H 'Origin: http://localhost:8080' \
-H 'Pragma: no-cache' \
-H 'Referer: http://localhost:8080/' \
-H 'Sec-Fetch-Dest: empty' \
-H 'Sec-Fetch-Mode: cors' \
-H 'Sec-Fetch-Site: same-site' \
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36' \
-H 'sec-ch-ua: "Not A(Brand";v="8", "Chromium";v="132", "Google Chrome";v="132"' \
-H 'sec-ch-ua-mobile: ?0' \
-H 'sec-ch-ua-platform: "macOS"' \
--data-raw '{"user":{"name":"John Doe","contact":"john.doe@example.ru"},"creditCard":{"number":"6011111111111117","expirationDate":"12/95","cvv":"123"},"userComment":"Please handle with care.","items":[{"name":"Book A","quantity":1},{"name":"Book B","quantity":2}],"billingAddress":{"street":"123 Main St","city":"Springfield","state":"IL","zip":"62701","country":"USA"},"shippingMethod":"Standard","giftWrapping":true,"termsAndConditionsAccepted":true}'
proto:
python -m grpc_tools.protoc -I=utils/pb --python_out=utils/pb --grpc_python_out=utils/pb utils/pb/order_executor/order_executor.proto --proto_path=utils/pb --python_out=utils/pb --grpc_python_out=utils/pb
start:
docker-compose up --build --scale order_executor=$(ORDER_EXECUTOR_REPLICAS)
2 changes: 2 additions & 0 deletions data/books.sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Title,Author,Genre,SubGenre,Height,Publisher
Fundamentals of Wavelets,"Goswami, Jaideva",tech,signal_processing,228,Wiley
14 changes: 14 additions & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM docker.io/postgres:16

RUN apt-get update && apt-get install -y \
git \
build-essential \
postgresql-server-dev-$PG_MAJOR \
&& rm -rf /var/lib/apt/lists/*

RUN git clone --branch v0.7.0 https://github.com/pgvector/pgvector.git \
&& cd pgvector \
&& make \
&& make install

COPY ./db/init-extensions.sql /docker-entrypoint-initdb.d/
Binary file added db/dummy_data/bookstore.sql
Binary file not shown.
1 change: 1 addition & 0 deletions db/init-extensions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE EXTENSION IF NOT EXISTS vector;
111 changes: 110 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ services:
# Mount the frontend directory
- ./frontend/src:/usr/share/nginx/html
orchestrator:
env_file:
- .env
build:
# Use the current directory as the build context
# This allows us to access the files in the current directory inside the Dockerfile
Expand All @@ -35,7 +37,10 @@ services:
- ./utils:/app/utils
# Mount the orchestrator/src directory in the current directory to the /app/orchestrator/src directory in the container
- ./orchestrator/src:/app/orchestrator/src
- ./orchestrator/logs:/app/orchestrator/logs
fraud_detection:
env_file:
- .env
build:
# Use the current directory as the build context
# This allows us to access the files in the current directory inside the Dockerfile
Expand All @@ -56,4 +61,108 @@ services:
# Mount the utils directory in the current directory to the /app/utils directory in the container
- ./utils:/app/utils
# Mount the fraud_detection/src directory in the current directory to the /app/fraud_detection/src directory in the container
- ./fraud_detection/src:/app/fraud_detection/src
- ./fraud_detection/src:/app/fraud_detection/src
suggestions:
build:
context: ./
dockerfile: ./suggestions/Dockerfile
env_file:
- .env
ports:
- 50053:50053
environment:
# Pass the environment variables to the container
# The PYTHONUNBUFFERED environment variable ensures that the output from the application is logged to the console
- PYTHONUNBUFFERED=TRUE
# The PYTHONFILE environment variable specifies the absolute entry point of the application
- PYTHONFILE=/app/suggestions/src/app.py
volumes:
# Mount the utils directory in the current directory to the /app/utils directory in the container
- ./utils:/app/utils
- ./suggestions/src:/app/suggestions/src
- ./ai/models:/app/ai/models/

postgres:
build:
context: .
dockerfile: ./db/Dockerfile
image: bookstore_postgres
container_name: bookstore_postgres
volumes:
- ./postgres_data:/var/lib/postgresql/data
- ./db/init-extensions.sql:/docker-entrypoint-initdb.d/init-extensions.sql
- ./db/dummy_data/bookstore.sql:/docker-entrypoint-initdb.d/bookstore.sql
env_file:
- .env
ports:
- "5432:5432"

transaction_verification:
env_file:
- .env
build:
# Use the current directory as the build context
# This allows us to access the files in the current directory inside the Dockerfile
context: ./
# Use the Dockerfile in the fraud_detection directorys
dockerfile: ./transaction_verification/Dockerfile
ports:
# Expose port 50052 on the host, and map port 50052 of the container to port 50051 on the host
- 50052:50052
environment:
# Pass the environment variables to the container
# The PYTHONUNBUFFERED environment variable ensures that the output from the application is logged to the console
- PYTHONUNBUFFERED=TRUE
# The PYTHONFILE environment variable specifies the absolute entry point of the application
# Check app.py in the fraud_detection directory to see how this is used
- PYTHONFILE=/app/transaction_verification/src/app.py
volumes:
# Mount the utils directory in the current directory to the /app/utils directory in the container
- ./utils:/app/utils
# Mount the transection_verification/src directory in the current directory to the /app/transection_verification/src directory in the container
- ./transaction_verification/src:/app/transaction_verification/src

redis:
image: redis:7
ports:
- "6379:6379"
volumes:
- redis_data:/data
command: ["redis-server", "--appendonly", "yes"]

order_executor:
env_file:
- .env
build:
context: .
dockerfile: ./order_executor/Dockerfile
depends_on:
- suggestions
- transaction_verification
- fraud_detection
- redis
environment:
- PYTHONUNBUFFERED=TRUE
- NODE_ID=${NODE_ID}
- PYTHONFILE=/app/order_executor/src/app.py
volumes:
- ./utils:/app/utils
- ./order_executor/src:/app/order_executor/src
command: ["python", "order_executor/src/app.py"]

order_debug:
build:
context: .
dockerfile: ./order_executor/Dockerfile
volumes:
- ./order_executor/src:/app/order_executor/src
- ./utils:/app/utils
command: ["python", "order_executor/src/debug.py"]


volumes:
redis_data:




52 changes: 50 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
# Documentation
## Overview
The Bookstore Application follows a modern microservices-based architecture. The architecture consists of three primary layers:
1. **Client-Facing Layer**
2. **Microservices Layer (gRPC Services)**
3. **Data Layer**

This folder should contain your documentation, explaining the structure and content of your project. It should also contain your diagrams, explaining the architecture. The recommended writing format is Markdown.
## Client-Facing Layer
### REST Checkout API
The **REST Checkout API** serves as the single entry point for client interactions. It handles customer checkout requests and orchestrates calls to the underlying microservices. Key features include:
- Managing checkout requests efficiently.
- Doing validation using schemas and data types.
- Orchestrating multiple microservices to complete the checkout process.

#### Threading Implementation
The checkout process implements threading to enhance performance by:
- Processing multiple microservice calls concurrently.

## Microservices Layer (gRPC Services)
This layer consists of independent services that handle specific tasks and communicate via **gRPC**

### 1. Suggestions Microservice
- Connects to a **PostgreSQL database** with the **pgvector** extension.
- Uses **sentence-transformers** to generate vector embeddings of book descriptions, its title and the author.
- Provides **personalized book recommendations** based on vector similarity.
- Enables **efficient semantic search** capabilities for books.

### 2. Fraud Detection Service
- Analyzes checkout transactions for potential fraud.
- Returns a **risk assessment score** to the checkout service to prevent fraudulent activities.

### 3. Validation Service
- Performs **credit card validation** using the **Luhn algorithm** to verify card numbers.
- Checks **expiration dates** to ensure the card is still valid.
- Provides a **fast validation layer** before payment processing to prevent invalid transactions.

## Data Layer
### PostgreSQL Database
- Serves as the **primary data store** for the application.
- Stores book metadata, user transactions, and other essential records.

### pgvector Extension
- A **specialized PostgreSQL extension** that enables efficient **vector operations and similarity searches**.

## Architecture Diagram
![Architecture Diagram](./images/architecture-diagram.png)
---

## System Diagram
![System Diagram](./images/system-diagram.png)

---
Loading