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

Update the typescript examples #313

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
107 changes: 107 additions & 0 deletions examples/port-ts/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import {
Action
} from '@port-labs/port';


const doSomethingAction = new Action("doSomethingAction", {
title: "Do Something",
identifier: "do-something",
icon: "Terraform",
description: "This action does something",
selfServiceTrigger: {
operation: "DAY-2",
blueprintIdentifier: "service",
userProperties: {
stringProps: {
myStringIdentifier: {
title: "My String Identifier",
required: true,
format: "entity",
blueprint: "githubPullRequest",
dataset: {
combinator: "and",
rules: [{
property: "$title",
operator: "contains",
value: {
jqQuery: "\"Bump\"", // filter PRs with title containing "Bump" i.e dependabot PRs
},
}],
},
},
},
numberProps: {
myNumberIdentifier: {
title: "My Number Identifier",
required: true,
maximum: 100,
minimum: 0,
},
},
booleanProps: {
myBooleanIdentifier: {
title: "My Boolean Identifier",
required: true,
},
},
objectProps: {
myObjectIdentifier: {
title: "My Object Identifier",
required: true,
},
},
arrayProps: {
myArrayIdentifier: {
title: "My Array Identifier",
required: true,
stringItems: {
format: "entity",
blueprint: "githubPullRequest",
dataset: JSON.stringify({
combinator: "and",
rules: [{
property: "$title",
operator: "contains",
value: "Bump", // filter PRs with title containing "Bump" i.e dependabot PRs
}],
}),
},
},
},
},
},
webhookMethod: {
url: "https://myserver.app/hook",
body: JSON.stringify({
myStringIdentifier: "{{.inputs.myStringIdentifier}}",
myNumberIdentifier: "{{.inputs.myNumberIdentifier}}",
myBooleanIdentifier: "{{.inputs.myBooleanIdentifier}}",
myObjectIdentifier: "{{.inputs.myObjectIdentifier}}",
myArrayIdentifier: "{{.inputs.myArrayIdentifier}}",
runId: "{{.run.id}}",
fullEntity: "{{.entity}}",
partialEntity: {
id: "{{.entity.identifier}}",
type: "{{.entity.title}}",
url: "{{.entity.properties.url}}",
defaultBranch: "{{.entity.properties.defaultBranch}}",
createdAt: "{{.entity.createdAt}}",
},
triggeredBy: "{{.trigger.by.user.email}}",
triggeredAt: "{{.trigger.at}}",
triggeredFrom: "{{.trigger.origin}}",
actionType: "{{.trigger.operation}}",
action: "{{.action}}",
}),
headers: {
runId: "{{.run.id}}",
},
method: "POST",
agent: "false",
synchronized: "false",
},
});

export const actions = {
doSomethingAction,
};
25 changes: 25 additions & 0 deletions examples/port-ts/blueprints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as port from "@port-labs/port";

export const blueprint = new port.Blueprint("microservice", {
identifier: "microservice",
title: "Microservice",
properties: {
stringProps: {
"language": {
default: "Go",
}
}
}
});

export const entity = new port.Entity("monolith", {
identifier: "monolith",
title: "monolith",
blueprint: blueprint.identifier,
properties: {
stringProps: {
"language": "Node",
}
}
});

28 changes: 4 additions & 24 deletions examples/port-ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
import * as port from "@port-labs/port";

export const blueprint = new port.Blueprint("microservice", {
identifier: "microservice",
title: "Microservice",
properties: {
stringProps: {
"language": {
default: "Go",
}
}
}
});

export const entity = new port.Entity("monolith", {
identifier: "monolith",
title: "monolith",
blueprint: blueprint.identifier,
properties: {
stringProps: {
"language": "Node",
}
}
});
import * as actions from "./actions";
import * as pages from "./pages";
import * as blueprints from "./blueprints";

export const resources = { blueprints, actions, pages };
150 changes: 150 additions & 0 deletions examples/port-ts/microservices.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Microservices Architecture Guide

