A complete Node.js microservices architecture demonstrating best practices for scalable backend development with User Management and Course Management services.
┌─────────────────────────────────────┐
│ CLIENTS │
│ (Web, Mobile, Desktop Apps) │
└─────────────────┬───────────────────┘
│
HTTP Requests
│
┌─────────────────▼───────────────────┐
│ API GATEWAY │
│ Port 3000 │
│ • Authentication & Authorization │
│ • Request Routing & Load Balance │
│ • Rate Limiting & Security │
│ • Request/Response Transformation │
└───────────┬─────────────────────────┘
│
┌─────────────┼─────────────┐
│ │
┌─────────▼─────────┐ ┌─────────▼─────────┐
│ USER SERVICE │ │ COURSE SERVICE │
│ Port 3001 │ │ Port 3002 │
│ │ │ │
│ • User Registration │ │ • Course CRUD │
│ • Authentication │ │ • Enrollments │
│ • Profile Mgmt │ │ • Progress Track │
│ • JWT Tokens │ │ • Instructor Panel │
│ • User Search │ │ • Analytics │
└─────────┬─────────┘ └─────────┬─────────┘
│ │
┌─────────▼─────────┐ ┌─────────▼─────────┐
│ USER DB │ │ COURSE DB │
│ MongoDB:27017 │ │ MongoDB:27018 │
│ │ │ │
│ • Users │ │ • Courses │
│ • Profiles │ │ • Lessons │
│ • Auth Tokens │ │ • Enrollments │
└───────────────────┘ └───────────────────┘
# Setup all services
cd microservices
./setup.sh # Mac/Linux
setup.bat # Windows
# Start all services
npm run dev:allcd microservices
docker-compose up --buildServices will run on:
- API Gateway: http://localhost:3000
- User Service: http://localhost:3001
- Course Service: http://localhost:3002
Before running the project, ensure you have the following installed:
- Node.js (v14+ recommended)
- npm (comes with Node.js)
- MongoDB (Ensure it's running locally or use a remote database)
Follow these steps to set up the project on your local machine:
-
Clone the repository:
git clone [https://github.com/JEWOOLAFAVOUR/Backend-Template.git](https://github.com/JEWOOLAFAVOUR/Backend-Template.git) cd backend-template -
Install dependencies:
npm install npm install nodemon -g
-
Environment Variables:
Create a
.envfile in the root directory and add the following:JWT_SECRET=your_random_secret_key PASS_SEC=your_random_pass_key MONGO_URI=your_mongodb_connection_string
-
Running the application:
nodemon app
To contribute code:
- Fork the Repository: Create a personal copy of the repository.
- Create a New Branch: Use a descriptive name for your branch (e.g.,
feature/add-authentication). - Make Changes: Implement your changes in the new branch.
- Test Your Changes: Ensure your changes don't break existing functionality.
- Commit and Push: Commit your changes with clear messages and push to your fork.
- Open a Pull Request: Submit a pull request to the main repository's
mainbranch.
- Code Quality: Write clean, readable, and maintainable code.
- Documentation: Update documentation for any changes that affect usage or functionality.
- Testing: Add tests for new features or bug fixes.