generated from purwadhikafullstack/finpro-nextjs-express-prisma
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2ea6804
Showing
51 changed files
with
10,794 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [18.x] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Build Project | ||
run: | | ||
npm install | ||
npm run build | ||
- name: Deploy to Linode | ||
uses: appleboy/scp-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
password: ${{ secrets.SSH_PASSWORD }} | ||
port: ${{ secrets.SSH_PORT }} | ||
source: './apps/web/.next, ./apps/web/*, ./apps/web/.*, ./apps/api, ./deploy.config.js, ./package*.json, ./turbo.json, ./.husky' | ||
target: '${{ secrets.SSH_FOLDER }}' | ||
- name: Run App | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.SSH_HOST }} | ||
username: ${{ secrets.SSH_USERNAME }} | ||
password: ${{ secrets.SSH_PASSWORD }} | ||
port: ${{ secrets.SSH_PORT }} | ||
script: | | ||
export NVM_DIR=~/.nvm | ||
source ~/.nvm/nvm.sh | ||
cd ${{ secrets.SSH_FOLDER }} | ||
npm install | ||
npx prisma generate --schema=./apps/api/prisma/schema.prisma | ||
pm2 start deploy.config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
.pnp | ||
.pnp.js | ||
|
||
# testing | ||
coverage | ||
|
||
# next.js | ||
.next/ | ||
out/ | ||
build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# turbo | ||
.turbo | ||
|
||
# vercel | ||
.vercel | ||
|
||
# others | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx --no -- commitlint --edit ${1} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env sh | ||
. "$(dirname -- "$0")/_/husky.sh" | ||
|
||
npx lint-staged | ||
# npx turbo run test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"*.{ts,js,tsx,jsx},!commitlint.config.js": [ | ||
"eslint . --ext js --report-unused-disable-directives --max-warnings 0", | ||
"prettier --write" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
auto-install-peers = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# Purwadhika Final Project Repository | ||
|
||
This project uses React.js with NextJS for the frontend, Express.js for the backend, and TurboRepo for monorepo management, facilitating rapid development of a scalable web application with streamlined collaboration and efficient server-client interactions. | ||
|
||
## Available Scripts | ||
|
||
### `npm run dev` | ||
|
||
Runs the app in the development mode. | ||
|
||
Open [http://localhost:5173](http://localhost:5173) to view it in the browser. For API, you can access it in [http://localhost:8000/api](http://localhost:8000/api). The app will reload if you make edits. | ||
|
||
### `npm run build` | ||
|
||
Builds the app for production to the `dist` folder for each project. | ||
|
||
### `npm run serve` | ||
|
||
Runs the app in the production mode. | ||
|
||
### `npm run <task> --workspace=<app-name>` | ||
|
||
Run command on specific app (install package, run test, etc). | ||
|
||
### `npm run <task> --workspace=<app-name> -- --<option>` | ||
|
||
Run command on specific app with options. | ||
|
||
Example : `npm run seqeulize --workspace=api -- --db:migrate` | ||
|
||
# Rules | ||
|
||
## Commit & Pull Request | ||
|
||
- Always use [conventional commit message](https://www.conventionalcommits.org/en/v1.0.0/) when committing changes or creating pull request | ||
- **"Squash and Merge"** your pull request to main branch | ||
|
||
## Naming Convention | ||
|
||
### REST API | ||
|
||
- Always use [REST API naming convention](https://restfulapi.net/resource-naming/) | ||
|
||
### File Naming Conventions: | ||
|
||
1. **Use CamelCase for filenames:** | ||
- Begin filenames with a lowercase letter. | ||
- For multiple words, capitalize the first letter of each subsequent word. | ||
- Example: `index.js`, `userModel.js`, `dataAccess.js` | ||
|
||
2. **Use Descriptive Names:** | ||
- Choose names that accurately describe the file's purpose or content. | ||
- Avoid overly generic names like `utils.js` unless the file genuinely contains utility functions. | ||
|
||
3. **Follow Naming Conventions for Specific File Types:** | ||
- For configuration files, use names like `.env`, `config.js`, or `settings.json`. | ||
- Use consistent naming for test files, such as appending `.test.js` or `.spec.js` to the filename being tested. | ||
- Use `package.json` for the project's metadata and dependencies. | ||
|
||
4. **Separate Concerns with File Naming:** | ||
- Follow a modular structure for different concerns (e.g., `userController.js`, `userService.js`, `userModel.js` for a user-related module). | ||
|
||
### Folder Naming Conventions: | ||
|
||
1. **Use Singular or Plural Naming:** | ||
- Choose a consistent convention for naming folders (e.g., `models` or `model`, `routes` or `route`). | ||
|
||
2. **Avoid Special Characters and Spaces:** | ||
- Use hyphens (`-`) or underscores (`_`) for separating words in folder names, but avoid spaces or special characters. | ||
|
||
3. **Use Descriptive Names for Folders:** | ||
- Name folders according to their content or purpose (e.g., `controllers`, `services`, `utils`, `tests`, `public`, `views`, etc.). | ||
|
||
4. **Nested Folder Structure:** | ||
- Create a logical and organized folder structure based on the project's architecture. | ||
- For larger projects, consider organizing files by features/modules (Feature-Based Structure) or layer-based (Layered Structure). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NODE_ENV=development | ||
PORT=8000 | ||
DATABASE_URL="mysql://root@localhost:3306/mydb" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
# Keep environment variables out of version control | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "api", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"dev": "cross-env NODE_ENV=development ts-node-dev -r tsconfig-paths/register src/index.ts", | ||
"build": "tsc && tsc-alias", | ||
"serve": "cross-env NODE_ENV=production node dist/index.js", | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"prisma": "npx prisma" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@prisma/client": "^5.7.1", | ||
"cors": "^2.8.5", | ||
"cross-env": "^7.0.3", | ||
"dotenv": "^16.3.1", | ||
"express": "^4.18.2", | ||
"ts-node": "^10.9.2", | ||
"ts-node-dev": "^2.0.0", | ||
"typescript": "^5.3.3" | ||
}, | ||
"devDependencies": { | ||
"@types/cors": "^2.8.17", | ||
"@types/express": "^4.17.21", | ||
"prisma": "^5.7.1", | ||
"tsc-alias": "^1.8.10", | ||
"tsconfig-paths": "^4.2.0" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
apps/api/prisma/migrations/20231228030315_sample/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
-- CreateTable | ||
CREATE TABLE `samples` ( | ||
`id` INTEGER NOT NULL AUTO_INCREMENT, | ||
`name` VARCHAR(191) NOT NULL, | ||
`code` VARCHAR(191) NOT NULL, | ||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
`updatedAt` DATETIME(3) NOT NULL, | ||
|
||
UNIQUE INDEX `samples_code_key`(`code`), | ||
PRIMARY KEY (`id`) | ||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Please do not edit this file manually | ||
# It should be added in your version-control system (i.e. Git) | ||
provider = "mysql" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// This is your Prisma schema file, | ||
// learn more about it in the docs: https://pris.ly/d/prisma-schema | ||
|
||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "mysql" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Sample { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
code String @unique | ||
createdAt DateTime @default(now()) | ||
updatedAt DateTime @updatedAt | ||
@@map("samples") // if you want to use snake_case format | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import express, { | ||
json, | ||
urlencoded, | ||
Express, | ||
Request, | ||
Response, | ||
NextFunction, | ||
Router, | ||
} from 'express'; | ||
import cors from 'cors'; | ||
import { PORT } from './config'; | ||
import { SampleRouter } from './routers/sample.router'; | ||
|
||
export default class App { | ||
private app: Express; | ||
|
||
constructor() { | ||
this.app = express(); | ||
this.configure(); | ||
this.routes(); | ||
this.handleError(); | ||
} | ||
|
||
private configure(): void { | ||
this.app.use(cors()); | ||
this.app.use(json()); | ||
this.app.use(urlencoded({ extended: true })); | ||
} | ||
|
||
private handleError(): void { | ||
// not found | ||
this.app.use((req: Request, res: Response, next: NextFunction) => { | ||
if (req.path.includes('/api/')) { | ||
res.status(404).send('Not found !'); | ||
} else { | ||
next(); | ||
} | ||
}); | ||
|
||
// error | ||
this.app.use( | ||
(err: Error, req: Request, res: Response, next: NextFunction) => { | ||
if (req.path.includes('/api/')) { | ||
console.error('Error : ', err.stack); | ||
res.status(500).send('Error !'); | ||
} else { | ||
next(); | ||
} | ||
}, | ||
); | ||
} | ||
|
||
private routes(): void { | ||
const sampleRouter = new SampleRouter(); | ||
|
||
this.app.get('/api', (req: Request, res: Response) => { | ||
res.send(`Hello, Purwadhika Student API!`); | ||
}); | ||
|
||
this.app.use('/api/samples', sampleRouter.getRouter()); | ||
} | ||
|
||
public start(): void { | ||
this.app.listen(PORT, () => { | ||
console.log(` ➜ [API] Local: http://localhost:${PORT}/`); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { config } from 'dotenv'; | ||
import { resolve } from 'path'; | ||
|
||
export const NODE_ENV = process.env.NODE_ENV || 'development'; | ||
|
||
const envFile = NODE_ENV === 'development' ? '.env.development' : '.env'; | ||
|
||
config({ path: resolve(__dirname, `../${envFile}`) }); | ||
config({ path: resolve(__dirname, `../${envFile}.local`), override: true }); | ||
|
||
// Load all environment variables from .env file | ||
|
||
export const PORT = process.env.PORT || 8000; | ||
export const DATABASE_URL = process.env.DATABASE_URL || ''; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const authUser = () => { | ||
|
||
} |
Oops, something went wrong.