## Table of Contents
1. [Overview](#overview)
2. [Microservices Components](#microservices-components)
3. [How to Use This Guide](#how-to-use-this-guide)
4. [Additional Resources](#additional-resources)
5. [Service Details](#service-details)
- [Auth Service](#auth-service)
- [User Service](#user-service)
- [Product Service](#product-service)
- [Order Service](#order-service)
- [Shipping Service](#shipping-service)
- [Notification Service](#notification-service)
- [Recommendation Service](#recommendation-service)
6. [Tips for Development](#tips-for-development)
- [Containerization](#containerization)
- [Error Handling](#error-handling)
- [Testing Strategies](#testing-strategies)
7. [Shared Knowledge](#shared-knowledge)
- [Microservices Architecture](#microservices-architecture)
- [Programming Languages](#programming-languages)
- [Design Patterns](#design-patterns)
- [Deployment Strategies](#deployment-strategies)
- [Cloud Services](#cloud-services)

## Overview

Our SaaS application is built on a microservices architecture, where different components handle specific functionalities independently. Each microservice is responsible for a well-defined set of tasks, fostering modularity, scalability, and maintainability.

## Microservices Components

| Service Name | Responsibilities | Team | Upstream Services | Downstream Services |
|--------------------|-------------------------------------------------------|----------------------|-----------------------------|-----------------------------|
| **Auth Service** | User authentication and authorization | Security Team | Identity Provider | User Management Service |
| **User Service** | User management and profile information | User Management Team | Auth Service | Notification Service |
| **Product Service**| Product catalog, inventory, and pricing information | Product Team | Auth Service, Order Service | Order Service, Recommendation Service |
| **Order Service** | Order processing and fulfillment | Order Management Team| Auth Service, Product Service| Shipping Service |
| **Shipping Service**| Shipping and delivery tracking | Logistics Team | Order Service | |
| **Notification Service** | Sending notifications to users | Communication Team | User Service, Order Service | |
| **Recommendation Service** | Product recommendations for users | Personalization Team| Product Service | |

## How to Use This Guide

1. **Responsibilities:** Understand the primary responsibilities of each microservice.
2. **Team:** Identify the team responsible for maintaining each microservice.
3. **Upstream Services:** Know which services provide data to the current service.
4. **Downstream Services:** Identify services that consume data from the current service.

## Additional Resources

- [GitHub Repository](https://github.com/yourorganization/saas-microservices)
- [API Documentation](https://api.yoursaas.com/docs)

Feel free to explore our GitHub repository for code implementations and check the API documentation for details on interacting with individual services.

## Service Details

### Auth Service
- **Architecture:** RESTful API with OAuth 2.0
- **Language:** Node.js
- **Design Patterns:** MVC, JWT for authentication
- **Frameworks:** Express.js, Passport.js
- **Deployment:** Docker containers on Kubernetes
- **Cloud Services:** AWS Cognito for user identity

### User Service
- **Architecture:** Microservices with RESTful endpoints
- **Language:** Java
- **Design Patterns:** CQRS, Event Sourcing
- **Frameworks:** Spring Boot
- **Deployment:** AWS ECS (Elastic Container Service)
- **Cloud Services:** Amazon RDS for user data storage

### Product Service
- **Architecture:** Microservices with GraphQL API
- **Language:** Python
- **Design Patterns:** Hexagonal Architecture
- **Frameworks:** Flask
- **Deployment:** Azure Functions
- **Cloud Services:** Azure Cosmos DB for product data

### Order Service
- **Architecture:** Event-Driven with message queues
- **Language:** Go
- **Design Patterns:** Saga pattern
- **Frameworks:** Gin
- **Deployment:** Serverless on AWS Lambda
- **Cloud Services:** AWS SNS/SQS for event handling

### Shipping Service
- **Architecture:** Microservices with RESTful API
- **Language:** Ruby
- **Design Patterns:** Singleton, Strategy for shipping providers
- **Frameworks:** Ruby on Rails
- **Deployment:** Heroku
- **Cloud Services:** Custom Docker images stored on Docker Hub

### Notification Service
- **Architecture:** Pub-Sub with message brokers
- **Language:** TypeScript
- **Design Patterns:** Observer pattern
- **Frameworks:** NestJS
- **Deployment:** Azure Kubernetes Service (AKS)
- **Cloud Services:** Azure Service Bus for message brokering

### Recommendation Service
- **Architecture:** Microservices with RESTful API
- **Language:** Kotlin
- **Design Patterns:** Builder pattern
- **Frameworks:** Ktor
- **Deployment:** Google Kubernetes Engine (GKE)
- **Cloud Services:** Google Cloud Firestore for recommendation data

## Tips for Development

### Containerization
- **Tip 1:** Ensure each microservice is encapsulated in a Docker container for consistency across environments.
- **Tip 2:** Leverage multi-stage Docker builds to minimize image size and improve security.
- **Tip 3:** Use Docker Compose for local development environments that mimic production setups.

### Error Handling
- **Tip 4:** Implement detailed error messages and logging to facilitate debugging in a distributed environment.
- **Tip 5:** Utilize centralized logging systems for monitoring and troubleshooting across microservices.

### Testing Strategies
- **Tip 6:** Adopt a combination of unit, integration, and end-to-end testing for comprehensive test coverage.
- **Tip 7:** Implement contract testing to validate communication between microservices.


## Shared Knowledge

### Microservices Architecture
Microservices architecture is a design approach where a system is composed of small, independent services that communicate over well-defined APIs. Key principles include modularity, autonomy, resilience, and continuous delivery.

### Programming Languages
Our tech stack includes diverse programming languages such as Node.js, Java, Python, Go, Ruby, and TypeScript. Each language is chosen based on its suitability for the specific microservice's requirements.

### Design Patterns
Design patterns like MVC, CQRS, Event Sourcing, and others are employed to solve common architectural challenges. These patterns ensure scalability, maintainability, and flexibility in our microservices.

### Deployment Strategies
Microservices are deployed using various strategies, including containerization with Docker, serverless architectures, and orchestration with Kubernetes. These approaches optimize scalability and resource utilization.

### Cloud Services
Our infrastructure relies on cloud services from providers like AWS, Azure, and Google Cloud. These services include managed databases, serverless computing, message brokers, and identity management solutions.

Feel free to explore and contribute to our shared knowledge. Knowledge sharing is fundamental to our collaborative and innovative development culture.

Happy coding!
Loading