cd bulak-smart-connect-js
npm install (optional)
npm run dev
cd bsc-js-backend
npm install or npm i -g @nestjs/cli (optional)
npm run start
Test at http://localhost:3000/
#Install TypeORM CLI
npm install -g typeorm
#Generate a migration after making entity changes
typeorm migration:generate -n CreateUserRolesStructure
#Apply migrations
typeorm migration:run
- Download and install MySQL Installer from https://dev.mysql.com/downloads/installer/
- During installation, select:
- MySQL Server
- MySQL Workbench
- MySQL Shell
- Connector/J
- I selected all though
- Configure MySQL Server with these settings:
- Authentication Method: Use Strong Password Encryption
- Root Password: [create a secure password]
- Launch MySQL Workbench
- Create a new database:
CREATE DATABASE bulak_smart_connect;
USE bulak_smart_connect;
-- Create users table
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL,
name VARCHAR(255) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create a test user (password: password123)
INSERT INTO users (email, password, name)
VALUES ('[email protected]', '$2b$10$mExcKUyHurlq1zNDNos9LOXbtUJZuvIKybmHr/BngC6ZamAjz1ohS', 'Test User');
-- Add roles table
CREATE TABLE roles
(
id
int NOT NULL AUTO_INCREMENT,
name
varchar(50) NOT NULL,
description
varchar(255),
PRIMARY KEY (id
),
UNIQUE KEY IDX_roles_name
(name
)
);
-- Insert default roles
INSERT INTO roles
(name, description) VALUES
('super_admin', 'Has all permissions and can manage other admins'),
('admin', 'Can manage staff and citizens'),
('staff', 'Can process applications and manage citizen requests'),
('citizen', 'Regular user of the system');
-- Add user_roles table for role assignment
CREATE TABLE user_roles
(
user_id
int NOT NULL,
role_id
int NOT NULL,
PRIMARY KEY (user_id
, role_id
),
FOREIGN KEY (user_id
) REFERENCES users
(id
) ON DELETE CASCADE,
FOREIGN KEY (role_id
) REFERENCES roles
(id
) ON DELETE CASCADE
);
-- Add a default role column to users table for quick access
ALTER TABLE users
ADD COLUMN default_role_id
int;
ALTER TABLE users
ADD CONSTRAINT fk_users_roles
FOREIGN KEY (default_role_id
) REFERENCES roles
(id
);
-- Update existing users to be citizens by default
UPDATE users
SET default_role_id
= (SELECT id FROM roles WHERE name = 'citizen');
-- Create a test admin (password: admin123)
INSERT INTO users (email, password, name)
VALUES ('[email protected]', '$2b$10$I6mQJSzXN4ReCGTuRzfAvOYVMJLvtmUZOZV1wZ9Tk3tJH2ASXZkhy', 'Admin User');
-- Create test super admin
INSERT INTO users (email, password, name)
VALUES ('[email protected]', '$2b$10$I6mQJSzXN4ReCGTuRzfAvOYVMJLvtmUZOZV1wZ9Tk3tJH2ASXZkhy', 'Super Admin User');
-- Create test staff
INSERT INTO users (email, password, name)
VALUES ('[email protected]', '$2b$10$I6mQJSzXN4ReCGTuRzfAvOYVMJLvtmUZOZV1wZ9Tk3tJH2ASXZkhy', 'Staff User');
-- Assign appropriate roles
INSERT INTO user_roles (user_id, role_id)
SELECT u.id, r.id
FROM users u, roles r
WHERE u.email = '[email protected]' AND r.name = 'admin';
INSERT INTO user_roles (user_id, role_id)
SELECT u.id, r.id
FROM users u, roles r
WHERE u.email = '[email protected]' AND r.name = 'super_admin';
INSERT INTO user_roles (user_id, role_id)
SELECT u.id, r.id
FROM users u, roles r
WHERE u.email = '[email protected]' AND r.name = 'staff';
-- Set default roles
UPDATE users u JOIN roles r ON r.name = 'admin'
SET u.default_role_id = r.id
WHERE u.email = '[email protected]';
UPDATE users u JOIN roles r ON r.name = 'super_admin'
SET u.default_role_id = r.id
WHERE u.email = '[email protected]';
UPDATE users u JOIN roles r ON r.name = 'staff'
SET u.default_role_id = r.id
WHERE u.email = '[email protected]';
Note: You can also import the database from the folder "database"
Export it if you make any changes on the database and/or to ensure we have a backup to match the proper database on the latest iterations
Also ensure there is no personal information on the database before you export it, for our safety. Optionally, you can just export it without the data, only the schema.
Create a .env file in the bsc-js-backend directory with:
DB_HOST=localhost
DB_PORT=3306
DB_USERNAME=root
DB_PASSWORD=your_password
DB_NAME=bulak_smart_connect
JWT_SECRET=your_jwt_secret_key
Generate a secure JWT secret using:
node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
Optionally, you can retrieve the env file from our secure channel and put it in the bsc-js-backend directory
If you prefer using XAMPP instead of MySQL Installer:
- Download and install XAMPP from https://www.apachefriends.org/
- Start the MySQL and Apache services from XAMPP Control Panel
- Open phpMyAdmin at http://localhost/phpmyadmin
- Create database and tables as described in the MySQL Setup section
- Note that XAMPP uses MariaDB instead of MySQL, but this is compatible with the provided instructions
cd bulak-smart-connect-js
npm run dev # Run React and NestJS concurrently
npm run start-frontend # Run React only
npm run start-backend # Run NestJS only
npm run build # Vite build
npm run lint # ESLint
npm run preview # Vite preview
For more backend options:
cd bsc-js-backend
npm run start # Start NestJS normally
npm run start:dev # Start NestJS in development mode
npm install -g firebase-tools (can be skipped)
cd bsc-js-backend
firebase login
firebase init emulators or firebase init (can be skipped)
firebase emulators:start
Test at http://127.0.0.1:4000/
install Java JDK from https://www.java.com/en/download/ and https://download.oracle.com/java/23/latest/jdk-23_windows-x64_bin.exe or https://www.oracle.com/java/technologies/downloads/
serviceAccountKey.json was ignored on git so if needed, just get it on our secure channel and put it on bsc-js-backend\src\config
npm run dev on the frontend folder now runs concurrently, meaning React, NestJs, & Firebase Emulator runs simultaneously
If you want to run it on its default behavior, go to package.json on the folder, C:\Users\YuKARLO15\Desktop\Programming_Codes\Bulak-Smart-Connect-JS\bulak-smart-connect-js and change the dev under the scripts into "dev": "vite",
cd bulak-smart-connect-js
npm run dev: will run React, NestJS (0n Dev Mode), and Firebase Emulator concurrently
npm run start-frontend: will run React only
npm run start-backend: will run NestJS (On Dev Mode) only
npm run start-emulators: will run Firebase Emulators only
npm run build: vite build
npm run lint: eslint
npm run preview: vite preview
To further see other options, just enter "npm run" to see options for React and Concurrently
For more options to run (mostly for Backend):
cd bsc-js-backend
npm run start: to start NestJS normally
firebase emulators:start: to start Firebase emulator
To further see other options, just enter "npm run" to see options for NestJS or "firebase" to see options for Firebase.