Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(order): implement order api and workflow #7

Merged
merged 10 commits into from
Jan 31, 2025
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
18 changes: 16 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,29 @@ DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:${POSTGRES_P

# SERVICES SETTINGS
NODE_ENV=development
AUTH_PORT=9095
ORDER_PORT=9096
AUTH_PORT=8081
ORDER_PORT=8082
PRODUCT_PORT=8083
SENDGRID_API_KEY=SG.your_sendgrid_api_key
# REMEMBER TO USE A VALID SENDER EMAIL, more info: https://app.sendgrid.com/settings/sender_auth/senders
[email protected]
EMAIL_FROM_NAME=ProjectX Team

# PAYMENT SETTINGS
# You can find your secret key in your Stripe account
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
# If you are testing your webhook locally with the Stripe CLI you
# can find the endpoint's secret by running `stripe listen`
# Otherwise, find your endpoint's secret in your webhook settings in the Developer Dashboard
STRIPE_WEBHOOK_SECRET=whsec_your_stripe_webhook_signing_secret

# DEVELOPMENT ONLY
NGROK_AUTHTOKEN=your_ngrok_auth_token

# WEB SETTINGS
SESSION_SECRET=your_secret_key_for_sessions
AUTH_API_URL="http://localhost:${AUTH_PORT}"
ORDER_API_URL="http://localhost:${ORDER_PORT}"
PRODUCT_API_URL="http://localhost:${PRODUCT_PORT}"
JWT_SECRET=your_secret_key_for_jwt
76 changes: 75 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"resolveSourceMapLocations": ["${workspaceFolder}/**", "!**/node_modules/**"],
"configurations": [
{
"name": "Web",
Expand All @@ -16,6 +15,81 @@
"console": "internalConsole",
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Debug Auth Service",
"type": "node",
"request": "attach",
"port": 9229,
"restart": true,
"sourceMaps": true,
"remoteRoot": "/app",
"localRoot": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/dist/apps/auth/**/*.js",
"${workspaceFolder}/dist/libs/**/*.js"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
],
"skipFiles": ["<node_internals>/**"],
"trace": true,
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceFolder}/node_modules/*",
"webpack:///./*": "${workspaceFolder}/*",
"webpack:///*": "*"
}
},
{
"name": "Debug Order Service",
"type": "node",
"request": "attach",
"port": 9230,
"restart": true,
"sourceMaps": true,
"remoteRoot": "/app",
"localRoot": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/dist/apps/order/**/*.js",
"${workspaceFolder}/dist/libs/**/*.js"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
],
"skipFiles": ["<node_internals>/**"],
"trace": true,
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceFolder}/node_modules/*",
"webpack:///./*": "${workspaceFolder}/*",
"webpack:///*": "*"
}
},
{
"name": "Debug Product Service",
"type": "node",
"request": "attach",
"port": 9231,
"restart": true,
"sourceMaps": true,
"remoteRoot": "/app",
"localRoot": "${workspaceFolder}",
"outFiles": [
"${workspaceFolder}/dist/apps/product/**/*.js",
"${workspaceFolder}/dist/libs/**/*.js"
],
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"!**/node_modules/**"
],
"skipFiles": ["<node_internals>/**"],
"trace": true,
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceFolder}/node_modules/*",
"webpack:///./*": "${workspaceFolder}/*",
"webpack:///*": "*"
}
}
]
}
142 changes: 80 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
<img width="100px" alt="Temporal for Durable Executions" src="https://avatars.githubusercontent.com/u/56493103?s=200&v=4">
</p>

> **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.
> **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.

## Notable Links 🤓

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

### Public Courses

Expand Down Expand Up @@ -49,45 +50,47 @@ Additionally, workflows support scheduled and time-based executions with configu

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

## Setting Up 🛠️
## Getting Started 🚀

### Requirements 🧰
### Prerequisites 🧰

- [Docker Compose](https://docs.docker.com/compose/install)
- [Node.js LTS Version](https://nodejs.org)
- [Git](https://git-scm.com/downloads)
- [Docker Compose](https://docs.docker.com/compose/install)
- Code editor:
- [VSCode](https://code.visualstudio.com/)
- [Cursor](https://www.cursor.com/)

### From Linux/Mac 
### Quick Setup 🛠️

- Install Homebrew
- Install tools using Homebrew:
```sh
brew install node
brew install git
brew install docker-compose
npm add --global nx@latest
1. **Clone and Setup Environment:**
```bash
git clone https://github.com/proyecto26/projectx.git
cd projectx
cp .env.example .env
```

### Documentation 📚

- **FrontEnd:**
Commands used to create the project and frontend structure (Nx, RemixJS, etc) [here](./docs/frontend/README.md).

- **BackEnd:**
Commands used to create the services (NestJS, Temporal, etc) [here](./docs/backend/README.md).
2. **Start Development Environment:**
```bash
# Build and start all services (db, temporal, backend services)
docker-compose up -d

## Usage 🏃
# View service logs
docker-compose logs -f [service]

### Monorepo
# Start web application
npm install
npm run dev:web
```

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

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

### Project Structure Overview
## Project Structure Overview

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

Expand All @@ -112,6 +115,10 @@ For more information on using Nx, refer to the [Nx documentation](https://nx.dev
- **Purpose**: Manages order processing, checkout, and payment handling.
- **Key Features**: Cart management, order tracking, and payment integration.

- **apps/product**:
- **Purpose**: Manages product catalog and inventory.
- **Key Features**: Product listing, details, and inventory management.

- **apps/web**:
- **Purpose**: The main web application interface.
- **Key Features**: User interaction with the system.
Expand Down Expand Up @@ -151,65 +158,76 @@ For more information on using Nx, refer to the [Nx documentation](https://nx.dev
```
</details>

### Run the web app

```sh
npm run dev:web
```

### Run the ui lib (See all the UI components)

```sh
npm run storybook
```
> [!TIP]
> View the Database diagram [here](./libs/backend/db/README.md).

### Run services with Docker Compose

- Build the images:
```sh
docker-compose build --no-cache
```

- Run the services:
```sh
docker-compose up -d
```

- Delete the services:
```sh
docker-compose down --volumes
```

## Explore the project 👀
## Development Tools 🔧

```sh
### Monorepo Management
```bash
# View project structure
npx nx show projects
npx nx graph
```

View the Database diagram [here](./libs/backend/db/README.md).

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

## Update project ⚡
### UI Development
```bash
# Run Storybook
npm run storybook
```

```sh
### Project Updates
```bash
npx nx migrate latest
npx nx migrate --run-migrations
```

## Docker 🚢
## Docker Configuration 🐳

- Images:
* https://registry.hub.docker.com/r/postgis/postgis/
* https://registry.hub.docker.com/r/temporalio/auto-setup
* https://registry.hub.docker.com/r/temporalio/admin-tools
* https://registry.hub.docker.com/r/temporalio/ui
Services defined in [docker-compose.yml](./docker-compose.yml):
- PostgreSQL with PostGIS
- Temporal server and UI
- Auth, Order, and Product services

All the images needed to run this project in development are listed in the [docker-compose.yml](./docker-compose.yml) file.
### Common Commands
```bash
# Build fresh images
docker-compose build --no-cache

# Start services
docker-compose up -d

# Remove services and volumes
docker-compose down --volumes
```

## Payment Providers

- Stripe:
- [Webhooks](https://docs.stripe.com/webhooks?lang=node)
- [Stripe Webhook integration](https://docs.stripe.com/api/webhook_endpoints)
- [Stripe Checkout](https://docs.stripe.com/payments/checkout)
- [Webhooks Dashboard](https://dashboard.stripe.com/test/workbench/webhooks)
- [Automatic fulfillment Orders](https://docs.stripe.com/checkout/fulfillment)
- [Interactive webhook endpoint builder](https://docs.stripe.com/webhooks/quickstart)
- [Trigger webhook events with the Stripe CLI](https://docs.stripe.com/stripe-cli/triggers)
- [Testing cards](https://docs.stripe.com/testing#cards)
- Stripe commands for testing webhooks:
```bash
brew install stripe/stripe-cli/stripe
stripe login --api-key ...
stripe trigger payment_intent.succeeded
stripe listen --forward-to localhost:8081/order/webhook
```

## Supporting 🍻
I believe in Unicorns 🦄
Expand Down
27 changes: 26 additions & 1 deletion apps/auth/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,35 @@
"projectType": "application",
"tags": [],
"targets": {
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/auth",
"main": "apps/auth/src/main.ts",
"tsConfig": "apps/auth/tsconfig.app.json",
"assets": [
"apps/auth/src/assets",
"apps/auth/src/workflows"
],
"isolatedConfig": true,
"webpackConfig": "apps/auth/webpack.config.js"
},
"configurations": {
"development": {
"mode": "development"
},
"production": {
"mode": "production"
}
}
},
"serve": {
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"dependsOn": ["build"],
"options": {
"buildTarget": "auth:build",
"runBuildTargetDependencies": false
Expand Down
12 changes: 11 additions & 1 deletion apps/auth/src/app/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import { AppService } from './app.service';
export class AppController {
constructor(private readonly appService: AppService) {}

/**
* Endpoint to initiate the login process by sending a verification email.
* @param body AuthLoginDto containing the user's email.
* @returns A message indicating the email was sent.
*/
@ApiOperation({
summary: 'Login with email',
description: 'This endpoint allow a user to login with email',
Expand All @@ -28,9 +33,14 @@ export class AppController {
@Post('login')
@HttpCode(HttpStatus.CREATED)
login(@Body() body: AuthLoginDto) {
return this.appService.sendLoginEmail(body);
return this.appService.login(body);
}

/**
* Endpoint to verify the login code and authenticate the user.
* @param body AuthVerifyDto containing the user's email and verification code.
* @returns AuthResponseDto containing the access token and user information.
*/
@ApiOperation({
summary: 'Verify login code',
description: 'This endpoint allow a user to verify the login code',
Expand Down
Loading
Loading