Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3b4ed6e
feat(problem1): complete summation solutions and integrate endpoint
Feb 11, 2026
1f37f73
fix: update problem1 to problem4 as requested
Feb 11, 2026
5b8c1d9
Updated Package Json With necessary dependency like better-sqlite3 fo…
Feb 12, 2026
43b4e19
commiting database file
Feb 12, 2026
5e3eeae
commiting database file
Feb 12, 2026
e2c3af3
feat(problem5): complete user CRUD implementation
Feb 12, 2026
e75adf1
Updated Readme.md for problem 5 and to instruct how to start server
Feb 12, 2026
062fc52
Test case written to make sure create, Read and Update work fine
Feb 12, 2026
adf3d0c
added condition to add score in existing table Users
Feb 12, 2026
d797306
- Installed and Used Websocket for live Update
Feb 12, 2026
0415139
Problem6: partial implementation of live leaderboard
Feb 12, 2026
c9d2982
Updated Readme.md for problem6
Feb 12, 2026
2cbee9b
Refactored document to have some gaps between content
Feb 12, 2026
66f87c4
Fix: queried only top 10 in desc to update leaderboard instead of all…
Feb 12, 2026
34ad5b6
Update flow of execution diagram in the readme.md
Feb 12, 2026
f9b0acb
Updated format of Visual Diagram
Feb 12, 2026
178e76d
problem6: Implemented security feature - JWT Token authorization for …
Feb 12, 2026
1904042
created command for generating ,env and jwt secret key placeholder
Feb 12, 2026
2800017
- added helmet to prevent ClickJack, XSS and browser based attactk. i…
Feb 12, 2026
9e35e22
problem4: security feature - add rate limiting
Feb 12, 2026
20ccb06
commited gitignore
Feb 12, 2026
77e2f2e
update README with instructions for using submit quiz Problem6 endpoi…
Feb 13, 2026
ed686f7
feat(problem6): implement audit logging mechanism
Feb 13, 2026
edf8af8
feat(problem6): add input sanitization with Joi
Feb 13, 2026
556ac88
Completed Assessment
Feb 13, 2026
d20cf3a
updated diagram format
Feb 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Node.js dependencies
node_modules/

# Logs
*.log

# Build output
dist/

# OS / editor files
.DS_Store
Thumbs.db
.vscode/

# Optional: lock file (depends on team policy)
package-lock.jsons
.env
41 changes: 41 additions & 0 deletions Client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// client.js
import WebSocket from 'ws';

function connect() {
const socket = new WebSocket('ws://localhost:3000'); // adjust port if needed

socket.on('open', () => {
console.log('Connected to Problem 6 WebSocket');
});

socket.on('message', (data) => {
try {
const msg = JSON.parse(data);

if (msg.type === 'leaderboardUpdate') {
console.log('Leaderboard updated:');
msg.leaderboard.forEach(user => {
console.log(`${user.name}: ${user.score}`);
});
} else {
console.log('Received:', msg);
}
} catch (err) {
console.error('Failed to parse message:', data);
}
});

socket.on('close', () => {
console.log('Disconnected from WebSocket server, retrying in 5s...');
setTimeout(connect, 5000); // retry after 5 seconds
});

socket.on('error', (err) => {
console.error('WebSocket error:', err.message);
// Close and retry
socket.close();
});
}

// Initial connect attempt
connect();
45 changes: 45 additions & 0 deletions Index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import express from 'express';
import { WebSocketServer } from 'ws';
import { initWebSocket } from './WebSocket.js';

import { sum_to_n_a, sum_to_n_b, sum_to_n_c } from './src/problem4/summation_solution.js';
import CrudUser from '../code-challenge/src/problem5/CrudUser.js';
import Architecture from './src/problem6/Architecture.js';

import dotenv from 'dotenv';
import helmet from 'helmet';

dotenv.config(); // loads .env file into process.env

const app = express();
const PORT = process.env.PORT || 3000;

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(helmet()); //to avoid clickjacking, XSS and browser based attacks

app.get('/problem4', (req, res) => {
try {
const results = {
forLoop: sum_to_n_a(5),
reducer: sum_to_n_b(5),
recursion: sum_to_n_c(5)
};
res.json(results);
} catch (e) {
res.status(500).json({ error: e.message });
}
});

app.use('/problem5/users', CrudUser);
app.use('/problem6', Architecture);

const server = app.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});

const wss = new WebSocketServer({ server });

initWebSocket(wss);

export { app };
Binary file added ProgramDatabase.db
Binary file not shown.
Binary file added ProgramDatabase.db-shm
Binary file not shown.
Binary file added ProgramDatabase.db-wal
Binary file not shown.
21 changes: 21 additions & 0 deletions WebSocket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
let wss;

export function initWebSocket(server) {
wss = server;

// Handle new connections
wss.on('connection', ws => {
console.log('Client connected to Problem 6');
ws.send(JSON.stringify({ message: 'Connected to Problem 6 live updates' }));
});
}

export function broadcastProblem6(data) {
if (!wss) return;

wss.clients.forEach(client => {
if (client.readyState === 1) {
client.send(JSON.stringify(data));
}
});
}
Binary file added image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading