-
Notifications
You must be signed in to change notification settings - Fork 0
Cloud-native MEAN boilerplate #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
5cfc650
chore: add root config (ESLint, Prettier, Husky, Docker Compose, CI)
cursoragent d68308a
feat: add backend (Express, Mongoose, health, users, auth modules)
cursoragent bfe95da
feat: add Angular frontend (standalone, signals, lazy routes, interce…
cursoragent File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| # Application | ||
| NODE_ENV=development | ||
|
|
||
| # Backend | ||
| BACKEND_PORT=3000 | ||
|
|
||
| # Frontend | ||
| FRONTEND_PORT=80 | ||
|
|
||
| # MongoDB (for local development - override in docker-compose) | ||
| MONGODB_URI=mongodb://localhost:27017/mean_db | ||
| MONGODB_PORT=27017 | ||
|
|
||
| # Security | ||
| CORS_ORIGIN=http://localhost:4200 | ||
| RATE_LIMIT_WINDOW_MS=900000 | ||
| RATE_LIMIT_MAX=100 | ||
|
|
||
| # JWT (optional - for auth module) | ||
| JWT_SECRET=your-super-secret-jwt-key-change-in-production | ||
| JWT_EXPIRES_IN=7d |
This file contains hidden or 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,44 @@ | ||
| { | ||
| "root": true, | ||
| "env": { | ||
| "node": true, | ||
| "es2022": true, | ||
| "browser": true | ||
| }, | ||
| "extends": [ | ||
| "eslint:recommended", | ||
| "plugin:@typescript-eslint/recommended", | ||
| "plugin:@typescript-eslint/strict", | ||
| "plugin:@typescript-eslint/stylistic", | ||
| "prettier" | ||
| ], | ||
| "parser": "@typescript-eslint/parser", | ||
| "parserOptions": { | ||
| "ecmaVersion": 2022, | ||
| "sourceType": "module" | ||
| }, | ||
| "plugins": ["@typescript-eslint"], | ||
| "ignorePatterns": [ | ||
| "node_modules", | ||
| "dist", | ||
| "build", | ||
| "coverage", | ||
| "*.config.js", | ||
| "*.config.cjs", | ||
| ".angular" | ||
| ], | ||
| "overrides": [ | ||
| { | ||
| "files": ["frontend/**/*.ts", "frontend/**/*.html"], | ||
| "parserOptions": { | ||
| "project": "frontend/tsconfig.json" | ||
| } | ||
| }, | ||
| { | ||
| "files": ["backend/**/*.ts"], | ||
| "parserOptions": { | ||
| "project": "backend/tsconfig.json" | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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,70 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, develop, 'cursor/**'] | ||
| pull_request: | ||
| branches: [main, develop, 'cursor/**'] | ||
|
|
||
| jobs: | ||
| backend: | ||
| name: Backend | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: backend | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| - name: Test | ||
| run: npm test | ||
| env: | ||
| NODE_ENV: test | ||
| MONGODB_URI: mongodb://localhost:27017/mean_test | ||
| PORT: 3000 | ||
|
|
||
| - name: Build | ||
| run: npm run build | ||
|
|
||
| frontend: | ||
| name: Frontend | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| working-directory: frontend | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| - name: Test | ||
| run: npm test -- --watch=false --browsers=ChromeHeadless --no-progress | ||
|
|
||
| - name: Build | ||
| run: npm run build | ||
| env: | ||
| NODE_ENV: production |
This file contains hidden or 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,13 @@ | ||
| node_modules | ||
| dist | ||
| build | ||
| coverage | ||
| .angular | ||
| .env | ||
| *.log | ||
| .DS_Store | ||
| *.tsbuildinfo | ||
| out-tsc | ||
| .idea | ||
| .vscode | ||
| *.local |
This file contains hidden or 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 hidden or 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 lint-staged |
This file contains hidden or 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,8 @@ | ||
| node_modules | ||
| dist | ||
| build | ||
| coverage | ||
| .angular | ||
| *.min.js | ||
| *.min.css | ||
| package-lock.json |
This file contains hidden or 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,9 @@ | ||
| { | ||
| "semi": true, | ||
| "singleQuote": true, | ||
| "tabWidth": 2, | ||
| "trailingComma": "es5", | ||
| "printWidth": 100, | ||
| "bracketSpacing": true, | ||
| "arrowParens": "always" | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,141 @@ | ||
| # mean-boilerplate | ||
| # MEAN Stack Boilerplate | ||
|
|
||
| A cloud-native, **12-Factor** MEAN stack (MongoDB, Express.js, Angular, Node.js) boilerplate fully written in **TypeScript**. | ||
|
|
||
| ## Technology Stack | ||
|
|
||
| | Layer | Technology | | ||
| | -------- | --------------------------------- | | ||
| | Database | MongoDB + Mongoose ODM | | ||
| | Backend | Node.js v20+ / Express.js | | ||
| | Frontend | Angular 17+ (Standalone, Signals) | | ||
| | Language | TypeScript (strict mode) | | ||
| | Styling | SCSS | | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| ``` | ||
| / | ||
| ├── .github/workflows/ci.yml # CI/CD pipeline | ||
| ├── .husky/ # Git hooks (lint-staged, commitlint) | ||
| ├── backend/ # Node.js/Express API | ||
| │ ├── src/ | ||
| │ │ ├── config/ # Env validation (Zod) | ||
| │ │ ├── db/ # MongoDB connection | ||
| │ │ ├── middleware/ # Error handling, rate limiting | ||
| │ │ ├── modules/ # Domain modules (health, users, auth) | ||
| │ │ ├── utils/ # Logger, AppError, asyncHandler | ||
| │ │ ├── app.ts | ||
| │ │ └── server.ts | ||
| │ ├── tests/ | ||
| │ ├── Dockerfile | ||
| │ └── package.json | ||
| ├── frontend/ # Angular SPA | ||
| │ ├── src/ | ||
| │ │ ├── app/ | ||
| │ │ │ ├── core/ # Interceptors, services, guards | ||
| │ │ │ ├── features/ # Lazy-loaded feature modules | ||
| │ │ │ └── layout/ | ||
| │ │ ├── environments/ | ||
| │ │ └── styles/ | ||
| │ ├── Dockerfile | ||
| │ └── package.json | ||
| ├── docker-compose.yml | ||
| ├── .env.example | ||
| └── package.json # Root scripts, lint-staged, husky | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Node.js 20+ | ||
| - Docker & Docker Compose (optional, for containerized run) | ||
| - MongoDB (local or Docker) | ||
|
|
||
| ### Local Development | ||
|
|
||
| ```bash | ||
| # 1. Clone and install | ||
| npm run install:all | ||
|
|
||
| # 2. Copy env files | ||
| cp .env.example .env | ||
| cp backend/.env.example backend/.env | ||
|
|
||
| # 3. Start MongoDB (if not running) | ||
| docker run -d -p 27017:27017 mongo:7 | ||
|
|
||
| # 4. Start backend | ||
| npm run backend:dev | ||
|
|
||
| # 5. In another terminal, start frontend | ||
| npm run frontend:dev | ||
| ``` | ||
|
|
||
| - **Backend:** http://localhost:3000 | ||
| - **Frontend:** http://localhost:4200 | ||
|
|
||
| ### Docker Compose | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| docker-compose up -d | ||
| ``` | ||
|
|
||
| - **Backend:** http://localhost:3000 | ||
| - **Frontend:** http://localhost:80 | ||
| - **MongoDB:** localhost:27017 | ||
|
|
||
| ## API Endpoints | ||
|
|
||
| | Method | Path | Description | | ||
| | ------ | ----------------- | -------------------------- | | ||
| | GET | / | API info | | ||
| | GET | /health/liveness | Kubernetes liveness probe | | ||
| | GET | /health/readiness | Kubernetes readiness probe | | ||
| | GET | /api/users | List users (paginated) | | ||
| | GET | /api/users/:id | Get user by ID | | ||
| | POST | /api/auth/login | Login (placeholder) | | ||
| | GET | /api/auth/me | Current user (placeholder) | | ||
|
|
||
| ## Configuration | ||
|
|
||
| Environment variables are validated at startup using **Zod**. See `.env.example` and `backend/.env.example` for the full schema. | ||
|
|
||
| Key variables: | ||
|
|
||
| - `NODE_ENV` – development | test | production | ||
| - `PORT` – Backend port (default 3000) | ||
| - `MONGODB_URI` – MongoDB connection string | ||
| - `CORS_ORIGIN` – Allowed frontend origin(s) | ||
| - `RATE_LIMIT_WINDOW_MS` / `RATE_LIMIT_MAX` – Rate limiting | ||
|
|
||
| ## Code Quality | ||
|
|
||
| - **ESLint** + **Prettier** – shared config at repo root | ||
| - **Husky** – pre-commit (lint-staged) and commit-msg (commitlint) | ||
| - **Conventional Commits** – `feat:`, `fix:`, `chore:`, etc. | ||
|
|
||
| ```bash | ||
| npm run lint | ||
| npm run format | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| ```bash | ||
| npm run backend:test # Jest | ||
| npm run frontend:test # Karma + Jasmine | ||
| ``` | ||
|
|
||
| ## CI/CD | ||
|
|
||
| GitHub Actions (`.github/workflows/ci.yml`) runs on push/PR to `main`, `develop`, and `cursor/**`: | ||
|
|
||
| - Backend: lint, test, build | ||
| - Frontend: lint, test, build | ||
|
|
||
| ## License | ||
|
|
||
| MIT | ||
This file contains hidden or 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,15 @@ | ||
| # Server | ||
| NODE_ENV=development | ||
| PORT=3000 | ||
|
|
||
| # MongoDB | ||
| MONGODB_URI=mongodb://localhost:27017/mean_db | ||
|
|
||
| # Security | ||
| CORS_ORIGIN=http://localhost:4200 | ||
| RATE_LIMIT_WINDOW_MS=900000 | ||
| RATE_LIMIT_MAX=100 | ||
|
|
||
| # JWT (for auth module) | ||
| JWT_SECRET=your-super-secret-jwt-key-change-in-production | ||
| JWT_EXPIRES_IN=7d |
This file contains hidden or 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,9 @@ | ||
| { | ||
| "extends": ["../.eslintrc.json"], | ||
| "parserOptions": { | ||
| "project": "./tsconfig.json" | ||
| }, | ||
| "rules": { | ||
| "@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }] | ||
| } | ||
| } |
This file contains hidden or 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 @@ | ||
| # ----- Build stage ----- | ||
| FROM node:20-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY package*.json ./ | ||
| RUN npm ci --only=production=false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| COPY tsconfig.json ./ | ||
| COPY src ./src | ||
|
|
||
| RUN npm run build | ||
|
|
||
| # ----- Production stage ----- | ||
| FROM node:20-alpine AS production | ||
|
|
||
| RUN addgroup -g 1001 -S nodejs && adduser -S nodejs -u 1001 | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY --from=builder /app/dist ./dist | ||
| COPY --from=builder /app/package*.json ./ | ||
|
|
||
| RUN npm ci --only=production && npm cache clean --force | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| USER nodejs | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| ENV NODE_ENV=production | ||
|
|
||
| CMD ["node", "dist/server.js"] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setup requires two separate
.envfiles (.envat the root andbackend/.env) with several overlapping variables (e.g.,NODE_ENV,MONGODB_URI,JWT_SECRET). This can be confusing for developers and prone to configuration errors. Consider simplifying this to a single.envfile at the project root. The backend application can be configured (e.g., using thedotenvpackage'spathoption) to read from the root-level file during local development.