Skip to content

Commit

Permalink
chore: update scripts in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
aseerkt committed Jul 3, 2024
1 parent 6f3e877 commit daadaa3
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 11 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@

## Tech Stacks

- Frontend - React.js, TailwindCSS
- Backend - Express, socket.io, MongoDB, Redis
- Frontend - React.js, TailwindCSS, React-Query
- Backend - Express, socket.io, PostgreSQL, Redis

## Get Started

### Run final build using docker compose

- Spin up the entire stack (redis, postgres, web, server)
- Spin up the entire stack (Redis, PostgreSQL, React.js, Node.js)
```bash
pnpm docker:build
pnpm docker:up
```
> Make sure ports `6379`,`5432`,`5000` and `3000` are not occupied
- Run migrations
```bash
pnpm docker:db:migrate
Expand All @@ -33,14 +34,19 @@ pnpm docker:db:seed
```
- Go to [http://localhost:3000](http://localhost:3000)

- Stop docker containers
```bash
pnpm docker:down
```

### Development

- Spin up PostgreSQL and Redis
```bash
docker compose up -d
```

> Make sure the ports (mongo: 27017, redis: 6379) are open for connection
> Make sure the ports (postgres: 5432, redis: 6379) are open for connection
- Install dependencies
```bash
Expand Down Expand Up @@ -69,7 +75,7 @@ pnpm dev

- Run playwright e2e tests
```bash
pnpm --filter e2e test
pnpm e2e:test
```
- Run playwright e2e tests in UI mode
```bash
Expand All @@ -80,6 +86,7 @@ pnpm --filter e2e test:ui
pnpm --filter e2e test:codegen
```


## Features Roadmap

### primary goals
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"lint": "pnpm run -r lint",
"prepare": "husky install",
"commitlint": "commitlint --edit",
"docker:build": "docker compose -f docker-compose.prod.yml up --build -d",
"docker:up": "docker compose -f docker-compose.prod.yml up --build -d",
"docker:db:migrate": "docker exec -it mchat-server pnpm migrate:run",
"docker:db:seed": "docker exec -it mchat-server pnpm seed",
"docker:up": "pnpm docker:build && pnpm docker:db-migrate"
"docker:down": "docker compose -f docker-compose.prod.yml down",
"e2e:test": "pnpm --filter e2e test"
},
"keywords": [
"chat", "realtime", "socket.io", "react", "node.js", "react-query"
Expand Down
59 changes: 59 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,25 @@ import {

const createApp = async () => {
if (cluster.isPrimary && config.isProd) {
console.log(`Master ${process.pid} is running`)
console.log(`Primary ${process.pid} is running`)

const numCPUs = availableParallelism()

const httpServer = createServer()

// setup sticky sessions
setupMaster(httpServer, { loadBalancingMethod: 'least-connection' })

// setup connection between the workers
setupPrimary()

httpServer.listen(config.port, () => {
console.log(`Server running at http://localhost:${config.port}`.blue.bold)
})

for (let i = 0; i < numCPUs; i++) {
// Spawn a new worker process.
// This can only be called from the primary process.
cluster.fork()
}

Expand Down Expand Up @@ -71,7 +75,10 @@ const createApp = async () => {
})

if (config.isProd) {
// use cluster adapter
io.adapter(createClusterAdapter())

// setup connection with primary process
setupWorker(io)
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/scripts/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { hash } from 'argon2'
import 'colors'

const USER_PASSWORD = 'bob@123'
const USER_COUNT = 300

const USER_COUNT = 1000
const GROUP_COUNT_PER_USER = 5
const MEMBER_COUNT_PER_GROUP = 35
const MESSAGE_PER_MEMBER = 5
Expand Down
1 change: 1 addition & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ dist-ssr
*.sln
*.sw?
.env
stats.html
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"postcss": "^8.4.38",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"rollup-plugin-visualizer": "^5.12.0",
"tailwindcss": "^3.4.4",
"typescript": "^5.2.2",
"vite": "^5.2.0"
Expand Down
3 changes: 2 additions & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import react from '@vitejs/plugin-react-swc'
import path from 'path'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
plugins: [react(), visualizer({ gzipSize: true, brotliSize: true })],
server: {
port: 3000,
},
Expand Down

0 comments on commit daadaa3

Please sign in to comment.