https://github.com/simotae14/monorepo-accounts
Monorepo with Nestjs and Nextjs
https://github.com/simotae14/monorepo-accounts
class-validator jest nestjs nextjs swagger
Last synced: about 2 months ago
JSON representation
Monorepo with Nestjs and Nextjs
- Host: GitHub
- URL: https://github.com/simotae14/monorepo-accounts
- Owner: simotae14
- Created: 2025-05-26T15:45:22.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-28T22:20:05.000Z (about 1 year ago)
- Last Synced: 2025-06-28T20:40:15.455Z (12 months ago)
- Topics: class-validator, jest, nestjs, nextjs, swagger
- Language: TypeScript
- Homepage:
- Size: 1.07 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Scalapay Test - Monorepo
> A monorepo for the Scalapay test where the backend is built in NestJS and the frontend in NextJS
This monorepo contains two applications working together to provide account creation functionality with a clean separation between frontend and backend services.
## ๐ Overview
### Applications
- **API (NestJS)**: Backend service running on `localhost:4000`
- Location: `apps/api/`
- Provides REST API endpoints including `POST /submit` for account creation
- **Web (Next.js)**: Frontend application running on `localhost:3000`
- Location: `apps/web/`
- Contains form interface at `/form` for account creation
- Communicates with the API service
## ๐ Quick Start
### Prerequisites
- Node.js (version 18 or higher recommended)
- npm package manager
### Installation
1. Clone the repository:
```bash
git clone
cd scalapay-test
```
2. Install dependencies for all workspaces:
```bash
npm install
```
This will install dependencies for both the API and Web applications using npm workspaces.
### Running the Applications
#### Development Mode (Both Apps)
Start both API and Web applications simultaneously:
```bash
npm run dev
```
This command runs both services concurrently:
- API server: http://localhost:4000
- Web application: http://localhost:3000
- Form interface: http://localhost:3000/form
#### Individual Applications
Start only the API server:
```bash
npm run dev:api
```
Start only the Web application:
```bash
npm run dev:web
```
### Production Mode
Build both applications:
```bash
npm run build
```
Start both applications in production mode:
```bash
npm run start
```
#### Individual Production Commands
Build and start API only:
```bash
npm run build:api
npm run start:api:prod
```
Build and start Web only:
```bash
npm run build:web
npm run start:web
```
#### API Development Modes
The NestJS API supports different startup modes:
- **Development with watch mode:**
```bash
npm run start:api:dev
```
- **Debug mode:**
```bash
npm run start:api:debug
```
- **Production mode:**
```bash
npm run start:api:prod
```
## ๐งช Testing
### All Tests
Run tests for both applications:
```bash
npm test
```
### API Testing
Run API unit tests:
```bash
npm run test:api
```
Run API tests in watch mode:
```bash
npm run test:api:watch
```
Run API tests with coverage:
```bash
npm run test:api:cov
```
Run API end-to-end tests:
```bash
npm run test:api:e2e
```
### Web Testing
Run Web application tests:
```bash
npm run test:web
```
For more Web testing options (watch mode, coverage, E2E), navigate to the web directory:
```bash
cd apps/web
npm run test:watch
npm run test:coverage
```
To run the e2e tests you need to start the monorepo
```bash
npm run dev
```
and then run the e2e tests from the web folder, unfortunately I add some issues to intercept the POST api so it writes to db at every submission
```bash
cd apps/web
npm run test:e2e:watch
```
## ๐ง Code Quality & Development Tools
### Formatting
Format code in both applications:
```bash
npm run format
```
Check formatting without making changes:
```bash
npm run format:check
```
Format individual applications:
```bash
npm run format:api
npm run format:web
```
### Linting
Lint both applications:
```bash
npm run lint
```
Lint individual applications:
```bash
npm run lint:api
npm run lint:web
```
Check API linting:
```bash
npm run lint:api:check
```
### Type Checking
Run TypeScript type checking for Web application:
```bash
npm run type-check:web
```
## ๐ Storybook (Web App)
The Web application includes Storybook for component development:
```bash
cd apps/web
npm run storybook
```
Storybook will be available at http://localhost:6006
## ๐ Swagger (API)
When you run the API part you have access to the Swagger code available for example at http://localhost:4000/api#/submit/AccountController_create
Also if you want to test the APIs you can use Postman and also use this VSCode extension VSCode Rest Client[https://marketplace.visualstudio.com/items?itemName=humao.rest-client] and use the file apps/api/rest-client.http to launch the APIs
## ๐๏ธ Project Structure
```
scalapay-test/
โโโ apps/
โ โโโ api/ # NestJS Backend Application
โ โ โโโ src/
โ โ โโโ test/
โ โ โโโ package.json
โ โ โโโ ...
โ โโโ web/ # Next.js Frontend Application
โ โโโ src/
โ โโโ public/
โ โโโ __tests__/
โ โโโ .storybook/
โ โโโ package.json
โ โโโ ...
โโโ package.json # Root package.json with workspace config
โโโ README.md # This file
```
## ๐ ๏ธ Technology Stack
### Backend (NestJS API)
- **NestJS** - Progressive Node.js framework
- **TypeScript** - Type safety
- **Jest** - Testing framework
### Frontend (Next.js Web)
- **Next.js 15.3.2** - React framework with Turbopack
- **React 19** - UI library
- **TypeScript** - Type safety
- **Tailwind CSS** - Utility-first CSS framework
- **Zustand** - State management
- **Zod** - Schema validation
- **Storybook** - Component development
### Development Tools
- **ESLint** - Code linting
- **Prettier** - Code formatting
- **Jest** - Testing framework
## ๐ก API Endpoints
The NestJS API provides the following endpoints:
- **POST** `/submit` - Create new account
- Used by the Web form for account creation
- **GET** `/submit` - Get all the accounts
- Used to check the created accounts
- **DELETE** `/submit/:id` - Delete a specific account
- Used to delete the created accounts
## ๐จ Troubleshooting
### Port Conflicts
Default ports used:
- API: `localhost:4000`
- Web: `localhost:3000`
- Storybook: `localhost:6006`
### Workspace Issues
If you encounter workspace-related issues:
```bash
# Clean install
rm -rf node_modules apps/*/node_modules
npm install
```
### Build Issues
Check for type errors and linting issues:
```bash
npm run lint
npm run type-check:web
```
### API Connection Issues
Ensure the API is running before testing form submissions:
```bash
npm run dev:api
# Then in another terminal
npm run dev:web
```
## ๐ Available Scripts
### Root Level Scripts
| Script | Description |
| ---------------- | ------------------------------------------ |
| `npm run dev` | Start both API and Web in development mode |
| `npm run build` | Build both applications for production |
| `npm run start` | Start both applications in production mode |
| `npm test` | Run tests for both applications |
| `npm run lint` | Lint both applications |
| `npm run format` | Format code in both applications |
### Individual App Scripts
| Script | Description |
| ------------------------- | ----------------------------- |
| `npm run dev:api` | Start API in development mode |
| `npm run dev:web` | Start Web application |
| `npm run start:api:dev` | Start API with watch mode |
| `npm run start:api:debug` | Start API in debug mode |
| `npm run start:api:prod` | Start API in production mode |
| `npm run test:api:*` | Various API testing commands |
## ๐ค Development Workflow
1. **Setup**: `npm install` (installs all workspace dependencies)
2. **Development**: `npm run dev` (starts both services)
3. **Testing**: `npm test` (runs all tests)
4. **Code Quality**: `npm run lint && npm run format:check`
5. **Build**: `npm run build` (builds both apps)
6. **Production**: `npm run start` (starts both in production mode)
## ๐ค Author
**Simone Taeggi**
## ๐ License
ISC License