Skip to content

tebinraouf/enterprise-api-sample-azure

Repository files navigation

Sample API

A robust NestJS-based REST API for a sample api with Azure deployment capabilities. This repository contains Bicep templates for deploying a complete Azure infrastructure stack.

🚀 Features

  • A Sample REST API placeholder in NestJS
  • OpenAPI/Swagger documentation
  • Azure Container Apps deployment setup in Bicep
  • Azure Container Registry setup in Bicep
  • Azure API Management setup in Bicep
  • Azure Log Analytics workspace
  • Github Action for CICD (support for 3 environments (dev, qa, prod))
  • Docker containerization

🛠️ Tech Stack

  • NestJS v11
  • TypeScript
  • Jest for testing
  • Docker
  • Azure Container Apps
  • Azure Container Registry
  • Azure API Management Service
    • Management Service
    • Product
    • API
  • Azure Log Analytics workspace
  • Bicep for Infrastructure as Code

📋 Prerequisites

  • Node.js >= v22.14.0
  • npm >= 10.9.2
  • Docker (for containerization)
  • Azure CLI (for deployment)

🏗️ Installation

# Install dependencies
npm install

🚀 Running the app

# Development mode
npm run start

🧪 Testing

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Test coverage
npm run test:cov

Prerequisites for Azure Deployment

  1. Azure subscription
  2. Azure Container Registry
  3. Azure credentials configured in GitHub Secrets

🏗 Azure Infrastructure Components

  • Resource Group: Logical container for Azure resources
  • Azure Container Registry (ACR): Private container registry for Docker images
  • Azure Container Apps: Serverless container hosting platform
  • API Management Service: API gateway for managing and securing APIs

📁 Project Structure

.
├── Dockerfile
├── README.md
├── bicep
│   ├── main.bicep
│   ├── modules
│   │   ├── apim.bicep
│   │   ├── containerEnvironment.bicep
│   │   ├── containerRegistry.bicep
│   │   └── resourceGroup.bicep
│   └── parameters
│       ├── dev.parameters.json
│       ├── prod.parameters.json
│       └── qa.parameters.json
├── eslint.config.mjs
├── nest-cli.json
├── package-lock.json
├── package.json
├── src
│   ├── app.module.ts
│   ├── auth
│   │   ├── auth.controller.ts
│   │   ├── auth.module.ts
│   │   └── auth.service.ts
│   ├── main.ts
│   └── user
│       └── user.module.ts
├── test
│   ├── app.e2e-spec.ts
│   └── jest-e2e.json
├── tsconfig.build.json
└── tsconfig.json

8 directories, 24 files

CICD GitHub

This project has one workflow to deploy the app and the infrastructure. The workflow requires AZURE_CREDENTIALS as a secret in Github. To create a secret, follow below:

az ad sp create-for-rbac --name "myApp" --role Contributor --scopes /subscriptions/{subscription-id}

For the AZURE_CREDENTIALS, store a JSON per below. Please note that you will need to map the fields per below:

{
  "clientSecret":  "your client secret to be here",
  "subscriptionId":  "your subscription id to be here",
  "tenantId":  "your tenant id to be here",
  "clientId":  "your client id to be here"
}

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📄 License

This project is licensed under the MIT License.

About

An Enterprise API Sample Based on Azure, NestJs, Bicep

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published