You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JSON REST API for an online learning platform built with Node.js, Express, and MariaDB (native driver, no ORM). It follows a layered architecture with controllers, services, repositories, validators, DTOs, and JWT-based role authorization, and includes automated Jest + Supertest tests for routes, services, validators, and middleware.
Quick Start
# 1. Install dependencies
npm install
# 2. Create your .env from the example
cp .env.example .env # then edit values# 3. Import the database schema
mariadb -u root < database/schema.sql
# 4. Start the server
npm run dev # nodemon (hot-reload)
npm start # production
The API listens on http://localhost:<PORT> (default 3000).
Run with Docker
This repository can run locally with two containers:
backend for the Node.js API
db for MariaDB 11.4
The database data is stored in a persistent Docker volume named mariadb_data, so your data survives normal container restarts. On the very first startup, Docker automatically imports database/schema.sql into the MariaDB container.
First-time Docker setup
PowerShell:
Copy-Item .env.docker.example .env.docker
docker compose --env-file .env.docker up --build
Git Bash / WSL:
cp .env.docker.example .env.docker
docker compose --env-file .env.docker up --build
After the containers start, open http://localhost:3000/api/health.
Common Docker commands
# Start in the background
docker compose --env-file .env.docker up --build -d
# Stop the containers
docker compose --env-file .env.docker down
# Show backend logs
docker compose --env-file .env.docker logs -f backend
# Show database logs
docker compose --env-file .env.docker logs -f db
# Rebuild after code changes
docker compose --env-file .env.docker up --build -d
# Remove containers and delete the database volume (full reset)
docker compose --env-file .env.docker down -v
Docker notes
The backend connects to MariaDB through Docker's internal network by using DB_HOST=db.
The database service has a health check, and the backend waits for a successful database connection before starting the API server.
Keep DB_NAME=csis_228_project unless you also update database/schema.sql, because the current schema file creates and uses that database name directly.
The checked-in .env.example is older and does not fully match the running code and schema. The Docker setup follows the actual runtime values from the codebase and local .env, not the stale example file.
# Run tests with the main automation script
npm run test# Run in watch mode during development
npm run test:watch
# Run with coverage report
npm run test:coverage
npm run test (same as npm test) runs Jest with --verbose --runInBand, which provides detailed output and automated sequential execution for stable local runs.
Testing Automation
Test execution is automated through npm scripts in package.json.
npm run test:watch automatically re-runs tests when files change.
npm run test:coverage automatically generates coverage summaries and detailed reports in the coverage/ directory.
Route, service, validator, and middleware suites are all included in the same automated testing workflow.
Notes
Tests are intentionally isolated from the database by mocking repository/database dependencies where needed.
JWT and runtime test environment variables are set in tests/setup/env.js for deterministic execution.
API Endpoints
Legend: 🔓 Public · 🔐 Authenticated · 🛡️ Instructor only
Node.js/Express/MariaDB REST API for an online learning platform with JWT auth, role-based access control, layered architecture, and automated Jest/Supertest tests.