Prerequisites
Before you begin, ensure you have the following installed:- Node.js (v16 or higher)
- SQL Server (Microsoft SQL Server or Azure SQL Database)
- Azure AD tenant with an app registration
- Git for cloning the repository
Get Started
Follow these steps to get the backend API running on your local machine.Install dependencies
Install all required npm packages:The project uses the following key dependencies:
- Express (v5.1.0) - Web framework
- mssql (v12.0.0) - SQL Server driver
- Sequelize (v6.37.7) - ORM for database operations
- Socket.io (v4.8.3) - Real-time notifications
- express-oauth2-jwt-bearer (v1.7.1) - Azure AD authentication
Configure environment variables
Create a
.env file in the root directory with the following configuration:Configure Azure AD
Set up your Azure AD app registration:
- Go to the Azure Portal
- Navigate to Azure Active Directory > App registrations
- Create a new registration or use an existing one
- Configure the following:
- Application ID URI: Set this as your
AZURE_AUDIENCE(e.g.,api://your-app-id) - Supported account types: Choose based on your requirements
- API permissions: Configure as needed for your organization
- Application ID URI: Set this as your
- Copy the Tenant ID and Application ID for your
.envfile
The API uses
express-oauth2-jwt-bearer to validate JWT tokens from Azure AD. Tokens must include the correct audience and issuer claims.Make Your First Authenticated Request
Once you have an Azure AD access token, you can make authenticated requests:Replace
YOUR_ACCESS_TOKEN with a valid JWT token from Azure AD. The token must have the correct audience (AZURE_AUDIENCE) configured in your .env file.API Documentation
The API includes interactive Swagger documentation. Once the server is running, visit:Development Mode
For development, use nodemon to automatically restart the server on file changes:Next Steps
Architecture
Learn about the system architecture and design patterns
API Reference
Explore all available endpoints and their documentation
Authentication
Deep dive into Azure AD authentication flow
Real-time Events
Learn how Socket.io powers real-time notifications
Troubleshooting
Database connection fails
Database connection fails
Ensure your SQL Server is accessible and credentials are correct. Check:
- Database server is running
- Firewall rules allow connections
trustServerCertificate: trueis set in the config (src/config/db.config.js:10)
Authentication errors
Authentication errors
If you receive 401 errors:
- Verify your Azure AD configuration
- Ensure the token has the correct
audienceclaim - Check that
AZURE_ISSUER_BASE_URLmatches your tenant - Confirm the user exists in the database with matching
azure_oid
CORS issues
CORS issues
Update CORS configuration in src/app.js:12-17 to allow your frontend origin.