https://github.com/htmujahid/full-stack-nestjs
https://github.com/htmujahid/full-stack-nestjs
Last synced: 20 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/htmujahid/full-stack-nestjs
- Owner: htmujahid
- Created: 2026-03-15T08:52:13.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-03-30T05:07:22.000Z (3 months ago)
- Last Synced: 2026-03-30T07:42:06.623Z (3 months ago)
- Language: TypeScript
- Size: 884 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# crude
Full-stack monorepo: **NestJS** backend + **React + Vite** frontend, served from a **single port**.
## Single-port architecture
Backend and frontend run on the **same port** (default `3000`) in both development and production. No separate dev servers, no proxy config, no CORS headaches.
- **API routes** (`/api/*`) → NestJS handles them
- **Everything else** → Vite (dev) or static client build (prod)
Because the browser talks to one origin, CORS is a non-issue: same-origin requests require no special headers or configuration.
## Stack
- **Backend**: NestJS 11, Express 5, TypeScript
- **Frontend**: React 19, Vite 7, TypeScript
- **Package manager**: pnpm
## Project layout
```
├── server/ # NestJS backend (API, Vite middleware)
├── client/ # React frontend
├── index.html # Root HTML (loads /client/main.tsx)
└── vite.config.ts # Vite config (builds to dist/client)
```
## Scripts
| Command | Description |
|----------------|----------------------------------------|
| `pnpm start:dev` | Dev mode: Nest + Vite HMR on port 3000 |
| `pnpm build` | Builds server + client |
| `pnpm start:prod`| Runs prod server (static client + API) |
| `pnpm lint` | Lint client & server |
## How it works
**Development**
- NestJS starts with watch mode.
- `ViteMiddleware` mounts Vite in middleware mode. First non-API request initializes the dev server lazily.
- `/api/*` → NestJS controllers; all other GET requests → Vite (HMR, transforms).
**Production**
- `pnpm build` emits NestJS to `dist/server` and Vite to `dist/client`.
- `ViteMiddleware` serves static files from `dist/client` with SPA fallback to `index.html`.
- `/api/*` still hits NestJS; static assets and SPA routes from Express.
Single process, single port, no CORS.