Skip to content
Merged
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
Binary file added docs/images/alert-rules-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/graphs-from-metrics.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/monitoring-architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/prometheus-connection-grafana.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
207 changes: 207 additions & 0 deletions docs/monitoring-documentation.md

Large diffs are not rendered by default.

107 changes: 107 additions & 0 deletions docs/simulation-documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Simulation Script Documentation

## Overview

This script simulates realistic user interactions with an API-based chat application for the purpose of testing and generating traffic. It performs the following:

- User registration and login
- Chat creation
- Retrieval and update of chat data
- Sending and retrieving messages
- Cleanup by deleting the chat

This script is ideal for load testing, development environment traffic simulation, and basic integration checks.

---

## File Location

```
simulation/index.js
```

---

## Requirements

- [Node.js](https://nodejs.org/) installed
- [pnpm](https://pnpm.io/) as the package manager
- `.env` file with the following environment variables:

```

API_BASE_URL=https://api.brainbytes.mcube.uk
TEST_EMAIL=test@email.com
TEST_PASSWORD=yourpassword

```

---

## How to Run

1. **Navigate to the `simulation` folder**:

```bash
cd simulation
```

2. **Install dependencies (if you haven’t already):**

```bash
pnpm install
```

3. **Run the simulation script:**

```bash
pnpm run dev
```

---

## Script Breakdown

### 1. `.env` Usage

The script reads these values from your `.env` file:

- `API_BASE_URL`: Base URL of the backend API
- `TEST_EMAIL` & `TEST_PASSWORD`: Credentials for simulated user

### 2. User Flow

The simulation follows this sequence:

1. **Register** the user (silently fails if already exists)
2. **Login** and retrieve an `accessToken`
3. **Create a chat**
4. Perform the following actions using the `accessToken`:
- Fetch `/me`
- Get all chats
- Get specific chat by ID
- Update chat name
- Send a message
- Retrieve messages
- Delete the chat

---

## Output

You will see console logs like:

```
Create chat response: { chat: { id: "abc123", ... } }
Simulated run finished.
```

---

## Troubleshooting

- Ensure `.env` is correctly configured in the `simulation` directory.
- Make sure the API server is running and accessible at `API_BASE_URL`.
- If you see `Login failed: 401`, check the credentials in `.env`.

---
5 changes: 3 additions & 2 deletions docs/system-design-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,9 @@ In the unlikely event that a deployed version introduces critical issues, a robu


### Monitoring and Observability
The team is currently planning to implement **Grafana and Prometheus** for comprehensive monitoring.
For immediate network monitoring, the **Traefik Dashboard** is used to observe networking activity and service status.
The team is currently using **Grafana and Prometheus** for comprehensive monitoring.

For more information, check this [documentation](./monitoring-documentation.md) out


---
Expand Down
3 changes: 3 additions & 0 deletions simulation/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
API_BASE_URL=
TEST_EMAIL=
TEST_PASSWORD=
6 changes: 6 additions & 0 deletions simulation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Simulation Script Documentation

This script simulates realistic user interactions with an API-based chat application for the purpose of testing and generating traffic.

> ⚠️ **Looking for the full documentation?**
> 👉 [View the complete guide here »](../docs/simulation-documentation.md)
114 changes: 114 additions & 0 deletions simulation/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import "dotenv/config";

const BASE_URL = process.env.API_BASE_URL;

const userCreds = {
email: process.env.TEST_EMAIL,
password: process.env.TEST_PASSWORD,
firstName: "Mark",
lastName: "Ngo",
};

const dummyChat1 = { prompt: "Can you teach me about biology?" };
const dummyChat2 = { prompt: "How does cells work?" };

async function registerUser() {
try {
await fetch(`${BASE_URL}/register`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(userCreds),
});
} catch (_) {
// Ignore if already registered
}
}

async function login() {
const res = await fetch(`${BASE_URL}/login`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(userCreds),
});

if (!res.ok) {
const text = await res.text();
throw new Error(`Login failed: ${res.status} - ${text}`);
}

const data = await res.json();
if (!data.accessToken) {
throw new Error("Login response did not contain accessToken");
}

return data.accessToken;
}

async function simulate() {
await registerUser();
const token = await login();

const headers = {
"Content-Type": "application/json",
cookie: `accessToken=${token}`,
};

// Create chat first
const createRes = await fetch(`${BASE_URL}/chats`, {
method: "POST",
headers,
body: JSON.stringify(dummyChat1),
});

if (!createRes.ok) {
const errorText = await createRes.text();
throw new Error(
`Failed to create chat: ${createRes.status} - ${errorText}`
);
}

const data = await createRes.json();
console.log("Create chat response:", data);

const { chat } = data;
if (!chat || !chat.id) {
throw new Error("Chat creation failed. No chat object returned.");
}

// Proceed only after chat is confirmed
// 1. Get /me
await fetch(`${BASE_URL}/me`, { headers });

// 2. Get all chats
await fetch(`${BASE_URL}/chats`, { headers });

// 3. Get chat by ID
await fetch(`${BASE_URL}/chats/${chat.id}`, { headers });

// 4. Update chat name
await fetch(`${BASE_URL}/chats/${chat.id}`, {
method: "PATCH",
headers,
body: JSON.stringify({ name: "Updated from traffic sim" }),
});

// 5. Send message
await fetch(`${BASE_URL}/chats/${chat.id}/messages`, {
method: "POST",
headers,
body: JSON.stringify(dummyChat2),
});

// 6. Get messages
await fetch(`${BASE_URL}/chats/${chat.id}/messages`, { headers });

// 7. Delete chat
await fetch(`${BASE_URL}/chats/${chat.id}`, {
method: "DELETE",
headers,
});

console.log(`Simulated run finished.`);
}

simulate();
18 changes: 18 additions & 0 deletions simulation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "simulation",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"sim": "node index.js"
},
"type": "module",
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@10.10.0",
"dependencies": {
"dotenv": "^16.5.0"
}
}
23 changes: 23 additions & 0 deletions simulation/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.