Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

feat(basket): add basket service to dev #13

Merged
merged 16 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
# GoodFood 2.0

GoodFood 2.0 is a food ordering application for Good Food, a company specializing in food services in France, Belgium, and Luxembourg.
GoodFood 2.0 is a food ordering application for Good Food, a company specializing in food services in France, Belgium,
and Luxembourg.

## Origin / Context

Good Food was formed from the merger of four food companies. The company offers various food services, including conventional dining, takeout, and delivery with phone orders. Ordering is also available through a web or mobile application.
Good Food was formed from the merger of four food companies. The company offers various food services, including
conventional dining, takeout, and delivery with phone orders. Ordering is also available through a web or mobile
application.

The GoodFood 2.0 project was initiated to update the existing ordering application, which had become outdated and was unable to handle more users. The objective is to create a modern, user-friendly, and modular new version that can handle a high volume of concurrent users, up to several thousand.
The GoodFood 2.0 project was initiated to update the existing ordering application, which had become outdated and was
unable to handle more users. The objective is to create a modern, user-friendly, and modular new version that can handle
a high volume of concurrent users, up to several thousand.

## Microservices ports

| Service | Port | Language | Database | Status | Assignee |
| ----------- | ----- | ----------- | ---------- | ------ | --------------- |
| Gateway | 50000 | Go | ❌ | ❌ | @Anatole-Godard |
| User (auth) | 50001 | Go | PostgreSQL | | @Anatole-Godard |
| Basket | 50002 | NodeJS (ts) | Redis | | @Anatole-Godard |
| Payment | 50003 | NodeJS (ts) | PostgreSQL | ✅ | @floriaaan |
| Product | 50004 | NodeJS (ts) | PostgreSQL | ❌ | @PierreLbg |
| Restaurant | 50005 | NodeJS (ts) | PostgreSQL | ❌ | @PierreLbg |
| Promotion | 50006 | NodeJS (ts) | PostgreSQL | ❌ | @PierreLbg |
| Order | 50007 | NodeJS (ts) | PostgreSQL | ✅ | @floriaaan |
| Delivery | 50008 | NodeJS (ts) | PostgreSQL | ✅ | @floriaaan |
|-------------|-------|-------------|------------|--------|-----------------|
| Gateway | 50000 | Go | ❌ | ❌ | @Anatole-Godard |
| User (auth) | 50001 | Go | PostgreSQL | ⚠️ | @Anatole-Godard |
| Basket | 50002 | NodeJS (ts) | Redis | ⚠️ | @Anatole-Godard |
| Payment | 50003 | NodeJS (ts) | PostgreSQL | ✅ | @floriaaan |
| Product | 50004 | NodeJS (ts) | PostgreSQL | ❌ | @PierreLbg |
| Restaurant | 50005 | NodeJS (ts) | PostgreSQL | ❌ | @PierreLbg |
| Promotion | 50006 | NodeJS (ts) | PostgreSQL | ❌ | @PierreLbg |
| Order | 50007 | NodeJS (ts) | PostgreSQL | ✅ | @floriaaan |
| Delivery | 50008 | NodeJS (ts) | PostgreSQL | ✅ | @floriaaan |
| Stock | 50009 | NodeJS (ts) | PostgreSQL | ⚠️ | @floriaaan |
| Reporting | 50020 | C# (dotnet) | PostgreSQL | ⚠️ | @floriaaan |
| Log | 50021 | Go | PostgreSQL | ✅ | @floriaaan |
| Log | 50021 | Go | PostgreSQL | ✅ | @floriaaan |
| (...) | (...) | (...) | (...) | (...) |

## File Hierarchy
Expand Down
2 changes: 2 additions & 0 deletions services/basket/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build
2 changes: 2 additions & 0 deletions services/basket/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REDIS_URL=redis://localhost:6379/0
PORT=50002
6 changes: 6 additions & 0 deletions services/basket/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
dist/
bin/
*.env*
!*.env.example

1 change: 1 addition & 0 deletions services/basket/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.12.0
33 changes: 33 additions & 0 deletions services/basket/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM node:18-alpine3.17 as builder

# Set working directory
WORKDIR /app

# Copy the application code
COPY ./basket/ .

# Install dependencies
RUN npm install

# Copy the proto files - TODO: fix this, proto files should be copied from goodfood/services/proto
COPY ./proto ./proto/

# Build the application
RUN npm run build


# Create a new image with the application
FROM node:18-alpine3.17 as runner

# Set working directory
WORKDIR /app

# Copy the application package
COPY --from=builder /app/dist .
COPY --from=builder /app/proto/ /proto/

# Expose the gRPC port
EXPOSE 50002

# Start the server
CMD [ "node", "index.js"]
27 changes: 27 additions & 0 deletions services/basket/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Basket Microservice

| Informations |
|-------------------------------------------|
| **Port:** 50002 |
| **Developer:** @Anatole-Godard |
| **Status:** In progress |
| **Last update:** 2023-08-14 |
| **Language:** NodeJS |
| **Dependencies:** TypeScript, gRPC, Redis |

## gRPC Methods

- Basket model:

- `GetBasket`: Retrieves a basket by its user ID.
- `AddProduct`: Adds a product to a basket.
- `DeleteProduct`: Deletes a product from a basket.
- `Reset`: Resets a basket.
- `UpdateRestaurant`: Sets a restaurant to a basket.

## Requirements

To run this microservice, you will need to have the following installed on your system:

- NodeJS (v18.12.0 or higher) (dev. with v18.12.0)
- Redis (v6.2.6 or higher) (dev. with docker image `redis:6.2.6`)
19 changes: 19 additions & 0 deletions services/basket/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
services:
basket-redis:
image: redis:latest
ports:
- "6379:6379"
volumes:
- goodfood-basket-volume:/data
networks:
- goodfood-basket-network
command: redis-server --appendonly yes
environment:
REDIS_USERNAME: redis
REDIS_PASSWORD: password

volumes:
goodfood-basket-volume:

networks:
goodfood-basket-network:
8 changes: 8 additions & 0 deletions services/basket/k8s/configmap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: goodfood-basket-configmap
labels:
app: goodfood-basket
data:
port: "50002"
31 changes: 31 additions & 0 deletions services/basket/k8s/deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: goodfood-basket
labels:
app: goodfood-basket
spec:
selector:
matchLabels:
app: goodfood-basket
template:
metadata:
labels:
app: goodfood-basket
spec:
containers:
- name: goodfood-basket
image: floriaaan/goodfood-basket:1.0.0
imagePullPolicy: Always
resources:
limits:
memory: "128Mi"
cpu: "200m"
env:
- name: PORT
valueFrom:
configMapKeyRef:
name: goodfood-basket-configmap
key: port
ports:
- containerPort: 50002
18 changes: 18 additions & 0 deletions services/basket/k8s/hpa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: goodfood-basket-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: goodfood-basket
minReplicas: 1
maxReplicas: 3
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 50
17 changes: 17 additions & 0 deletions services/basket/k8s/ingress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: goodfood-basket
spec:
ingressClassName: nginx
rules:
- host: basket.localdev.me
http:
paths:
- pathType: Prefix
backend:
service:
name: goodfood-basket
port:
number: 50002
path: /
13 changes: 13 additions & 0 deletions services/basket/k8s/service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: goodfood-basket
spec:
selector:
app: goodfood-basket
ports:
- name: "grpc"
port: 50002
targetPort: 50002
status:
loadBalancer: {}
Loading
Loading