Skip to content

Commit b40a2fb

Browse files
committed
feat(core): user, Shop - entities, send email via SES, serverless oflline
1 parent 4244551 commit b40a2fb

24 files changed

+12484
-147
lines changed

.eslintrc.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
env: {
3+
es2021: true,
4+
node: true,
5+
},
6+
extends: [
7+
'airbnb-base',
8+
],
9+
parser: '@typescript-eslint/parser',
10+
parserOptions: {
11+
ecmaVersion: 'latest',
12+
sourceType: 'module',
13+
},
14+
plugins: [
15+
'@typescript-eslint',
16+
],
17+
rules: {
18+
'import/no-unresolved': 'off',
19+
'import/extensions': 'off',
20+
'import/no-import-module-exports': 'off',
21+
'import/prefer-default-export': 'off',
22+
'no-useless-constructor': 'off',
23+
'no-unused-vars': 'off',
24+
'no-empty-function': 'off',
25+
'import/no-extraneous-dependencies': 'off',
26+
'no-extra-semi': 'off',
27+
'dot-notation': 'off',
28+
},
29+
};

.gitignore

+10-126
Original file line numberDiff line numberDiff line change
@@ -1,130 +1,14 @@
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
1+
# package directories
2+
node_modules
3+
jspm_packages
1094

1105
# 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
6+
.serverless
1217

122-
# Stores VSCode versions used for testing VSCode extensions
123-
.vscode-test
8+
# esbuild directories
9+
.esbuild
10+
.dynamodb
11+
.nvmrc
12412

125-
# yarn v2
126-
.yarn/cache
127-
.yarn/unplugged
128-
.yarn/build-state.yml
129-
.yarn/install-state.gz
130-
.pnp.*
13+
# autogenerated files
14+
swagger

LICENSE

-21
This file was deleted.

README.md

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
# Description
2+
It is a serverless application that uses AWS lambda, dynamodb, and api gateway. It is written in typescript and uses the serverless framework.
3+
4+
# Setup
5+
## Prerequisites
6+
- nodejs
7+
- npm
8+
- serverless framework
9+
- aws cli
10+
- aws credentials
11+
- dynamodb local
12+
- dynamodb admin
13+
- dynamodb migrate
14+
15+
# Features
16+
17+
- User
18+
- Create a user
19+
- Get a user
20+
- Update a user
21+
- Delete a user
22+
- Shop
23+
- Create a shop
24+
- Get a shop
25+
- Mail - send an email via [AWS SES](https://aws.amazon.com/ses/)
26+
27+
## Installation
28+
29+
Setup npm dependencies
30+
31+
```bash
32+
npm install
33+
```
34+
35+
Setup serverless framework
36+
37+
```bash
38+
npm install -g serverless
39+
```
40+
41+
Install dynamodb local
42+
43+
```bash
44+
npx sls dynamodb install
45+
```
46+
47+
Install dynamodb admin
48+
49+
```bash
50+
npm install -g dynamodb-admin
51+
```
52+
after installation, run the following command to start dynamodb admin
53+
```bash
54+
dynamodb-admin
55+
```
56+
_note: admin will be available at http://localhost:8001
57+
58+
Install dynamodb migrate
59+
60+
```bash
61+
npm install -g dynamodb-migrate
62+
```
63+
64+
## Run
65+
```bash
66+
npx serverless offline start --stage=dev
67+
```
68+
69+
## Deploy
70+
```bash
71+
npx serverless deploy --stage=<name>
72+
```
73+
74+
## Remove
75+
```bash
76+
npx serverless remove --stage=<name>
77+
```
78+
79+
# API Documentation
80+
Will be available at http://localhost:3000/swagger
81+
82+
# Project Structure
83+
```bash
84+
src
85+
├── functions
86+
│   ├── mail
87+
│   │   ├── handler.ts
88+
│   │   └── routes.ts
89+
│   ├── shop
90+
│   │   ├── handler.ts
91+
│   │   └── routes.ts
92+
│   └── user
93+
│   ├── handler.ts
94+
│   └── routes.ts
95+
├── libs
96+
│   ├── api-gateway.ts
97+
│   ├── handler-resolver.ts
98+
│   └── lambda.ts
99+
├── model
100+
│   ├── Shop.ts
101+
│   ├── User.ts
102+
│   └── index.ts
103+
└── services
104+
├── index.ts
105+
├── shop-service.ts
106+
└── user-service.ts
107+
```
108+
Each function has its own folder with a handler and routes file. The handler file contains the lambda function and the routes file contains the api gateway routes.
109+
Example of the handler file:
110+
```typescript
111+
const create = middyfy(
112+
{
113+
type: 'object',
114+
required: ['body'],
115+
properties: {
116+
body: {
117+
type: 'object',
118+
required: ['email'],
119+
properties: {
120+
email: { type: 'string', format: 'email' },
121+
},
122+
},
123+
},
124+
},
125+
async (event: APIGatewayProxyEventWithBody<any>): Promise<APIGatewayProxyResult> => {
126+
const user = await userService.create({
127+
email: event.body.email,
128+
userId: uuidv4(),
129+
isVerified: false,
130+
});
131+
132+
return formatJSONResponse({
133+
user,
134+
});
135+
},
136+
);
137+
```
138+
`middify` - is a helper function that wraps the lambda function with params validation and error handling.
139+
140+
# Contributing Guide
141+
## Branching
142+
- `master` - production branch
143+
- `dev` - development branch
144+
- `feature/<name>` - feature branch
145+
- `bugfix/<name>` - bugfix branch
146+
- `hotfix/<name>` - hotfix branch
147+
- `release/<name>` - release branch
148+
- `docs/<name>` - documentation branch
149+
- `test/<name>` - test branch
150+
- `chore/<name>` - chore branch
151+
- `refactor/<name>` - refactor branch
152+
- `style/<name>` - style branch
153+
- `ci/<name>` - ci branch
154+
155+
## Commit Message
156+
```bash
157+
<type>[optional scope]: <description>
158+
```
159+
Example:
160+
```bash
161+
feat(api): send an email to the customer when a product is shipped
162+
```
163+
Commit message should be with the next format - conventionalcommits We are use commitizen for commit message formatting.

0 commit comments

Comments
 (0)