This repository hosts the backend for a custom contact form application, designed for robustness and scalability. The application supports both microservices and monolithic architectures, addressing various deployment preferences. Each architectural style is maintained in separate branches: containers
(merged with main
) for microservices using Docker and Kubernetes, and heroku-single-service
for a simplified monolithic architecture suitable for deployment on Heroku.
- containers: Implements a microservices architecture with services containerized using Docker and orchestrated with Kubernetes. This setup is ideal for scalable and distributed environments.
- heroku-single-service: Features a monolithic architecture, streamlined for easy deployment on Heroku. This branch is well-suited for smaller-scale applications or for those who prefer simplicity in deployment and management.
- ApiGateway: Serves as the main entry point for all incoming requests and routes them to the appropriate services. It orchestrates interactions between other services to fulfill requests.
- ApiValidationService: Checks the validity of email addresses to ensure they are correctly formatted and actually exist.
- MongoDBDataLoggingService: Responsible for logging form submission data to MongoDB, providing a record of user interactions and requests.
- EmailNotificationService: Sends emails to the form owner and the user, confirming receipt of the submission and providing any necessary follow-up information.
- Docker and Kubernetes (for the
containers
branch) - Heroku CLI (for the
heroku-single-service
branch) - Node.js (for local development and testing)
- Git (for version control management)
Clone the repository and navigate to the desired branch:
git clone https://github.com/M-YasirGhaffar/custom-form-backend-azure-microservices-deploy
cd custom-form-backend-azure-microservices-deploy
git checkout <branch-name> # Choose 'containers' for microservices or 'heroku-single-service' for monolithic backend.
Install dependencies:
npm install
Run the application:
npm start
Ensure you have set the necessary environment variables as outlined in the .env.example
file.
-
Build Docker Images: Build Docker images using Azure Container Registry (ACR).
az acr build --registry your-registry-name --image service-name:latest .
-
Deploy on Kubernetes: Deploy using Azure Kubernetes Service (AKS).
kubectl apply -f deployments/kubernetes/
Set the necessary environment variables following the .env.example
file.
-
Create Heroku App:
heroku create
-
Deploy Application:
git push heroku master
- Heroku Live Link: Heroku Deployment
- Kubernetes Live Link: AKS Deployment
The backend provides several endpoints to manage form submissions, email validations, data logging, and notifications. Here’s how you can utilize these endpoints:
- Endpoint:
/submit
- Method:
POST
- Description: Handles user data submissions, including validation, logging, and notifications.
- Request and Response Examples:
// Request { "email": "user@example.com", //Email is compulsory "name": "John Doe", "message": "Your service is great!" } // Success Response { "status": "success", "message": "Form submitted successfully" } // Error Response { "status": "error", "message": "Invalid email provided" }
Frontend developers can interact with these endpoints using JavaScript's fetch
API or libraries like axios
to integrate these functionalities into their web applications.