Skip to content

About

Backend API of Codin, a dashboard platform for monitoring IoT and robotic systems. Software Engineering II coursework: tests, CI and linting added to the course's code.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Codin Backend (Software Engineering II, group 5)

Backend API of Codin (Configure, Deploy, Inspect), a platform for building dashboards that monitor IoT-based systems, such as robotic systems, through a graphical interface, including over a remote network. Users sign up, connect data sources, and create, share and clone dashboards.

Context

Group coursework for Software Engineering II at Aristotle University of Thessaloniki, 2022-2023, by a team of three (see Team). The course handed the class a largely complete Codin backend and frontend. The assignment was to run the project the way an agile team would, assessed continuously through the Cyclopt platform on three axes: project management and CI/CD, testing strategy and implementation, and quality analytics (improving static-analysis metrics without changing behaviour). According to the team, the metrics improved over the course; the Cyclopt reports are no longer available, so this repository quotes no values.

This repository holds the course's application plus what the group added.

Provided by the course: the application source in src/ (routes, models, middlewares), from SoftwareEngineering2-Assignment/se2-backend. Four of its files differ from the course version by small changes: the users route, the dashboard model, the mailer, and a formatting change in src/utilities/index.js. The server and the secrets for the deployment job were also provided by the course.

Added by the group:

  • Automated test suite (AVA, with c8 for coverage): 53 tests across the users, sources, dashboards and general routes, run against a real MongoDB with mock data loaded at the start of every test file. See tests/.
  • Continuous integration and deployment (GitHub Actions, .github/workflows/cicd.yaml): on every push, a job starts a MongoDB service container, installs dependencies on Node 14, and runs the tests and ESLint. A second job, for pushes to main, connects to the course server over SSH, pulls, reinstalls and restarts the app with pm2; it runs only when the repository variable DEPLOY_TO_COURSE_SERVER is set to true, and needs the course's server and SSH secrets, so it cannot run elsewhere.
  • Linting and commit hook: ESLint (Airbnb base config) and a Husky pre-commit hook that runs npm run lint.
  • Local database setup: docker-compose.yml starts MongoDB 5.0.14 and mongo-express 0.54.0, and mongo-init/mongo-init.js creates the application database user.

Tech stack

Node.js, Express, MongoDB with Mongoose, JSON Web Tokens and bcryptjs for authentication, yup for request validation, SendGrid for the password-reset email. AVA, c8, got and test-listen for tests. ESLint, Husky and lint-staged for code quality. Docker Compose for the local database.

API overview

Area Endpoints
Users (/users) POST /create, /authenticate, /resetpassword, /changepassword
Sources (/sources) GET /sources, POST /create-source, /change-source, /delete-source, /source, /check-sources
Dashboards (/dashboards) GET /dashboards, /dashboard; POST /create-dashboard, /delete-dashboard, /save-dashboard, /clone-dashboard, /share-dashboard, /check-password-needed, /check-password, /change-password
General (/general) GET /statistics, /test-url, /test-url-request

Running it

cp .env.sample .env        # fill in PORT, SERVER_SECRET, MONGODB_URI, PLATFORM_URI, SERVER_URI, SENDGRID_API_KEY
docker compose up -d       # local MongoDB and mongo-express (credentials in docker-compose.yml are development defaults)
npm ci                     # on Node 14 with npm 6; with a newer npm use: npm install
npm run dev                # development, or: npm start for production

npm ci works only with npm 6: the committed package-lock.json is in the npm 6 format, and newer npm versions reject it. npm install works on newer versions.

Typical local values: PORT=3000, SERVER_URI=http://localhost:3000, PLATFORM_URI=http://localhost:3002 (the frontend), and, for the compose database, MONGODB_URI=mongodb://codin:password@localhost:27017/codin. mongo-express is then at http://localhost:8081 with the image's default login (admin / pass).

Without a SendGrid key the server still starts and prints a warning; the password-reset email needs a valid key, and a failed send is only logged.

Checked: on Node 14.21.3 with npm 6.14.18, npm ci, npm start and npm run dev start the server against the compose database, and a sign-up and a login through /users/create and /users/authenticate succeed.

Running the tests

The tests need a reachable MongoDB and the same .env values (SERVER_SECRET, MONGODB_URI, PLATFORM_URI, SERVER_URI). They wipe and reload the collections they use, so point MONGODB_URI at a throwaway database.

npm test        # AVA with coverage
npm run lint    # ESLint with --fix, so it edits files in place

All 53 tests pass on Node 14.21.3 (npm ci) and on Node 16.20.2 (npm install), with c8 reporting 90.17 % statement coverage. One test (GET /test-url with an existing URL) fetches a page from Wikipedia and needs internet access. On a slow disk AVA's 10 second inactivity limit can be too short; npx ava --timeout=90s avoids that.

Frontend

The React frontend that goes with this backend is a separate repository: se2-frontend-group5. A deployment on Netlify is online at https://se2-frontend-5.netlify.app. The page loads; whether it can still reach a working backend is not guaranteed, because the backend it was built for ran on the course's server.

Licence

The repository carries the course's MIT licence (LICENSE, with robotics-4-all as the copyright holder named in the file).

Team

About

Backend API of Codin, a dashboard platform for monitoring IoT and robotic systems. Software Engineering II coursework: tests, CI and linting added to the course's code.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages