Skip to content

Commit f76a6ae

Browse files
authored
feat(order): implement order api and workflow (#7)
* add ngrock to expose a webhook for order service * code review * fix(order): add processing payment child workflow for creating orders * fix vscode debugging and add payment lib * add nestjs app for product management * implement endpoint for loading products * fix issue creating orders with stripe * fix workflow steps for reporting order failures * fix payment processing workflow * code review
1 parent c502c20 commit f76a6ae

File tree

150 files changed

+21869
-10857
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+21869
-10857
lines changed

.env.example

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,29 @@ DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:${POSTGRES_P
1515

1616
# SERVICES SETTINGS
1717
NODE_ENV=development
18-
AUTH_PORT=9095
19-
ORDER_PORT=9096
18+
AUTH_PORT=8081
19+
ORDER_PORT=8082
20+
PRODUCT_PORT=8083
2021
SENDGRID_API_KEY=SG.your_sendgrid_api_key
2122
# REMEMBER TO USE A VALID SENDER EMAIL, more info: https://app.sendgrid.com/settings/sender_auth/senders
2223
2324
EMAIL_FROM_NAME=ProjectX Team
2425

26+
# PAYMENT SETTINGS
27+
# You can find your secret key in your Stripe account
28+
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
29+
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
30+
# If you are testing your webhook locally with the Stripe CLI you
31+
# can find the endpoint's secret by running `stripe listen`
32+
# Otherwise, find your endpoint's secret in your webhook settings in the Developer Dashboard
33+
STRIPE_WEBHOOK_SECRET=whsec_your_stripe_webhook_signing_secret
34+
35+
# DEVELOPMENT ONLY
36+
NGROK_AUTHTOKEN=your_ngrok_auth_token
37+
2538
# WEB SETTINGS
2639
SESSION_SECRET=your_secret_key_for_sessions
2740
AUTH_API_URL="http://localhost:${AUTH_PORT}"
2841
ORDER_API_URL="http://localhost:${ORDER_PORT}"
42+
PRODUCT_API_URL="http://localhost:${PRODUCT_PORT}"
2943
JWT_SECRET=your_secret_key_for_jwt

.vscode/launch.json

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// Hover to view descriptions of existing attributes.
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
6-
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
76
"configurations": [
87
{
98
"name": "Web",
@@ -16,6 +15,81 @@
1615
"console": "internalConsole",
1716
"cwd": "${workspaceFolder}",
1817
"envFile": "${workspaceFolder}/.env"
18+
},
19+
{
20+
"name": "Debug Auth Service",
21+
"type": "node",
22+
"request": "attach",
23+
"port": 9229,
24+
"restart": true,
25+
"sourceMaps": true,
26+
"remoteRoot": "/app",
27+
"localRoot": "${workspaceFolder}",
28+
"outFiles": [
29+
"${workspaceFolder}/dist/apps/auth/**/*.js",
30+
"${workspaceFolder}/dist/libs/**/*.js"
31+
],
32+
"resolveSourceMapLocations": [
33+
"${workspaceFolder}/**",
34+
"!**/node_modules/**"
35+
],
36+
"skipFiles": ["<node_internals>/**"],
37+
"trace": true,
38+
"sourceMapPathOverrides": {
39+
"webpack:///./~/*": "${workspaceFolder}/node_modules/*",
40+
"webpack:///./*": "${workspaceFolder}/*",
41+
"webpack:///*": "*"
42+
}
43+
},
44+
{
45+
"name": "Debug Order Service",
46+
"type": "node",
47+
"request": "attach",
48+
"port": 9230,
49+
"restart": true,
50+
"sourceMaps": true,
51+
"remoteRoot": "/app",
52+
"localRoot": "${workspaceFolder}",
53+
"outFiles": [
54+
"${workspaceFolder}/dist/apps/order/**/*.js",
55+
"${workspaceFolder}/dist/libs/**/*.js"
56+
],
57+
"resolveSourceMapLocations": [
58+
"${workspaceFolder}/**",
59+
"!**/node_modules/**"
60+
],
61+
"skipFiles": ["<node_internals>/**"],
62+
"trace": true,
63+
"sourceMapPathOverrides": {
64+
"webpack:///./~/*": "${workspaceFolder}/node_modules/*",
65+
"webpack:///./*": "${workspaceFolder}/*",
66+
"webpack:///*": "*"
67+
}
68+
},
69+
{
70+
"name": "Debug Product Service",
71+
"type": "node",
72+
"request": "attach",
73+
"port": 9231,
74+
"restart": true,
75+
"sourceMaps": true,
76+
"remoteRoot": "/app",
77+
"localRoot": "${workspaceFolder}",
78+
"outFiles": [
79+
"${workspaceFolder}/dist/apps/product/**/*.js",
80+
"${workspaceFolder}/dist/libs/**/*.js"
81+
],
82+
"resolveSourceMapLocations": [
83+
"${workspaceFolder}/**",
84+
"!**/node_modules/**"
85+
],
86+
"skipFiles": ["<node_internals>/**"],
87+
"trace": true,
88+
"sourceMapPathOverrides": {
89+
"webpack:///./~/*": "${workspaceFolder}/node_modules/*",
90+
"webpack:///./*": "${workspaceFolder}/*",
91+
"webpack:///*": "*"
92+
}
1993
}
2094
]
2195
}

README.md

Lines changed: 80 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
<img width="100px" alt="Temporal for Durable Executions" src="https://avatars.githubusercontent.com/u/56493103?s=200&v=4">
99
</p>
1010

11-
> **ProjectX** is a comprehensive full-stack template designed to simplify the development of scalable and resilient applications using **React** and **Temporal**. By integrating Temporals advanced workflow orchestration with Reacts dynamic frontend framework, ProjectX enables developers to build applications with durable executions and seamless communication between services.
11+
> **ProjectX** is a comprehensive full-stack template designed to simplify the development of scalable and resilient applications using **React** and **Temporal**. By integrating Temporal's advanced workflow orchestration with React's dynamic frontend framework, ProjectX enables developers to build applications with durable executions and seamless communication between services.
1212
1313
## Notable Links 🤓
1414

1515
- [Get started with Temporal and TypeScript](https://github.com/temporalio/sdk-typescript)
16+
- [Workflow Messages - TypeScript SDK](https://docs.temporal.io/develop/typescript/message-passing)
1617

1718
### Public Courses
1819

@@ -50,45 +51,47 @@ Additionally, workflows support scheduled and time-based executions with configu
5051

5152
**Batch Processing:** Handling large-scale batch jobs with retry mechanisms and progress monitoring.
5253

53-
## Setting Up 🛠️
54+
## Getting Started 🚀
5455

55-
### Requirements 🧰
56+
### Prerequisites 🧰
5657

58+
- [Docker Compose](https://docs.docker.com/compose/install)
5759
- [Node.js LTS Version](https://nodejs.org)
5860
- [Git](https://git-scm.com/downloads)
59-
- [Docker Compose](https://docs.docker.com/compose/install)
6061
- Code editor:
6162
- [VSCode](https://code.visualstudio.com/)
6263
- [Cursor](https://www.cursor.com/)
6364

64-
### From Linux/Mac 
65+
### Quick Setup 🛠️
6566

66-
- Install Homebrew
67-
- Install tools using Homebrew:
68-
```sh
69-
brew install node
70-
brew install git
71-
brew install docker-compose
72-
npm add --global nx@latest
67+
1. **Clone and Setup Environment:**
68+
```bash
69+
git clone https://github.com/proyecto26/projectx.git
70+
cd projectx
71+
cp .env.example .env
7372
```
7473

75-
### Documentation 📚
76-
77-
- **FrontEnd:**
78-
Commands used to create the project and frontend structure (Nx, RemixJS, etc) [here](./docs/frontend/README.md).
79-
80-
- **BackEnd:**
81-
Commands used to create the services (NestJS, Temporal, etc) [here](./docs/backend/README.md).
74+
2. **Start Development Environment:**
75+
```bash
76+
# Build and start all services (db, temporal, backend services)
77+
docker-compose up -d
8278

83-
## Usage 🏃
79+
# View service logs
80+
docker-compose logs -f [service]
8481

85-
### Monorepo
82+
# Start web application
83+
npm install
84+
npm run dev:web
85+
```
8686

87-
Instructions to use Nx CLI [here](./docs/NX_README.md).
87+
### Documentation 📚
8888

89-
For more information on using Nx, refer to the [Nx documentation](https://nx.dev/getting-started/intro).
89+
For detailed information about the project, please refer to:
90+
- [Architecture Overview](./docs/architecture/README.md)
91+
- [Frontend Guide](./docs/frontend/README.md)
92+
- [Backend Guide](./docs/backend/README.md)
9093

91-
### Project Structure Overview
94+
## Project Structure Overview
9295

9396
<img width="1643" alt="image" src="https://github.com/user-attachments/assets/82e99efc-640d-4ba4-a485-c92c0184f473">
9497

@@ -113,6 +116,10 @@ For more information on using Nx, refer to the [Nx documentation](https://nx.dev
113116
- **Purpose**: Manages order processing, checkout, and payment handling.
114117
- **Key Features**: Cart management, order tracking, and payment integration.
115118
119+
- **apps/product**:
120+
- **Purpose**: Manages product catalog and inventory.
121+
- **Key Features**: Product listing, details, and inventory management.
122+
116123
- **apps/web**:
117124
- **Purpose**: The main web application interface.
118125
- **Key Features**: User interaction with the system.
@@ -152,65 +159,76 @@ For more information on using Nx, refer to the [Nx documentation](https://nx.dev
152159
```
153160
</details>
154161

155-
### Run the web app
156162

157-
```sh
158-
npm run dev:web
159-
```
160163

161-
### Run the ui lib (See all the UI components)
162164

163-
```sh
164-
npm run storybook
165-
```
165+
> [!TIP]
166+
> View the Database diagram [here](./libs/backend/db/README.md).
166167
167-
### Run services with Docker Compose
168168

169-
- Build the images:
170-
```sh
171-
docker-compose build --no-cache
172-
```
173169

174-
- Run the services:
175-
```sh
176-
docker-compose up -d
177-
```
178-
179-
- Delete the services:
180-
```sh
181-
docker-compose down --volumes
182-
```
183170

184-
## Explore the project 👀
171+
## Development Tools 🔧
185172

186-
```sh
173+
### Monorepo Management
174+
```bash
175+
# View project structure
187176
npx nx show projects
188177
npx nx graph
189-
```
190-
191-
View the Database diagram [here](./libs/backend/db/README.md).
192178

193-
Do you want to change the path of a project to decide your own organization? No problem:
194-
```sh
179+
# Move project location
195180
npx nx g @nx/workspace:move --project core libs/backend/common
196181
```
197182

198-
## Update project ⚡
183+
### UI Development
184+
```bash
185+
# Run Storybook
186+
npm run storybook
187+
```
199188

200-
```sh
189+
### Project Updates
190+
```bash
201191
npx nx migrate latest
202192
npx nx migrate --run-migrations
203193
```
204194

205-
## Docker 🚢
195+
## Docker Configuration 🐳
206196

207-
- Images:
208-
* https://registry.hub.docker.com/r/postgis/postgis/
209-
* https://registry.hub.docker.com/r/temporalio/auto-setup
210-
* https://registry.hub.docker.com/r/temporalio/admin-tools
211-
* https://registry.hub.docker.com/r/temporalio/ui
197+
Services defined in [docker-compose.yml](./docker-compose.yml):
198+
- PostgreSQL with PostGIS
199+
- Temporal server and UI
200+
- Auth, Order, and Product services
212201

213-
All the images needed to run this project in development are listed in the [docker-compose.yml](./docker-compose.yml) file.
202+
### Common Commands
203+
```bash
204+
# Build fresh images
205+
docker-compose build --no-cache
206+
207+
# Start services
208+
docker-compose up -d
209+
210+
# Remove services and volumes
211+
docker-compose down --volumes
212+
```
213+
214+
## Payment Providers
215+
216+
- Stripe:
217+
- [Webhooks](https://docs.stripe.com/webhooks?lang=node)
218+
- [Stripe Webhook integration](https://docs.stripe.com/api/webhook_endpoints)
219+
- [Stripe Checkout](https://docs.stripe.com/payments/checkout)
220+
- [Webhooks Dashboard](https://dashboard.stripe.com/test/workbench/webhooks)
221+
- [Automatic fulfillment Orders](https://docs.stripe.com/checkout/fulfillment)
222+
- [Interactive webhook endpoint builder](https://docs.stripe.com/webhooks/quickstart)
223+
- [Trigger webhook events with the Stripe CLI](https://docs.stripe.com/stripe-cli/triggers)
224+
- [Testing cards](https://docs.stripe.com/testing#cards)
225+
- Stripe commands for testing webhooks:
226+
```bash
227+
brew install stripe/stripe-cli/stripe
228+
stripe login --api-key ...
229+
stripe trigger payment_intent.succeeded
230+
stripe listen --forward-to localhost:8081/order/webhook
231+
```
214232

215233
## Supporting 🍻
216234
I believe in Unicorns 🦄

apps/auth/project.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,35 @@
55
"projectType": "application",
66
"tags": [],
77
"targets": {
8+
"build": {
9+
"executor": "@nx/webpack:webpack",
10+
"outputs": ["{options.outputPath}"],
11+
"defaultConfiguration": "production",
12+
"options": {
13+
"target": "node",
14+
"compiler": "tsc",
15+
"outputPath": "dist/apps/auth",
16+
"main": "apps/auth/src/main.ts",
17+
"tsConfig": "apps/auth/tsconfig.app.json",
18+
"assets": [
19+
"apps/auth/src/assets",
20+
"apps/auth/src/workflows"
21+
],
22+
"isolatedConfig": true,
23+
"webpackConfig": "apps/auth/webpack.config.js"
24+
},
25+
"configurations": {
26+
"development": {
27+
"mode": "development"
28+
},
29+
"production": {
30+
"mode": "production"
31+
}
32+
}
33+
},
834
"serve": {
935
"executor": "@nx/js:node",
1036
"defaultConfiguration": "development",
11-
"dependsOn": ["build"],
1237
"options": {
1338
"buildTarget": "auth:build",
1439
"runBuildTargetDependencies": false

apps/auth/src/app/app.controller.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import { AppService } from './app.service';
1515
export class AppController {
1616
constructor(private readonly appService: AppService) {}
1717

18+
/**
19+
* Endpoint to initiate the login process by sending a verification email.
20+
* @param body AuthLoginDto containing the user's email.
21+
* @returns A message indicating the email was sent.
22+
*/
1823
@ApiOperation({
1924
summary: 'Login with email',
2025
description: 'This endpoint allow a user to login with email',
@@ -28,9 +33,14 @@ export class AppController {
2833
@Post('login')
2934
@HttpCode(HttpStatus.CREATED)
3035
login(@Body() body: AuthLoginDto) {
31-
return this.appService.sendLoginEmail(body);
36+
return this.appService.login(body);
3237
}
3338

39+
/**
40+
* Endpoint to verify the login code and authenticate the user.
41+
* @param body AuthVerifyDto containing the user's email and verification code.
42+
* @returns AuthResponseDto containing the access token and user information.
43+
*/
3444
@ApiOperation({
3545
summary: 'Verify login code',
3646
description: 'This endpoint allow a user to verify the login code',

0 commit comments

Comments
 (0)