Skip to content

Commit bbae5c1

Browse files
author
Encore
committed
Initial commit
0 parents  commit bbae5c1

31 files changed

Lines changed: 4708 additions & 0 deletions

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.encore
2+
encore.gen.go
3+
encore.gen.cue
4+
/.encore
5+
node_modules
6+
/encore.gen

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Event-Driven Architecture Starter
2+
3+
This is an event-driven microservices application using Pub/Sub for asynchronous communication between services.
4+
5+
The example in this starter is an Uptime Monitoring System that continuously monitors the uptime of a list of websites.
6+
7+
When it detects a website is down, it posts a Slack message notifying that the website is down, and another message when the website is back up again.
8+
9+
It has a react frontend and you can try a demo version [here](https://uptime.encore.build/).
10+
11+
[![Deploy to Encore](https://github.com/encoredev/examples/raw/main/assets/deploytoenc.svg)](https://app.encore.cloud/create-app/clone/ts-uptime)
12+
13+
![Frontend](https://encore.dev/assets/tutorials/uptime/frontend.png)
14+
![Architecture](https://encore.dev/assets/tutorials/uptime/encore-flow.png)
15+
16+
17+
## Build from scratch with a tutorial
18+
19+
If you prefer, check out the [tutorial](https://encore.dev/docs/ts/tutorials/uptime) to learn how to build this application from scratch.
20+
21+
## Prerequisites
22+
23+
**Install Encore:**
24+
- **macOS:** `brew install encoredev/tap/encore`
25+
- **Linux:** `curl -L https://encore.dev/install.sh | bash`
26+
- **Windows:** `iwr https://encore.dev/install.ps1 | iex`
27+
28+
**Docker:**
29+
1. Install [Docker](https://docker.com)
30+
2. Start Docker
31+
32+
## Create app
33+
34+
Create a local app from this template:
35+
36+
```bash
37+
encore app create uptime-example --example=ts/uptime
38+
```
39+
40+
## Run app locally
41+
42+
Before running your application, make sure you have Docker installed and running. Then run this command from your application's root folder:
43+
44+
```bash
45+
encore run
46+
```
47+
48+
To use the Slack integration, set the Slack Webhook URL (see tutorial above):
49+
```bash
50+
encore secret set --type local,dev,pr,prod SlackWebhookURL
51+
```
52+
53+
**Note:** Cron Jobs do not execute when running locally.
54+
55+
## View the frontend
56+
57+
While `encore run` is running, head over to [http://localhost:4000/](http://localhost:4000/) to view the frontend for your uptime monitor.
58+
59+
## Using the API
60+
61+
Check if a given site is up (defaults to 'https://' if left out):
62+
```bash
63+
curl 'http://localhost:4000/ping/google.com'
64+
```
65+
66+
Add a site to be automatically pinged every 1 hour:
67+
```bash
68+
curl 'http://localhost:4000/site' -d '{"url":"google.com"}'
69+
```
70+
71+
Check all tracked sites immediately:
72+
```bash
73+
curl -X POST 'http://localhost:4000/check-all'
74+
```
75+
76+
Get the current status of all tracked sites:
77+
```bash
78+
curl 'http://localhost:4000/status'
79+
```
80+
81+
## Local Development Dashboard
82+
83+
While `encore run` is running, open [http://localhost:9400/](http://localhost:9400/) to access Encore's [local developer dashboard](https://encore.dev/docs/ts/observability/dev-dash).
84+
85+
Here you can see traces for all requests that you made while using the frontend, see your architecture diagram, and view API documentation in the Service Catalog.
86+
87+
## Connecting to databases
88+
89+
You can connect to your databases via psql shell:
90+
91+
```bash
92+
encore db shell <database-name> --env=local --superuser
93+
```
94+
95+
Learn more in the [CLI docs](https://encore.dev/docs/ts/cli/cli-reference#database-management).
96+
97+
## Deployment
98+
99+
### Self-hosting
100+
101+
See the [self-hosting instructions](https://encore.dev/docs/ts/self-host/build) for how to use `encore build docker` to create a Docker image and configure it.
102+
103+
### Encore Cloud Platform
104+
105+
Deploy your application to a free staging environment in Encore's development cloud using `git push encore`:
106+
107+
```bash
108+
git add -A .
109+
git commit -m 'Commit message'
110+
git push encore
111+
```
112+
113+
You can also open your app in the [Cloud Dashboard](https://app.encore.dev) to integrate with GitHub, or connect your AWS/GCP account, enabling Encore to automatically handle cloud deployments for you.
114+
115+
## Link to GitHub
116+
117+
Follow these steps to link your app to GitHub:
118+
119+
1. Create a GitHub repo, commit and push the app.
120+
2. Open your app in the [Cloud Dashboard](https://app.encore.dev).
121+
3. Go to **Settings ➔ GitHub** and click on **Link app to GitHub** to link your app to GitHub and select the repo you just created.
122+
4. To configure Encore to automatically trigger deploys when you push to a specific branch name, go to the **Overview** page for your intended environment. Click on **Settings** and then in the section **Branch Push** configure the **Branch name** and hit **Save**.
123+
5. Commit and push a change to GitHub to trigger a deploy.
124+
125+
[Learn more in the docs](https://encore.dev/docs/platform/integrations/github)
126+
127+
## Testing
128+
129+
To run tests, configure the `test` command in your `package.json` to the test runner of your choice, and then use the command `encore test` from the CLI. The `encore test` command sets up all the necessary infrastructure in test mode before handing over to the test runner. [Learn more](https://encore.dev/docs/ts/develop/testing)
130+
131+
```bash
132+
encore test
133+
```

encore.app

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"id": "event-driven-architecture-starter123-c7wi",
3+
"lang": "typescript",
4+
"build": {
5+
"docker": {
6+
"bundle_source": true
7+
},
8+
"hooks": {
9+
"postbuild": "npx next build ./frontend"
10+
}
11+
}
12+
}

example-initial-setup.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// This JSON file configures certain behavior when Encore creates the example.
2+
{
3+
// initial_secrets specifies initial values for the secrets
4+
// when creating an example app. It should NOT be used for storing
5+
// actual secrets; it's only for examples.
6+
"initial_secrets": {
7+
"SlackWebhookURL": "" // disable Slack integration to start.
8+
}
9+
}

frontend/.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
.yarn/install-state.gz
8+
9+
# testing
10+
/coverage
11+
12+
# next.js
13+
/.next/
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

frontend/app/favicon.ico

25.3 KB
Binary file not shown.

frontend/app/globals.css

Whitespace-only changes.

frontend/app/layout.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Metadata } from "next";
2+
import { Inter } from "next/font/google";
3+
import "./globals.css";
4+
5+
import Providers from "./providers";
6+
7+
const inter = Inter({ subsets: ["latin"] });
8+
9+
export const metadata: Metadata = {
10+
title: "Create Next App",
11+
description: "Generated by create next app",
12+
};
13+
14+
export default function RootLayout({
15+
children,
16+
}: Readonly<{
17+
children: React.ReactNode;
18+
}>) {
19+
return (
20+
<html lang="en">
21+
<head>
22+
<script src="https://cdn.tailwindcss.com"></script>
23+
<script src="https://encore.dev/encore-toolbar.js"></script>
24+
</head>
25+
<Providers>
26+
<body className={inter.className}>{children}</body>
27+
</Providers>
28+
</html>
29+
);
30+
}

0 commit comments

Comments
 (0)