Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
64 changes: 64 additions & 0 deletions App-Description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Day 19 - Application Architecture and Endpoint Summary

### 🔧 Overview

This application demonstrates a full-stack setup using **React + Redux** on the frontend and **Express + MongoDB** on the backend. It is structured to showcase multiple features while maintaining clarity for learning purposes. The frontend handles the UI and state management using Redux, while the backend manages API routes, database operations, and server-side logic.

### 📐 Project Setup

This Project is cloned from [Repo](https://github.com/PiyushB752/express-react-fullstack_Zolvit_Day-19). The dependencies are installed using the command "npm install" or "npm i". This project can start using the command "npm run dev".

### ⚙️ Technology Stack

| Layer | Technology |
|-------------|----------------------------------|
| Frontend | React, Redux, Redux-Saga |
| Backend | Node.js, Express.js |
| Database | MongoDB (via Mongoose) |
| Dev Tools | Babel, dotenv, Webpack, Concurrently |

### 🗂 App Structure

#### 🖥️ Frontend

The frontend of this application is built using **React + Redux**. Key components include:

**UI Components**
1. **Dashboard.jsx** – Main dashboard interface
2. **Login.jsx** and **Signup.jsx** – Authentication screens
3. **Navigation.jsx** – Navigation bar
4. **TaskDetails.jsx** and **TaskList.jsx** – Task-related views

**Redux / State Management**
1. **mutations.js** – Contains Redux action creators
2. **sagas.js** – Handles side effects using Redux-Saga
3. **sagas.mock.js** – Mock data for sagas

#### 🌐 Backend

The backend of this application is built using **Express.js + MongoDB**. Key files include:

1. **server.js** – Main entry point for the Express server
2. **authenticate.js** – Handles user authentication logic
3. **connect-db.js** – Establishes connection to MongoDB
4. **initialize-db.js** – Seeds the database with initial data
5. **communicate-db.js** – Contains functions to query and mutate the database

### 🏞️ Environment Configuration

| Setting | Value |
|----------------|-----------------------------------------|
| MongoDB URI | `mongodb://localhost:27017/organizer` |
| Frontend Port | `8080` |
| Backend Port | `7777` |

### 📡 API Endpoints

| Method | Endpoint | Description |
|--------|------------------|-----------------------------------------|
| POST | `/task/new` | Adds a new task to the database. |
| POST | `/task/update` | Updates an existing task in the database. |
| POST | `/comment/new` | Adds a new comment to the task. |
| POST | `/user/create` | Creating new users |
| POST | `/authenticate` | User authentication |
| GET | `/tasks` | Getting all task data |
50 changes: 50 additions & 0 deletions MongoMemoryValidations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# API Integration Test Validations

This document describes the validations performed by the integration tests using an in-memory MongoDB (`mongodb-memory-server`) for isolated testing.


## ⚙ Environment

- **Database:** In-memory MongoDB (`MongoMemoryServer`)
- **App:** Express API tested using `Mocha` + `chai` + `Supertest`.


## ✅ Validations Tested

### 1️⃣ User Creation

- **Endpoint:** `POST /user/create`
- **Validation Logic:**
- A new user can be created successfully.
- Response contains:
- `userID`
- `state.session.authenticated === 'AUTHENTICATED'`

### 2️⃣ User Authentication

- **Endpoint:** `POST /authenticate`
- **Validation Logic:**
- **Valid credentials:**
- Returns a `token`.
- `state.session.authenticated === 'AUTHENTICATED'`.
- **Invalid password:**
- Returns HTTP `500`.
- Response text is `'Password incorrect'`.

### 3️⃣ Task Creation

- **Endpoint:** `POST /task/new`
- **Validation Logic:**
- A new task can be added with:
- `name` (string)
- `isComplete` (boolean)
- `owner` (user ID string)

### 4️⃣ Task Update

- **Endpoint:** `POST /task/update`
- **Validation Logic:**
- A task can be updated with:
- `id` (task ID)
- New `name`
- Updated `isComplete` status
76 changes: 76 additions & 0 deletions Performance_Report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 📊 k6 Load Testing Report

This report documents the load testing of the `http://localhost:7777` endpoints using [k6](https://k6.io). The goal is to analyze **performance**, **reliability**, and **correctness** under simulated user load.

## 📅 Test Environment & Setup

| Aspect | Details |
|---------------------|-------------------------------------|
| API Endpoint | http://localhost:7777 (multiple APIs) |
| Test Tool | k6 Load Testing Tool |
| Test Duration | 40 seconds |
| Virtual Users | Ramp-up to 100 concurrent users |
| Request Type | HTTP POST (various endpoints) |
| Network Conditions | Localhost (minimal network latency) |

## 🧪 Test Objective

- Simulate up to 100 virtual users (VUs) hitting various API endpoints
- Measure API response time and throughput under load
- Validate API correctness using k6 checks
- Identify any errors, failures, or timeouts

## ✏️ Final Output

```
✓ /user/create status 200 or 500
✓ /authenticate status 200
✓ /authenticate has token
✓ /task/new status 200
✓ /task/update status 200
✓ /comment/new status 200

HTTP
http_req_duration.......................................................: avg=56.55ms min=471.6µs med=36.97ms max=393.13ms p(90)=177.04ms p(95)=259.53ms
{ expected_response:true }............................................: avg=61.83ms min=471.6µs med=37.5ms max=393.13ms p(90)=214.22ms p(95)=262.59ms
http_req_failed.........................................................: 17.56% 7219 out of 41095
http_reqs...............................................................: 41095 1026.737476/s

EXECUTION
iteration_duration......................................................: avg=283.4ms min=12.05ms med=300.09ms max=800.75ms p(90)=453.01ms p(95)=468.45ms
iterations..............................................................: 8219 205.347495/s
vus.....................................................................: 1 min=1 max=100
vus_max................................................................: 100 min=100 max=100

NETWORK
data_received...........................................................: 14 MB 344 kB/s
data_sent...............................................................: 7.3 MB 181 kB/s
```

## 🔍 Detailed Metrics Explanation

| Metric | Explanation | Interpretation |
|---------------------------|----------------------------------------------------------------------|----------------------------------------------------------------------|
| **http_req_duration (avg)** | Average duration of HTTP requests. | Requests were fast: ~56.55 ms on average. |
| **http_req_duration (p90)** | 90% of requests completed faster than this time. | 90% of requests < 177 ms — good latency. |
| **http_req_duration (p95)** | 95% of requests completed faster than this time. | 95% of requests < 259 ms — minor spikes in latency. |
| **http_req_failed** | % of requests that failed (non-2xx or network errors). | 17.56% failed — needs investigation (likely /user/create 500 errors).|
| **http_reqs** | Total HTTP requests sent. | 41,095 requests made during test. |
| **iteration_duration (avg)**| Avg duration of a full VU iteration. | Each test loop took ~283 ms. |
| **iteration_duration (p90)**| 90% of loops finished in < this time. | 453 ms per loop at 90th percentile — smooth loop timing. |
| **iteration_duration (p95)**| 95% of loops finished in < this time. | 468 ms shows slight delays under high load. |
| **vus** | Active virtual users at a time. | Reached target 100 VUs. |
| **vus_max** | Max number of VUs during test. | Successfully scaled to 100 VUs. |
| **data_received** | Total data received from server. | 14 MB, expected for small API responses. |
| **data_sent** | Total data sent to server. | 7.3 MB of POST request bodies. |

## 📈 Interpretation Summary

The load test results indicate:

- **Latency:** Response times were excellent overall, with most requests under 200 ms even under high load.
- **Reliability:** 17.56% of requests failed — likely due to duplicate user creation or auth conflicts. Needs error handling improvements.
- **Throughput:** Achieved over 1,000 requests/sec locally — strong performance.
- **Correctness:** All checks passed — status codes, tokens, empty bodies where expected.
- **User Simulation:** Full 100 VUs were active; concurrency target achieved.
- **Data Volume:** Reasonable amounts of data sent/received, typical for API CRUD operations.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ This version of the application is found at the [Add Sign Up Branch](https://git

### Security
Coming February 2019.

## Walkthrought Video
link - https://drive.google.com/file/d/1nLH_jtvvDCj5r4yV3LSVHrjZI1ZI6Jmh/view?usp=sharing
107 changes: 107 additions & 0 deletions Test_Plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Test Plan

This document outlines the test strategy, tools, and execution flow for the `express-react-fullstack` application.

## 📌 **Test Types & Coverage**

### 1️⃣ **Unit Tests**
- **Scope:** Test isolated utility functions, specifically `assembleUserState` logic.
- **Tooling:** `mocha`, `chai`
- **Location:** `test/BackendTestingFolder/unit.test.js`
- **Focus:**
- User session state assembly.
- Correct retrieval of user tasks, groups, users, and comments.

- **Run Command:**
```bash
npm run test-backend
```

- **Success Criteria:**
- All utility functions produce correct output.
- Data integrity in user state assembly is verified.

### 2️⃣ **Integration Tests**
- **Scope:** Verify API routes and DB interactions.
- **Tooling:** `mocha`, `chai`, `supertest`
- **Location:**
- `test/BackendTestingFolder/integrate.test.js`
- `test/BackendTestingFolder/mongoMemory.test.js`
- **Focus:**
- Create and authenticate users.
- Create, update tasks.
- DB consistency between real MongoDB and in-memory DB.

- **Run Command:**
```bash
npm run test-backend
```

- **Success Criteria:**
- API endpoints return correct HTTP status and response payloads.
- Database reflects expected changes.

### 3️⃣ **Frontend Selenium Tests**
- **Scope:** Browser automation simulating user actions.
- **Tooling:** `selenium-webdriver`, `mocha`, `chai`
- **Location:** `test/FrontendTestingFolder/selenium.test.mjs`
- **Focus:**
- Sign up new user.
- Login user.
- Verify redirection to dashboard.
- Capture screenshots during each step.

- **Run Command:**
```bash
npm run test-frontend
```

- **Success Criteria:**
- Navigation flow succeeds without errors.
- Screenshots captured at key milestones.
- URLs match expected paths.

### 4️⃣ **Load Testing**
- **Scope:** Validate system performance under load.
- **Tooling:** `k6`
- **Location:** `test/PerformanceTestingFolder/load_test.js`
- **Focus:**
- Load test user creation, authentication, task/comment operations.
- Assess response codes and basic response validation.

- **Run Command:**
```bash
k6 run test/PerformanceTestingFolder/load_test.js
```

- **Success Criteria:**
- APIs handle increasing load without failure.
- Response times stay within acceptable limits.

## ⚙ **Test Execution Flow**

```bash
1️⃣ Run backend unit and integration tests - npm run test-backend

2️⃣ Run frontend Selenium E2E tests - npm run test-frontend

3️⃣ Run load tests - k6 run test/PerformanceTestingFolder/load_test.js
```

## 🌍 **Environment Notes**
- **Real DB Integration:** Run `npm run server`
- **Memory DB Integration:** Run `npm run server-memory`
- **Dev mode (for Selenium):** Run `npm run start-dev`

## 📂 **File Locations**
| Test Type | File Path |
|----------------|-----------------------------------------------|
| Unit | `test/BackendTestingFolder/unit.test.js` |
| Integration | `test/BackendTestingFolder/integrate.test.js` |
| Integration (Memory) | `test/BackendTestingFolder/mongoMemory.test.js` |
| Frontend E2E | `test/FrontendTestingFolder/selenium.test.mjs` |
| Load Test | `test/PerformanceTestingFolder/load_test.js` |

## ✅ **Summary**

This test plan ensures the correctness, resilience, and performance of `express-react-fullstack` through comprehensive unit, integration, E2E, and load tests using a modern JS testing stack.
Loading