diff --git a/.commitlintrc.json b/.commitlintrc.json new file mode 100644 index 0000000..e2b30fa --- /dev/null +++ b/.commitlintrc.json @@ -0,0 +1,26 @@ +{ + "extends": ["@commitlint/config-conventional"], + "rules": { + "type-enum": [ + "error", + "always", + [ + "feat", + "fix", + "perf", + "revert", + "docs", + "style", + "refactor", + "test", + "ci", + "chore" + ] + ], + "type-case": ["error", "always", "lowercase"], + "type-empty": ["error", "never"], + "subject-empty": ["error", "never"], + "subject-full-stop": ["error", "never", "."], + "subject-case": ["error", "never", ["start-case", "pascal-case"]] + } +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..fefde18 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,166 @@ +name: CI/CD Pipeline + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + semantic-commits: + name: Validate Semantic Commits + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Validate commits + run: | + # For PRs: validate commits from merge-base to HEAD, excluding merges + # For pushes: validate new commits, excluding merges + if [ "${{ github.event_name }}" = "pull_request" ]; then + npx commitlint --from ${{ github.event.pull_request.base.sha }} --to HEAD --exclude "^Merge pull request" + else + npx commitlint --from HEAD~1 --to HEAD --exclude "^Merge" + fi + + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run linting + run: npm run lint + + unit-tests: + name: Unit Tests + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run unit tests with coverage + run: npm run test:cov + + - name: Upload coverage artifacts + uses: actions/upload-artifact@v4 + if: always() + with: + name: coverage-report + path: coverage/ + retention-days: 15 + + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build project + run: npm run build + + - name: Cache build artifacts + uses: actions/cache@v4 + with: + path: dist/ + key: build-${{ github.sha }} + retention-days: 7 + + e2e-tests: + name: E2E Tests + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Restore build artifacts + uses: actions/cache@v4 + with: + path: dist/ + key: build-${{ github.sha }} + fail-on-cache-miss: true + + - name: Run E2E tests + run: npm run test:e2e + + test-results: + name: Test Results Summary + runs-on: ubuntu-latest + needs: [semantic-commits, lint, unit-tests, build, e2e-tests] + if: always() + steps: + - name: Check job statuses + run: | + if [[ "${{ needs.semantic-commits.result }}" == "failure" ]] || \ + [[ "${{ needs.lint.result }}" == "failure" ]] || \ + [[ "${{ needs.unit-tests.result }}" == "failure" ]] || \ + [[ "${{ needs.build.result }}" == "failure" ]] || \ + [[ "${{ needs.e2e-tests.result }}" == "failure" ]]; then + echo "❌ CI/CD Pipeline failed" + exit 1 + fi + echo "✅ CI/CD Pipeline passed" + + - name: Report summary + if: always() + run: | + echo "## CI/CD Pipeline Results" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY + echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY + echo "| Semantic Commits | ${{ needs.semantic-commits.result }} |" >> $GITHUB_STEP_SUMMARY + echo "| Lint | ${{ needs.lint.result }} |" >> $GITHUB_STEP_SUMMARY + echo "| Unit Tests | ${{ needs.unit-tests.result }} |" >> $GITHUB_STEP_SUMMARY + echo "| Build | ${{ needs.build.result }} |" >> $GITHUB_STEP_SUMMARY + echo "| E2E Tests | ${{ needs.e2e-tests.result }} |" >> $GITHUB_STEP_SUMMARY diff --git a/.gitignore b/.gitignore index 4b56acf..7fa9271 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,4 @@ pids # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json +.claude diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100644 index 0000000..3b4299e --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +npx --no -- commitlint --edit "$1" diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..8839974 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,113 @@ +{ + "branches": ["main"], + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { + "type": "feat", + "release": "minor" + }, + { + "type": "fix", + "release": "patch" + }, + { + "type": "perf", + "release": "patch" + }, + { + "type": "revert", + "release": "patch" + }, + { + "type": "docs", + "release": false + }, + { + "type": "style", + "release": false + }, + { + "type": "refactor", + "release": false + }, + { + "type": "test", + "release": false + }, + { + "type": "ci", + "release": false + } + ] + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { + "type": "feat", + "section": "Features", + "hidden": false + }, + { + "type": "fix", + "section": "Bug Fixes", + "hidden": false + }, + { + "type": "perf", + "section": "Performance Improvements", + "hidden": false + }, + { + "type": "revert", + "section": "Reverts", + "hidden": false + }, + { + "type": "docs", + "section": "Documentation", + "hidden": true + }, + { + "type": "style", + "section": "Styles", + "hidden": true + }, + { + "type": "refactor", + "section": "Code Refactoring", + "hidden": true + }, + { + "type": "test", + "section": "Tests", + "hidden": true + }, + { + "type": "ci", + "section": "CI/CD", + "hidden": true + } + ] + } + } + ], + "@semantic-release/changelog", + [ + "@semantic-release/github", + { + "successComment": false, + "failComment": false + } + ], + "@semantic-release/git" + ] +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0031820 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Shi Chen & Gianmarco Murru + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 8f0f65f..ba746f4 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,337 @@ -
- -[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 -[circleci-url]: https://circleci.com/gh/nestjs/nest - -A progressive Node.js framework for building efficient and scalable server-side applications.
- - - -## Description - -[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. - -## Project setup +# Feedback API + +[](./LICENSE) +[](https://nodejs.org/) + +An open-source REST API for collecting, organizing, and analyzing user feedback. Built with **NestJS**, **TypeScript**, and **SQLite3**/**PostgreSQL**. + +--- + +## Features +### Planned Features + +**Phase 1: Core MVP** (current development) +- Feedback CRUD operations (create, read, update, delete) +- Survey management with questions +- Response collection and retrieval +- Input validation and error handling +- Swagger/OpenAPI documentation + +**Phase 2: Analytics** +- Response statistics and aggregation +- Survey analytics endpoints +- Question-level analytics +- Query optimization and indexing + +--- + +## Tech Stack + +| Technology | Version | Purpose | +|-----------|---------|---------| +| **Node.js** | 20.x | Runtime environment | +| **NestJS** | 11.0 | Progressive Node.js framework with excellent structure | +| **TypeScript** | 5.7 | Type-safe JavaScript targeting ES2023 | +| **Jest** | 30.0 | Unit and E2E testing framework | +| **ESLint & Prettier** | Latest | Code quality and automated formatting | +| **GitHub Actions** | - | CI/CD automation and testing | +| **Semantic Release** | - | Automated versioning and changelog generation | + +--- + +## Quick Start + +### Prerequisites +- **Node.js** 20.x or higher +- **npm** or **yarn** package manager +- **git** for version control + +### Installation + +```bash +# Clone the repository +git clone https://github.com/shichenitu/Feedback-API-Project.git +cd Feedback-API-Project + +# Install dependencies +npm install + +# Start the development server +npm run start:dev +``` + +The API will be available at `http://localhost:3000` + +### Verify Installation +```bash +# You should receive a response +curl http://localhost:3000 +# Response: "Hello World!" +``` + +--- + +## API Documentation + +Swagger/OpenAPI documentation is coming soon and will be available at `/api/docs` once implemented. + +The API will follow RESTful conventions with standard HTTP methods and status codes: +- `GET` for retrieval +- `POST` for creation +- `PUT` for updates +- `DELETE` for deletion +- `200/201` for success, `400` for bad requests, `404` for not found, `500` for server errors + +--- + +## Project Structure + +``` +src/ +├── main.ts # Application entry point +├── app.module.ts # Root module +├── app.controller.ts # Root controller +├── app.service.ts # Root service +├── user/ +│ ├── user.entity.ts # User entity definition +│ ├── user.service.ts # User business logic (coming soon) +│ └── user.controller.ts # User endpoints (coming soon) +├── feedback/ +│ ├── feedback.entity.ts # Feedback entity definition +│ ├── feedback.service.ts # Feedback business logic (coming soon) +│ └── feedback.controller.ts # Feedback endpoints (coming soon) +└── common/ + ├── filters/ # Exception handlers + ├── pipes/ # Validation pipes + └── decorators/ # Custom decorators + +test/ +├── app.e2e-spec.ts # E2E test suite +└── jest-e2e.json # E2E test configuration + +.github/workflows/ +├── ci.yml # Continuous integration pipeline +└── release.yml # Automated release workflow +``` + +**Design Principles:** +- **Services** - Contain business logic and database queries +- **Controllers** - Handle HTTP requests and input validation +- **Entities** - Define database models and relationships +- **Error Handling** - Consistent, descriptive error responses +- **Testing** - Both unit and integration test coverage + +--- + +## Development + +### Setting Up Your Environment ```bash -$ npm install +# Install dependencies +npm install + +# Verify setup by running tests +npm test ``` -## Compile and run the project +### Available npm Scripts ```bash -# development -$ npm run start +# Development +npm run start # Start production server +npm run start:dev # Start with hot-reload +npm run start:debug # Start with debugger +npm run start:prod # Run built application + +# Building +npm run build # Compile TypeScript to JavaScript + +# Code Quality +npm run lint # Run ESLint +npm run format # Format with Prettier -# watch mode -$ npm run start:dev +# Testing +npm test # Run unit tests +npm run test:watch # Watch mode for tests +npm run test:cov # Generate coverage report +npm run test:debug # Debug tests +npm run test:e2e # Run end-to-end tests -# production mode -$ npm run start:prod +# Releases +npm run semantic-release # Create a new release (CI/CD only) ``` -## Run tests +### Code Style + +The project uses **ESLint** and **Prettier** for consistent code formatting: ```bash -# unit tests -$ npm run test +# Lint your code +npm run lint + +# Auto-format your code +npm run format +``` + +### Semantic Commits -# e2e tests -$ npm run test:e2e +This project follows [Conventional Commits](https://www.conventionalcommits.org) specification for clear, semantic commit messages: -# test coverage -$ npm run test:cov ``` +feat: add user authentication # New feature (minor version bump) +fix: resolve login timeout issue # Bug fix (patch version bump) +docs: update API documentation # Documentation (no version bump) +refactor: simplify survey logic # Refactoring (no version bump) +test: add tests for feedback service # Tests (no version bump) +``` + +Using semantic commits enables automated version management and changelog generation. + +--- -## Deployment +## Testing -When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the [deployment documentation](https://docs.nestjs.com/deployment) for more information. +The project includes comprehensive test coverage with both unit and integration tests. -If you are looking for a cloud-based platform to deploy your NestJS application, check out [Mau](https://mau.nestjs.com), our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps: +### Running Tests Locally ```bash -$ npm install -g @nestjs/mau -$ mau deploy +# Unit tests +npm test + +# Unit tests with coverage report +npm run test:cov + +# End-to-end tests +npm run test:e2e + +# Watch mode (re-run on file changes) +npm run test:watch ``` -With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure. +### CI/CD Automation + +All tests are automatically run on: +- **Push to main branch** - Triggers full CI pipeline +- **Pull requests to main** - Blocks merge if tests fail + +The GitHub Actions pipeline includes: +1. **Linting** - ESLint validation (~30s) +2. **Unit Tests** - Jest with coverage (~45s) +3. **Build** - TypeScript compilation (~30s) +4. **E2E Tests** - Integration tests (~60s) + +View pipeline status in the **Actions** tab of the GitHub repository. + +--- + +## Roadmap + +### Phase 1: Core MVP (Current) +Establishing the foundation for feedback collection: +- [ ] Survey CRUD endpoints (create, read, update, delete) +- [ ] Question management (add, remove, reorder questions) +- [ ] Response collection and retrieval +- [ ] Comprehensive input validation +- [ ] Error handling with descriptive messages +- [ ] Swagger/OpenAPI documentation +- [ ] Database schema and migrations -## Resources +### Phase 2: Analytics (Q2 2026) +Adding insight capabilities: +- [ ] Response statistics (count, trends) +- [ ] Survey analytics endpoints +- [ ] Question-level analytics +- [ ] Query optimization with proper indexing +- [ ] Performance monitoring -Check out a few resources that may come in handy when working with NestJS: +### Phase 3+: Ideas for Future Enhancements +Advanced features ideas (no commitment yet): +- [ ] Advanced question types (matrix questions, ranking, conditional logic) +- [ ] Survey templates and presets +- [ ] Multi-team/organization support with permission models +- [ ] Data export functionality (CSV, PDF) +- [ ] Real-time results dashboard +- [ ] Webhook notifications for new responses +- [ ] Public/shareable survey links +- [ ] Response filtering and search -- Visit the [NestJS Documentation](https://docs.nestjs.com) to learn more about the framework. -- For questions and support, please visit our [Discord channel](https://discord.gg/G7Qnnhy). -- To dive deeper and get more hands-on experience, check out our official video [courses](https://courses.nestjs.com/). -- Deploy your application to AWS with the help of [NestJS Mau](https://mau.nestjs.com) in just a few clicks. -- Visualize your application graph and interact with the NestJS application in real-time using [NestJS Devtools](https://devtools.nestjs.com). -- Need help with your project (part-time to full-time)? Check out our official [enterprise support](https://enterprise.nestjs.com). -- To stay in the loop and get updates, follow us on [X](https://x.com/nestframework) and [LinkedIn](https://linkedin.com/company/nestjs). -- Looking for a job, or have a job to offer? Check out our official [Jobs board](https://jobs.nestjs.com). +Share your thoughts by adding a new [https://github.com/shichenitu/Feedback-API-Project/issues/new?q=state%3Aopen+label%3Aenhancement](Feature request) -## Support +--- -Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). +## Contributing -## Stay in touch +We welcome contributions from the community! Whether you're fixing bugs, adding features, or improving documentation, your help is appreciated. -- Author - [Kamil Myśliwiec](https://twitter.com/kammysliwiec) -- Website - [https://nestjs.com](https://nestjs.com/) -- Twitter - [@nestframework](https://twitter.com/nestframework) +### Getting Started + +1. **Fork** this repository +2. **Clone** your fork locally +3. **Create** a feature branch: `git checkout -b feat/your-feature-name` +4. **Make** your changes +5. **Test** your changes: `npm test && npm run test:e2e` +6. **Lint** your code: `npm run lint` +7. **Commit** with semantic messages: `git commit -m "feat: describe your feature"` +8. **Push** to your fork: `git push origin feat/your-feature-name` +9. **Open** a pull request to `main` with a clear description + +### Requirements + +Before submitting a pull request, ensure: +- ✅ All tests pass: `npm test && npm run test:e2e` +- ✅ Code is properly formatted: `npm run lint` +- ✅ New features include tests +- ✅ Commits use [semantic commit](https://www.conventionalcommits.org) format +- ✅ Documentation is updated if needed + +### Code Review Process + +Pull requests are reviewed for: +- **Strategy** - Does it align with our roadmap and product vision? +- **Functionality** - Does it work as intended? +- **Testing** - Are new features properly tested? +- **Code Quality** - Does it follow project patterns? +- **Documentation** - Is it clearly documented? +- **Performance** - Are there any performance implications? + +GitHub Actions must show all checks passing before merge is possible. + +### Questions or Issues? + +- **Report bugs** via GitHub Issues +- **Discuss features** in GitHub Discussions +- **Review code** in pull requests + +--- ## License -Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE). +This project is licensed under the **MIT License** - see the [LICENSE](./LICENSE) file for details. + +The MIT License is a permissive open-source license that allows you to: +- ✅ Use this software for commercial purposes +- ✅ Modify the source code +- ✅ Distribute the software +- ✅ Use privately + +With the requirement to: +- ⚠️ Include the license and copyright notice + +--- + +## Authors + +- [**Shi Chen**](https://github.com/shichenitu) - Co-author +- [**Gianmarco Murru**](https://github.com/gianmarcomurru) - Co-author + +--- + +## Connect & Support + +- **GitHub Issues** - Report bugs or request features +- **GitHub Discussions** - Ask questions and discuss ideas +- **License Questions** - See [LICENSE](./LICENSE) file + +Thank you for your interest in the Feedback API! 🚀 diff --git a/package.json b/package.json index 9bbae6b..ec899fa 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { - "name": "my-awesome-api", + "name": "feedback-api", "version": "0.0.1", - "description": "", - "author": "", + "description": "An open-source Feedback API using TypeScript/NestJS.", + "author": "Shi Chen & Gianmarco Murru", "private": true, "license": "UNLICENSED", "scripts": { + "prepare": "husky install", "build": "nest build", "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", "start": "nest start", @@ -49,7 +50,10 @@ "ts-node": "^10.9.2", "tsconfig-paths": "^4.2.0", "typescript": "^5.7.3", - "typescript-eslint": "^8.20.0" + "typescript-eslint": "^8.20.0", + "@commitlint/cli": "^18.0.0", + "@commitlint/config-conventional": "^18.0.0", + "husky": "^8.0.3" }, "jest": { "moduleFileExtensions": [