cotrav_monorepo_package_creation_service_build_guide
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| cotrav_monorepo_package_creation_service_build_guide [2026/01/19 11:48] – created pradnya | cotrav_monorepo_package_creation_service_build_guide [2026/01/27 08:38] (current) – [Cotrav Monorepo – Package Creation & Service Build Guide] pradnya | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Cotrav Monorepo – Package Creation & Service Build Guide ====== | ====== Cotrav Monorepo – Package Creation & Service Build Guide ====== | ||
| - | This document describes **how to create shared packages and build/run services** in the Cotrav monorepo. | + | This document describes **how to create shared packages and build/run services** in the Cotrav monorepo. |
| + | |||
| + | Git - [[https:// | ||
| + | |||
| ===== Repository Structure ===== | ===== Repository Structure ===== | ||
| < | < | ||
| - | |||
| cotrav-services/ | cotrav-services/ | ||
| - | |||
| │ | │ | ||
| - | |||
| ├─ package.json (root – workspaces enabled) | ├─ package.json (root – workspaces enabled) | ||
| - | |||
| │ | │ | ||
| - | |||
| ├─ packages/ (shared libraries) | ├─ packages/ (shared libraries) | ||
| - | |||
| │ ├─ logger/ | │ ├─ logger/ | ||
| - | |||
| │ ├─ errors/ | │ ├─ errors/ | ||
| - | |||
| │ ├─ middlewares/ | │ ├─ middlewares/ | ||
| - | |||
| │ └─ tsconfig.json (base TS config for packages) | │ └─ tsconfig.json (base TS config for packages) | ||
| - | |||
| │ | │ | ||
| - | |||
| ├─ workspace/ (runtime services) | ├─ workspace/ (runtime services) | ||
| - | |||
| │ ├─ auth-service/ | │ ├─ auth-service/ | ||
| - | |||
| │ ├─ booking-service/ | │ ├─ booking-service/ | ||
| - | |||
| │ └─ payment-service/ | │ └─ payment-service/ | ||
| - | |||
| │ | │ | ||
| - | |||
| └─ node_modules/ | └─ node_modules/ | ||
| + | </ | ||
| + | |||
| + | ===== Prerequisites ===== | ||
| + | |||
| + | ^Tool^Version| | ||
| + | |||
| + | |Node.js|> | ||
| + | |||
| + | |npm|>= 9.x| | ||
| + | |||
| + | |TypeScript|> | ||
| + | |||
| + | |VS Code|Recommended| | ||
| + | |||
| + | ===== Root Workspace Setup ===== | ||
| + | |||
| + | Root '' | ||
| + | |||
| + | The root enables **npm workspaces** so shared packages can be consumed without publishing. | ||
| + | |||
| + | cmd | ||
| + | < | ||
| + | |||
| + | npm install | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Install Dependencies ===== | ||
| + | |||
| + | ==== Logger ==== | ||
| + | |||
| + | < | ||
| + | npm install pino | ||
| + | |||
| + | npm install -D @types/node | ||
| + | |||
| + | </ | ||
| + | |||
| + | Error | ||
| + | |||
| + | < | ||
| + | npm install -D @types/node | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Middleware ==== | ||
| + | |||
| + | < | ||
| + | npm install express | ||
| + | |||
| + | npm install -D @types/ | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Build Package ==== | ||
| + | |||
| + | package/ | ||
| + | |||
| + | cmd | ||
| + | |||
| + | < | ||
| + | npm run build --workspace=packages/ | ||
| + | |||
| + | </ | ||
| + | |||
| + | package/ | ||
| + | |||
| + | cmd | ||
| + | |||
| + | < | ||
| + | npm run build --workspace=packages/ | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Creating Error & Middleware Packages ==== | ||
| + | |||
| + | Repeat the same steps for: | ||
| + | |||
| + | * '' | ||
| + | * '' | ||
| + | Only **business logic differs**, structure remains identical. | ||
| + | |||
| + | ====== Creating a Service ====== | ||
| + | |||
| + | Example: '' | ||
| + | |||
| + | Folder Creation | ||
| + | |||
| + | < | ||
| + | cd workspace | ||
| + | mkdir auth-service | ||
| + | cd auth-service | ||
| + | npm init -y | ||
| + | |||
| + | </ | ||
| + | |||
| + | Service '' | ||
| + | |||
| + | < | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }, | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Install Dependencies ==== | ||
| + | |||
| + | < | ||
| + | npm install | ||
| + | |||
| + | npm install -D typescript | ||
| + | |||
| + | npm install express dotenv jsonwebtoken bcryptjs swagger-ui-express swagger-jsdoc pino | ||
| + | |||
| + | </ | ||
| + | |||
| + | Type deps | ||
| + | |||
| + | < | ||
| + | npm install -D | ||
| + | @types/ | ||
| + | @types/node | ||
| + | @types/ | ||
| + | @types/ | ||
| + | @types/ | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Build Services & Packages ==== | ||
| + | |||
| + | Execute below command on root folder " | ||
| + | |||
| + | < | ||
| + | npm run build | ||
| + | |||
| + | npm run typecheck | ||
| + | |||
| + | </ | ||
| + | |||
| + | ==== Run auth service in dev ==== | ||
| + | |||
| + | < | ||
| + | npm run dev:auth | ||
| + | |||
| + | </ | ||
| + | ==== Clean all builds ==== | ||
| + | |||
| + | < | ||
| + | </ | ||
| + | |||
| + | ==== Sanity check (must work) ==== | ||
| + | < | ||
| </ | </ | ||
cotrav_monorepo_package_creation_service_build_guide.1768823324.txt.gz · Last modified: by pradnya
