Skip to content

Commit 0a1fd65

Browse files
authored
Merge pull request #151 from tebanieo/recipe-backend
NERDS Stack - Recipe backend - Initial Phase
2 parents 3b534ed + d1709a5 commit 0a1fd65

File tree

23 files changed

+920
-0
lines changed

23 files changed

+920
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ workshops/relational-migration/setenv.sh
2727
workshops/relational-migration/setenvd.sh
2828
workshops/relational-migration/source-tables/app_db.*
2929

30+
**/.aws-sam/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Recipe Example
2+
3+
This is the first full example in the NERDS stack, this examples fully uses SAM instead of ExpressJS for the backend. We will be working with a recipe sharing website! Where users can create recipes, collections, comment, share and subscribe to users, and at the end they could add elemnts to their shopping lists to buy the goods required to cook the recipe.
4+
5+
**TODO**: This project is still work in progress and it needs additional documentation, we will be releasing the features by phases (which will be tracked in the release table below), the first one is an initial portion of the backend with only users and recipes interactions, and we will build all the way up to the full application, this approach is to make it easier to consume rather than a big bang!
6+
7+
To execute this project please:
8+
9+
1. Open the [backend](./backend/README.md) folder with instructions to execute the backend locally.
10+
2. Open the [frontend](./frontend/README.md) folder with instructions to execute the front end and run your web applicaation locally.
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
.pnpm-debug.log*
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
*.lcov
25+
26+
# nyc test coverage
27+
.nyc_output
28+
29+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30+
.grunt
31+
32+
# Bower dependency directory (https://bower.io/)
33+
bower_components
34+
35+
# node-waf configuration
36+
.lock-wscript
37+
38+
# Compiled binary addons (https://nodejs.org/api/addons.html)
39+
build/Release
40+
41+
# Dependency directories
42+
node_modules/
43+
jspm_packages/
44+
45+
# Snowpack dependency directory (https://snowpack.dev/)
46+
web_modules/
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Optional npm cache directory
52+
.npm
53+
54+
# Optional eslint cache
55+
.eslintcache
56+
57+
# Optional stylelint cache
58+
.stylelintcache
59+
60+
# Microbundle cache
61+
.rpt2_cache/
62+
.rts2_cache_cjs/
63+
.rts2_cache_es/
64+
.rts2_cache_umd/
65+
66+
# Optional REPL history
67+
.node_repl_history
68+
69+
# Output of 'npm pack'
70+
*.tgz
71+
72+
# Yarn Integrity file
73+
.yarn-integrity
74+
75+
# dotenv environment variable files
76+
.env
77+
.env.development.local
78+
.env.test.local
79+
.env.production.local
80+
.env.local
81+
82+
# parcel-bundler cache (https://parceljs.org/)
83+
.cache
84+
.parcel-cache
85+
86+
# Next.js build output
87+
.next
88+
out
89+
90+
# Nuxt.js build / generate output
91+
.nuxt
92+
dist
93+
94+
# Gatsby files
95+
.cache/
96+
# Comment in the public line in if your project uses Gatsby and not Next.js
97+
# https://nextjs.org/blog/next-9-1#public-directory-support
98+
# public
99+
100+
# vuepress build output
101+
.vuepress/dist
102+
103+
# vuepress v2.x temp and cache directory
104+
.temp
105+
.cache
106+
107+
# Docusaurus cache and generated files
108+
.docusaurus
109+
110+
# Serverless directories
111+
.serverless/
112+
113+
# FuseBox cache
114+
.fusebox/
115+
116+
# DynamoDB Local files
117+
.dynamodb/
118+
119+
# TernJS port file
120+
.tern-port
121+
122+
# Stores VSCode versions used for testing VSCode extensions
123+
.vscode-test
124+
125+
# yarn v2
126+
.yarn/cache
127+
.yarn/unplugged
128+
.yarn/build-state.yml
129+
.yarn/install-state.gz
130+
.pnp.*
131+
132+
#Secret Files
133+
.secrets.baseline
134+
135+
#local docker DDB file
136+
.ddb_cid
137+
138+
src/package-lock.json
139+
**/.aws-sam/
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Recipes Backend Example
2+
3+
## Description
4+
5+
This project is a backend service for a recipe management system, built using AWS SAM (Serverless Application Model) and DynamoDB as part of the NERDS stack.
6+
7+
## Prerequisites
8+
9+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/)
10+
- [DynamoDB Local Docker Image](https://hub.docker.com/r/amazon/dynamodb-local)
11+
- [Node v22.3.0](https://nodejs.org/en/blog/release/v22.3.0)
12+
- [AWS JavaScript SDK v3](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/dynamodb/)
13+
- [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html)
14+
15+
## Setup
16+
17+
1. Install dependencies:
18+
19+
```bash
20+
npm install
21+
```
22+
23+
2. Start the local DynamoDB:
24+
25+
```bash
26+
npm run start-db
27+
```
28+
29+
3. Create the recipes table:
30+
31+
```bash
32+
npm run create-recipes-table
33+
```
34+
35+
4. Build the SAM application:
36+
37+
```bash
38+
npm run build-backend
39+
```
40+
41+
5. Start the local API:
42+
43+
```bash
44+
npm run start-backend
45+
```
46+
47+
# Setup
48+
49+
![demo.gif](./documentation/demo.gif)
50+
51+
# Creating an user
52+
53+
![demo-api.gif](./documentation/demo-api.gif)
54+
55+
## Available Scripts
56+
57+
- `npm run start-db`: Start local DynamoDB container
58+
- `npm run stop-db`: Stop and remove local DynamoDB container
59+
- `npm run create-recipes-table`: Create the recipes table in local DynamoDB
60+
- `npm run show-tables`: List tables in local DynamoDB
61+
- `npm run scan-recipes`: Scan all items in the recipes table
62+
- `npm run build-backend`: Build the SAM application, if you change the code in the `src/*` folder you need to rebuild your project.
63+
- `npm run start-backend`: Start the local API
64+
- `npm run create-user`: Create a sample user using curl
65+
66+
## Configuration
67+
68+
The project uses the following configuration (defined in package.json):
69+
70+
- DynamoDB host: `0.0.0.0`
71+
- DynamoDB port: `8000`
72+
- API port: `3000`
73+
- Recipe table name: `recipe_table`
74+
75+
## API Endpoints
76+
77+
- `POST /users`: Create a new user
78+
- `GET /users/{userId}`: Get user details
79+
- `PUT /users/{userId}`: Update user details
80+
- `DELETE /users/{userId}`: Delete a user
81+
- `POST /recipes`: Create a new recipe
82+
- `GET /recipes/{recipeId}`: Get recipe details
83+
- `PUT /recipes/{recipeId}`: Update recipe details
84+
- `DELETE /recipes/{recipeId}`: Delete a recipe
85+
- `GET /recipes`: List all recipes
86+
87+
## Development
88+
89+
To start development:
90+
91+
1. Ensure local DynamoDB is running (`npm run start-db`)
92+
2. Make changes to the Lambda functions in the `src` directory
93+
3. Rebuild the application (`npm run build-backend`)
94+
4. Start the local API (`npm run start-backend`)
95+
5. Test your changes using the provided npm scripts or tools like Postman
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 0.2
2+
phases:
3+
install:
4+
commands:
5+
# Install all dependencies (including dependencies for running tests)
6+
- npm install
7+
pre_build:
8+
commands:
9+
# Discover and run unit tests in the '__tests__' directory
10+
- npm run test
11+
# Remove all unit tests to reduce the size of the package that will be ultimately uploaded to Lambda
12+
- rm -rf ./__tests__
13+
# Remove all dependencies not needed for the Lambda deployment package (the packages from devDependencies in package.json)
14+
- npm prune --production
15+
build:
16+
commands:
17+
# Use AWS SAM to package the application by using AWS CloudFormation
18+
- aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --output-template template-export.yml
19+
artifacts:
20+
type: zip
21+
files:
22+
- template-export.yml
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3.8"
2+
services:
3+
dynamodb-local:
4+
command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data"
5+
image: "amazon/dynamodb-local:latest"
6+
container_name: dynamodb-local-recipe-backend
7+
ports:
8+
- "8000:8000"
9+
volumes:
10+
- "./docker/dynamodb:/home/dynamodblocal/data"
11+
working_dir: /home/dynamodblocal
Binary file not shown.
214 KB
Loading
2.78 MB
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"Parameters": {
3+
"DYNAMODB_ENDPOINT": "http://dynamodb-local:8000"
4+
}
5+
}

0 commit comments

Comments
 (0)