Get Started
Live demo available at https://nilsriga.ddns.net
This repository contains the completed test project for Trodo, implementing a currency rate conversion chart using an external API. The project includes a NestJS backend, a NextJS SSR frontend, and is designed to run with a CI/CD pipeline, Nginx reverse proxy, and PM2 process management. It is fully documented at https://nilsriga.github.io/currency/ and includes setup instructions, detailed API documentation, and testing protocols.
Project Overview
- Backend: NestJS API with MySQL database and TypeORM, with Sentry for monitoring.
- Frontend: Next.js (SSR) PWA with Redux and 100% Lighthouse score.
- CI/CD: GitHub Actions configured for unit, integration, and e2e testing.
- Production Setup: Nginx reverse proxy, PM2 process management, self-hosted runner.
- Documentation: Full project documentation hosted via Jekyll in
/docs
.
Table of Contents
- Project Structure
- Setup Instructions
- Development Commands
- Testing
- Production Setup
- CI/CD Pipeline
- Documentation
Project Structure
.
├── .github # GitHub Actions for CI/CD
├── admin # Admin tools, including database dump and ecosystem config for PM2
├── back # Backend API (NestJS)
├── docs # Jekyll documentation for full project overview
├── front # Main frontend (Next.js, SSR, PWA)
└── front-vanilla # Alternate frontend in vanilla React (is working)
Setup Instructions
1. Repository and Dependencies
First, download the repository and install the dependencies for each section:
git clone <repository-url>
cd <repository-directory>
2. Backend Setup (NestJS)
- Navigate to the backend directory:
cd back
-
Install MySQL (if not installed). Then create a new MySQL database.
- Configure Environment Variables:
- Duplicate
example.env
as.env
in theback
folder. - Fill out
.env
with your MySQL connection details.
- Duplicate
- Install dependencies:
npm install
- Run Database Migrations:
npm run typeorm migration:run
- Load Initial Data:
- Navigate to the
admin
folder and load thecurrencies.sql
file to populate the database with initial values:mysql -u <username> -p <database_name> < admin/currencies.sql
- Navigate to the
- Start Development Server:
npm run start:dev
Note: For testing environments, you may need to install MySQL and SQLite3 globally to avoid any errors:
npm install -g mysql sqlite3
3. Frontend Setup (Next.js)
- Navigate to the frontend directory:
cd ../front
- Configure Environment Variables:
- Duplicate
example.env
as.env
and customize as needed.
- Duplicate
- Install dependencies:
npm install
- Start Development Server:
npm run dev
Development Commands
Backend Commands
- Run Development Server:
npm run start:dev
- Run Database Migrations:
npm run typeorm migration:run
- Run Backend Tests:
npm run test
Frontend Commands
- Start Frontend Dev Server:
npm run dev
- Build for Production:
npm run build
- Start Production Server:
npm start
Testing
This project uses a comprehensive suite of tests, including unit, integration, and end-to-end (e2e) tests. GitHub Actions handles automated testing in the CI/CD pipeline, and tests can also be run locally.
- Run Backend Tests:
cd back npm run test
- Run Frontend Tests:
cd ../front npm run test
Production Setup
1. PM2 Process Management
Use PM2 to manage Node processes for a zero-downtime setup.
- Navigate to the
admin
folder and use the provided PM2 ecosystem file:cd ../admin pm2 start ecosystem.config.js
- Monitor with PM2:
pm2 monit
2. Nginx Configuration
To serve the application with Nginx, use the provided configuration file in the admin
folder:
-
Copy Nginx Configuration: Place the
nginx.conf
fromadmin
into your Nginx configuration directory (usually/etc/nginx/sites-available
), and create a symbolic link in/etc/nginx/sites-enabled
. -
Reload Nginx:
sudo systemctl reload nginx
CI/CD Pipeline
GitHub Actions are configured to handle automated testing and deployment. A self-hosted runner can be set up to speed up testing:
-
Set Up Self-Hosted Runner: Follow the instructions in
.github/workflows/
to create a self-hosted runner for faster testing during development. -
Use GitHub Actions Commands:
- Refer to the
.pipeline.yml
file inadmin
for CI/CD setup. - The pipeline automates build, testing, and deployment steps as defined in GitHub Actions workflows.
- Refer to the
Documentation
Full documentation is generated with Jekyll and is available in the docs
folder. To view documentation locally:
- Navigate to
docs
:cd ../docs
- Serve Documentation:
bundle exec jekyll serve
Documentation will be available at
http://localhost:4000
.
For live documentation, visit https://nilsriga.github.io/currency/.