Loading repository data…
Loading repository data…
maryokafor28 / repository
A production-ready RESTful API built with Node.js, Express, TypeScript, and MongoDB featuring JWT authentication, product & user management, comprehensive testing (Unit, Integration & E2E), and CI/CD with GitHub Actions.
A comprehensive Node.js (Express + TypeScript) backend API with robust testing strategy, featuring authentication, user management, and product management modules.
Live API: https://codepilot-backend.onrender.com
API Documentation: View Postman Collection
Runtime & Framework:
Database:
Authentication:
Testing:
DevOps:
codepilot-backend/
├── src/
│ ├── modules/
│ │ ├── auth/
│ │ │ ├── controller.ts # Auth request handlers
│ │ │ ├── service.ts # Auth business logic
│ │ │ └── routes.ts # Auth endpoints
│ │ ├── users/
│ │ │ ├── model.ts # User schema & model
│ │ │ ├── controller.ts # User request handlers
│ │ │ ├── service.ts # User business logic
│ │ │ └── routes.ts # User endpoints
│ │ └── products/
│ │ ├── model.ts # Product schema & model
│ │ ├── controller.ts # Product request handlers
│ │ ├── service.ts # Product business logic
│ │ └── routes.ts # Product endpoints
│ ├── middleware/
│ │ ├── auth.ts # JWT authentication
│ │ └── errorHandler.ts # Global error handling
│ ├── routes/
│ │ ├── index.ts # JWT authentication
│ ├── config/
│ │ └── db.ts # MongoDB connection
│ ├── utils/
│ │ └── token.ts # JWT utilities
│ ├── app.ts # Express app setup
│ └── server.ts # Server entry point
├── __tests__/
│ ├── unit/
│ │ ├── auth/
│ │ │ └── service.test.ts # Auth service unit tests
│ │ ├── users/
│ │ │ └── service.test.ts # User service unit tests
│ │ └── products/
│ │ └── service.test.ts # Product service unit tests
│ ├── integration/
│ │ ├── auth.test.ts # Auth API integration tests
│ │ ├── users.test.ts # User API integration tests
│ │ └── products.test.ts # Product API integration tests
│ └── e2e/
│ └── setup/
│ └── dbSetup.ts
│ └── helper.ts.ts
├── .github/
│ └── workflows/
│ └── test.yml # CI/CD pipeline
├── coverage/ # Generated coverage reports (gitignored)
├── dist/ # Compiled JavaScript (gitignored)
├── .env # Environment variables (gitignored)
├── .gitignore
├── jest.config.js # Jest configuration
├── tsconfig.json # TypeScript configuration
├── package.json
└── README.md
Clone the repository
git clone https://github.com/maryokafor28/codepilot-backend.git
cd codepilot-backend
Install dependencies
npm install
Set up environment variables
Create a .env file in the root directory:
PORT=5000
NODE_ENV=development
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/codepilot?retryWrites=true&w=majority (or use the local mongodb)
JWT_SECRET=your_super_secret_jwt_key_here
JWT_EXPIRES_IN=7d
Run the development server
npm run dev
Server will start at http://localhost:5000
npm run dev # Start development server with hot reload
npm run build # Compile TypeScript to JavaScript
npm start # Run production server (requires build first)
npm test # Run all tests
npm test -- --watch # Run tests in watch mode
npm test -- --coverage # Generate coverage report
My testing strategy follows the Testing Pyramid approach, ensuring both broad coverage and high confidence in code reliability. We implement three layers of testing that work together to catch bugs at different levels of the application.
| Test Type | Command Run | Coverage (Lines %) | Number of Tests | Share of Total |
|---|---|---|---|---|
| Unit Tests | npx jest --coverage tests/unit | 27.22% | 23 | 60% |
| Integration Tests | npx jest --coverage src/tests/integration | 79.2% | 14 | 30% |
| End-to-End (E2E) Tests | npx jest --coverage src/tests/e2e | 80.69% | 32 | 10% |
▲
| E2E Tests — 80.69% coverage
| (10% of total tests, full workflow)
|
| Integration Tests — 79.2% coverage
| (30% of total tests, cross-module behavior)
|
| Unit Tests — 27.22% coverage
| (60% of total tests, isolated logic)
▼
Purpose: Test individual functions and business logic in complete isolation.
What we test:
Tools: Jest with mocked dependencies
Coverage focus:
Why this gives confidence:
Purpose: Test how multiple components work together, including API routes, controllers, services, and database interactions.
What we test:
Tools: Jest + Supertest + Real test database
Example flows tested:
Coverage focus:
Why this gives confidence:
Purpose: Test complete user workflows from start to finish, simulating real-world usage scenarios.
What we test:
Tools: Jest + Supertest + Test database
Example workflows tested:
Complete User Journey:
Product Management Flow:
Authentication Flow:
Coverage focus:
Why this gives confidence:
Our test suite maintains high coverage across all modules:
| Metric | Target | Current |
|---|---|---|
| Statements | ≥ 80% | 85.45% |
| Branches | ≥ 75% | 66.03% |
| Functions | ≥ 85% | 88.46% |
| Lines | ≥ 80% | 86.45% |
Overall: 9 test suites, 69 tests — all passing
Generate coverage report:
npm test -- --coverage
View detailed HTML report: coverage/lcov-report/index.html
All tests run automatically on every push and pull request via GitHub Actions:
Workflow includes:
View CI status: Check the badge at the top of this README or visit the Actions tab.
The multi-layered testing approach ensures:
Individual functions work correctly (Unit tests) ✅ Components integrate properly (Integration tests) ✅ Complete features function as expected (E2E tests) ✅ Production deployments are safe (CI/CD validation)
For detailed request/response examples, see the Postman Collection.
Live URL: https://codepilot-backend.onrender.com
Deployment Process:
main branch triggers automatic deploymentHosted on MongoDB Atlas:
Ensure all tests pass before submitting:
npm test
Mary Amadi