Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ef922b8
Harden backend/services/chat_service.py
CoreyLeath-code Jul 18, 2026
25445f3
Harden backend/routes/chat_routes.py
CoreyLeath-code Jul 18, 2026
ae62bf5
Harden backend/api.py
CoreyLeath-code Jul 18, 2026
cb3bb34
Harden backend/config.py
CoreyLeath-code Jul 18, 2026
aaab234
Harden app/core/security.py
CoreyLeath-code Jul 18, 2026
74c635a
Harden requirements.txt
CoreyLeath-code Jul 18, 2026
7d12fbe
Harden .github/workflows/trojanchat-hygiene.yml
CoreyLeath-code Jul 18, 2026
5b28865
Harden .github/workflows/benchmarks.yml
CoreyLeath-code Jul 18, 2026
4c09efe
Harden .github/workflows/security-supply-chain.yml
CoreyLeath-code Jul 18, 2026
89265c7
Add .github/workflows/codeql.yml
CoreyLeath-code Jul 18, 2026
12072d3
Add tests/test_backend_hardening.py
CoreyLeath-code Jul 18, 2026
10b40e5
Add tests/test_benchmark.py
CoreyLeath-code Jul 18, 2026
50af1a9
Add tests/test_security.py
CoreyLeath-code Jul 18, 2026
b5579c6
Add benchmarks/run_benchmark.py
CoreyLeath-code Jul 18, 2026
00d8e19
Add benchmarks/latest.json
CoreyLeath-code Jul 18, 2026
ecdf5e7
Add benchmarks/benchmark_report.md
CoreyLeath-code Jul 18, 2026
e4dcad6
Add docs/AUDIT.md
CoreyLeath-code Jul 18, 2026
23899ba
Add docs/PRODUCTION_CHECKLIST.md
CoreyLeath-code Jul 18, 2026
1ea5286
Harden README.md
CoreyLeath-code Jul 18, 2026
47b02bb
Harden CHANGELOG.MD
CoreyLeath-code Jul 18, 2026
8b11e98
Expand README research metrics and benchmark dashboard
CoreyLeath-code Jul 18, 2026
71e6974
Document CodeQL default setup in README.md
CoreyLeath-code Jul 18, 2026
f74b3f5
Document CodeQL default setup in docs/AUDIT.md
CoreyLeath-code Jul 18, 2026
b5edd66
Document CodeQL default setup in CHANGELOG.MD
CoreyLeath-code Jul 18, 2026
1c277e8
Remove CodeQL workflow conflicting with default setup
CoreyLeath-code Jul 18, 2026
385a8d9
Fix frontend security gate in frontend/package.json
CoreyLeath-code Jul 18, 2026
9f77366
Fix frontend security gate in frontend/package-lock.json
CoreyLeath-code Jul 18, 2026
39e78cb
Fix frontend security gate in .github/workflows/trojanchat-hygiene.yml
CoreyLeath-code Jul 18, 2026
7b909b7
Fix frontend security gate in CHANGELOG.MD
CoreyLeath-code Jul 18, 2026
d05a95b
Fix frontend security gate in docs/AUDIT.md
CoreyLeath-code Jul 18, 2026
3739c16
Resolve Trivy findings in .github/workflows/security-supply-chain.yml
CoreyLeath-code Jul 18, 2026
da0a2b9
Resolve Trivy findings in Dockerfile
CoreyLeath-code Jul 18, 2026
79fb5da
Resolve Trivy findings in CHANGELOG.MD
CoreyLeath-code Jul 18, 2026
fdd7a40
Remove vulnerable build tooling from runtime image
CoreyLeath-code Jul 18, 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
30 changes: 18 additions & 12 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ jobs:
with:
python-version: '3.11'

- name: Install Performance Harness Dependencies
run: |
if [ -f "requirements.txt" ]; then pip install -r requirements.txt; fi
pip install pytest pytest-benchmark pytest-asyncio websockets cryptography fastapi
- name: Install benchmark dependencies
run: pip install -r requirements-dev.txt

- name: Execute Profiling Suite & Track Latency Metrics
env:
PYTHONPATH: .
run: |
echo "Executing high-concurrency message broadcast and cryptographic routine benchmarks..."
# Runs benchmarks if present, otherwise outputs structured system performance logging
if [ -d "tests/benchmarks" ]; then
pytest tests/benchmarks/ --benchmark-json=output.json
else
echo "Executing isolated performance profile for local encryption times and pub/sub message dispatch speeds..."
echo "Performance metrics captured successfully. Broadcast pipelines remain sub-millisecond."
fi
python -m benchmarks.run_benchmark --output benchmarks/latest.json
python -m pytest tests/test_benchmark.py -q
python - <<'PY'
import json
result = json.load(open("benchmarks/latest.json", encoding="utf-8"))
regression = result["comparison"]["throughput_change_percent"]
if regression < -15:
raise SystemExit(f"Throughput regression {regression}% exceeds 15% budget")
PY
- name: Upload benchmark evidence
uses: actions/upload-artifact@v4
with:
name: benchmark-report
path: |
benchmarks/latest.json
benchmarks/benchmark_report.md
5 changes: 3 additions & 2 deletions .github/workflows/security-supply-chain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ jobs:
format: sarif
output: trivy-results.sarif
severity: HIGH,CRITICAL
limit-severities-for-sarif: true
ignore-unfixed: true
exit-code: "0"
exit-code: "1"
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v4
with:
Expand Down Expand Up @@ -88,4 +89,4 @@ jobs:
format: table
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: "0"
exit-code: "1"
53 changes: 43 additions & 10 deletions .github/workflows/trojanchat-hygiene.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,19 @@ jobs:
python-version: "3.11"
cache: pip
- name: Install quality tooling
run: python -m pip install --upgrade pip ruff black
run: python -m pip install --upgrade pip ruff black bandit
- name: Validate Python syntax
run: python -m compileall -q app backend tests
- name: Run blocking Ruff correctness checks
run: ruff check app backend tests/test_api.py tests/test_chat_service.py tests/test_inference_cache.py --select E9,F63,F7,F82
- name: Run blocking Ruff and Bandit checks
run: |
ruff check backend/api.py backend/routes backend/services app/core/security.py benchmarks tests/test_api.py tests/test_backend_hardening.py tests/test_benchmark.py tests/test_security.py
bandit -q backend/api.py backend/config.py backend/routes/*.py backend/services/*.py app/core/inference_cache.py app/core/security.py app/services/chat_service.py -f json -o bandit-report.json
Comment on lines +32 to +35

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Separate Ruff and Bandit into distinct steps.

Because GitHub Actions runs shell scripts with set -e by default, if ruff check finds issues and returns a non-zero exit code, the bandit command will not execute. Splitting these into two steps ensures both tools run and report their findings regardless of the other's status.

🛠️ Proposed fix
-      - name: Run blocking Ruff and Bandit checks
-        run: |
-          ruff check backend/api.py backend/routes backend/services app/core/security.py benchmarks tests/test_api.py tests/test_backend_hardening.py tests/test_benchmark.py tests/test_security.py
-          bandit -q backend/api.py backend/config.py backend/routes/*.py backend/services/*.py app/core/inference_cache.py app/core/security.py app/services/chat_service.py -f json -o bandit-report.json
+      - name: Run blocking Ruff checks
+        run: ruff check backend/api.py backend/routes backend/services app/core/security.py benchmarks tests/test_api.py tests/test_backend_hardening.py tests/test_benchmark.py tests/test_security.py
+      - name: Run blocking Bandit checks
+        if: success() || failure()
+        run: bandit -q backend/api.py backend/config.py backend/routes/*.py backend/services/*.py app/core/inference_cache.py app/core/security.py app/services/chat_service.py -f json -o bandit-report.json
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run blocking Ruff and Bandit checks
run: |
ruff check backend/api.py backend/routes backend/services app/core/security.py benchmarks tests/test_api.py tests/test_backend_hardening.py tests/test_benchmark.py tests/test_security.py
bandit -q backend/api.py backend/config.py backend/routes/*.py backend/services/*.py app/core/inference_cache.py app/core/security.py app/services/chat_service.py -f json -o bandit-report.json
- name: Run blocking Ruff checks
run: ruff check backend/api.py backend/routes backend/services app/core/security.py benchmarks tests/test_api.py tests/test_backend_hardening.py tests/test_benchmark.py tests/test_security.py
- name: Run blocking Bandit checks
if: success() || failure()
run: bandit -q backend/api.py backend/config.py backend/routes/*.py backend/services/*.py app/core/inference_cache.py app/core/security.py app/services/chat_service.py -f json -o bandit-report.json
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/trojanchat-hygiene.yml around lines 32 - 35, Split the
combined “Run blocking Ruff and Bandit checks” workflow step into separate Ruff
and Bandit steps, preserving each command and its arguments. Ensure both checks
execute independently so a non-zero Ruff result does not prevent the Bandit
command from running.

- name: Upload static-analysis report
if: always()
uses: actions/upload-artifact@v4
with:
name: static-analysis-report
path: bandit-report.json
- name: Publish formatting advisory
run: |
black --check app backend tests/test_api.py tests/test_chat_service.py tests/test_inference_cache.py \
Expand Down Expand Up @@ -63,7 +71,16 @@ jobs:
tests/test_api.py \
tests/test_chat_service.py \
tests/test_inference_cache.py \
--cov=app \
tests/test_backend_hardening.py \
tests/test_benchmark.py \
tests/test_security.py \
--cov=backend.api \
--cov=backend.routes.chat_routes \
--cov=backend.routes.ws_routes \
--cov=backend.services.chat_service \
--cov=app.core.inference_cache \
--cov=app.services.chat_service \
--cov-fail-under=90 \
--cov-report=term-missing \
--cov-report=xml \
--junitxml=pytest-results.xml \
Expand All @@ -90,20 +107,36 @@ jobs:
cache: pip
- name: Install audit tooling
run: pip install pip-audit
- name: Generate dependency audit report
- name: Enforce dependency audit
run: |
set +e
pip-audit -r requirements.txt --progress-spinner off --format json --output pip-audit.json
status=$?
echo "pip-audit completed with status ${status}; findings are retained as an artifact for triage."
exit 0
- name: Upload dependency audit
uses: actions/upload-artifact@v4
Comment on lines +110 to 114

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Ensure the dependency audit report is uploaded on failure.

If pip-audit detects vulnerabilities, it returns a non-zero exit code which fails the step. As a result, the subsequent Upload dependency audit step will be skipped, and the JSON report won't be available for review.

🛠️ Proposed fix
       - name: Upload dependency audit
+        if: success() || failure()
         uses: actions/upload-artifact@v4
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Enforce dependency audit
run: |
set +e
pip-audit -r requirements.txt --progress-spinner off --format json --output pip-audit.json
status=$?
echo "pip-audit completed with status ${status}; findings are retained as an artifact for triage."
exit 0
- name: Upload dependency audit
uses: actions/upload-artifact@v4
- name: Enforce dependency audit
run: |
pip-audit -r requirements.txt --progress-spinner off --format json --output pip-audit.json
- name: Upload dependency audit
if: success() || failure()
uses: actions/upload-artifact@v4
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/trojanchat-hygiene.yml around lines 110 - 114, The Upload
dependency audit step is skipped when Enforce dependency audit fails, preventing
access to the generated report. Update the Upload dependency audit step to run
regardless of the preceding pip-audit result while preserving its existing
artifact configuration.

with:
name: pip-audit-report
path: pip-audit.json
if-no-files-found: warn

frontend-build:
name: "Continuous Integration / Frontend Build"
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install locked dependencies
run: npm ci --ignore-scripts
- name: Enforce high-severity dependency audit
run: npm audit --audit-level=high
- name: Build production frontend
run: npm run build

container-smoke-test:
name: "Deployment / Container Build & Smoke Test"
needs: test-matrix
Expand All @@ -126,7 +159,7 @@ jobs:

release-readiness:
name: "Release Engineering / Artifact Readiness"
needs: [test-matrix, dependency-audit, container-smoke-test]
needs: [test-matrix, dependency-audit, frontend-build, container-smoke-test]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
23 changes: 20 additions & 3 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
# Changelog
All notable changes to TrojanChat will be documented in this file.

## [Unreleased]
### Added
- Reproducible before/after latency, throughput, and peak-memory benchmark with raw JSON evidence.
- Unit and integration tests for bounded storage, negative API cases, and WebSocket lifecycle.
- CodeQL default-setup documentation, blocking static/security scans, audit, and production checklist.

### Changed
- Canonical critical-path coverage is enforced at 90%.
- Message retention is bounded and thread-safe; API inputs and history queries are constrained.

### Performance
- Reference run reduced peak Python allocations by 80.06% with a 6.8% throughput tradeoff.

### Security
- Sanitized internal errors and changed dependency/Trivy findings from advisory to blocking.
- Upgraded Next.js from 14.2.15 to 15.5.20 to remove current HIGH-severity advisories; added a blocking frontend audit and production build.
- Removed pip/setuptools/wheel build tooling from the runtime image and constrained SARIF output to the declared HIGH/CRITICAL policy.

## [0.2.0] - 2026-04-02
### Changed
- **Python runtime**: Docker base image upgraded from `python:3.10-slim` to `python:3.12-slim`
- **CI/CD**: GitHub Actions updated `actions/checkout@v3→v4`, `actions/setup-python@v4→v5`, Python `3.11→3.12`
- **CI/CD**: GitHub Actions updated — `actions/checkout@v3→v4`, `actions/setup-python@v4→v5`, Python `3.11→3.12`
- **CI/CD**: Fixed `backend/requirements.txt` reference (created missing file) and corrected test runner path
- **requirements.txt**: Pinned minimum versions for all Python dependencies; added `pydantic-settings>=2.5.0`, `fastapi>=0.115.0`, `uvicorn>=0.30.0`, `httpx>=0.27.0`, `pytest-asyncio>=0.24.0`
- **Pydantic v2**: Migrated `BaseSettings` import in `app/core/app/core/config.py` from `pydantic` to `pydantic_settings` package
- **Deprecation fixes**: Replaced `datetime.utcnow()` (deprecated in Python 3.12) with `datetime.now(timezone.utc)` in `mcp_adapter.py`, `app/core/security.py`, and `backend/services/chat_service.py`
- **Node.js (server/)**: Upgraded dependencies `express@4.18→4.21`, `socket.io@4.7→4.8`, `mongoose@7→8`, `dotenv@16.0→16.4`, `jest@29.5→29.7`, `supertest@6→7`, `nodemon@2→3`
- **Node.js (server/)**: Upgraded dependencies — `express@4.18→4.21`, `socket.io@4.7→4.8`, `mongoose@7→8`, `dotenv@16.0→16.4`, `jest@29.5→29.7`, `supertest@6→7`, `nodemon@2→3`
Comment on lines +25 to +30

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix character encoding corruption (mojibake).

Several Markdown files contain text corrupted by a character encoding mismatch (e.g., UTF-8 bytes interpreted as Windows-1252), resulting in artifacts like —, →, 🚀, and “.

  • CHANGELOG.MD#L23-L28: restore proper em-dashes and right-arrows (, ).
  • README.md#L52-L52: fix the em-dash in microbenchmark—not.
  • README.md#L72-L72: fix the rocket emoji (🚀).
  • README.md#L101-L114: fix the Unicode box-drawing characters for the directory tree.
  • docs/AUDIT.md#L21-L21: fix the smart quotes (, ).
📍 Affects 3 files
  • CHANGELOG.MD#L23-L28 (this comment)
  • README.md#L52-L52
  • README.md#L72-L72
  • README.md#L101-L114
  • docs/AUDIT.md#L21-L21
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CHANGELOG.MD` around lines 23 - 28, Restore the corrupted UTF-8 characters
across the documented Markdown sites: replace mojibake em-dashes and
right-arrows in CHANGELOG.MD lines 23-28, the em-dash in README.md line 52, the
rocket emoji in README.md line 72, and the directory-tree box-drawing characters
in README.md lines 101-114; replace the corrupted quotes in docs/AUDIT.md line
21 with proper smart quotes. Preserve all surrounding text and formatting.


### Breaking Changes
- **Pydantic v2**: `BaseSettings` is no longer exported from `pydantic`; it requires the `pydantic-settings` package. Run `pip install pydantic-settings` or use the updated `requirements.txt`.
Expand All @@ -31,4 +49,3 @@ All notable changes to TrojanChat will be documented in this file.
### Security
- Added JWT expiration
- Added request rate limiting

10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ WORKDIR /build
COPY requirements.txt .
RUN python -m venv /opt/venv \
&& /opt/venv/bin/pip install --upgrade pip \
&& /opt/venv/bin/pip install -r requirements.txt
&& /opt/venv/bin/pip install -r requirements.txt \
&& /opt/venv/bin/pip uninstall --yes setuptools wheel \
&& /opt/venv/bin/pip uninstall --yes pip

FROM python:3.11-slim AS runtime

Expand All @@ -16,7 +18,11 @@ ENV PATH=/opt/venv/bin:$PATH \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONPATH=/app

RUN useradd --create-home --uid 10001 appuser
# The base image ships build tooling that is unnecessary at runtime. Removing it
# also prevents scanners from treating setuptools' vendored build dependencies
# as remotely exploitable application packages.
RUN python -m pip uninstall --yes setuptools wheel \
&& useradd --create-home --uid 10001 appuser
WORKDIR /app

COPY --from=builder /opt/venv /opt/venv
Expand Down
83 changes: 68 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# TrojanChat
[![CI](https://github.com/CoreyLeath-code/TrojanChat/actions/workflows/trojanchat-hygiene.yml/badge.svg)](https://github.com/CoreyLeath-code/TrojanChat/actions/workflows/trojanchat-hygiene.yml)
[![Benchmarks](https://github.com/CoreyLeath-code/TrojanChat/actions/workflows/benchmarks.yml/badge.svg)](https://github.com/CoreyLeath-code/TrojanChat/actions/workflows/benchmarks.yml)
[![Security](https://github.com/CoreyLeath-code/TrojanChat/actions/workflows/security-supply-chain.yml/badge.svg)](https://github.com/CoreyLeath-code/TrojanChat/actions/workflows/security-supply-chain.yml)
[![CodeQL](https://img.shields.io/badge/CodeQL-default%20setup-enabled-2F80ED?logo=github)](https://github.com/CoreyLeath-code/TrojanChat/security/code-scanning)
[![Release](https://img.shields.io/github/v/release/CoreyLeath-code/TrojanChat?display_name=tag)](https://github.com/CoreyLeath-code/TrojanChat/releases)
[![Coverage](https://img.shields.io/badge/critical--path%20coverage-92.57%25-success)](#engineering-evidence)
[![Throughput](https://img.shields.io/badge/throughput-40%2C326.50%20msg%2Fs-blue)](#research-benchmark)
[![Peak memory](https://img.shields.io/badge/peak%20memory-4.228%20MiB-blueviolet)](#research-benchmark)
[![Memory improvement](https://img.shields.io/badge/memory%20reduction-80.06%25-success)](#research-benchmark)
[![Benchmark date](https://img.shields.io/badge/benchmark-2026--07--18-informational)](benchmarks/benchmark_report.md)
![Python](https://img.shields.io/badge/Python-3.11%20%7C%203.12-3776AB?logo=python&logoColor=white)
![FastAPI](https://img.shields.io/badge/FastAPI-Backend-009688?logo=fastapi&logoColor=white)
![Streamlit](https://img.shields.io/badge/Streamlit-Frontend-FF4B4B?logo=streamlit&logoColor=white)
Expand Down Expand Up @@ -30,6 +40,49 @@

TrojanChat is a production-hardened, multi-client chat architecture optimized for high-concurrency environments. Moving away from standard blocking network sockets, this platform leverages asynchronous event loops to maintain thousands of concurrent connections efficiently while maintaining structural memory efficiency.

## Engineering evidence

| Evidence | Current result | Enforcement |
|---|---:|---|
| Unit + integration tests | 30 passing locally | Python 3.11/3.12 CI matrix |
| Critical-path coverage | 92.57% | CI fails below 90% |
| Median / P99 write latency | 1,239.880 / 1,303.501 ms per 50k-message run | Reproducible benchmark artifact |
| Throughput | 40,326.50 messages/s | Regression budget: no worse than -15% |
| Peak Python memory | 4.228 MiB | 80.06% below legacy baseline |
| Static analysis | Ruff + Bandit | Blocking; JSON report retained |
| Security | CodeQL, Gitleaks, pip-audit, Trivy | Blocking on secrets and actionable vulnerabilities |
| Supply chain | CycloneDX SBOM + Dependabot | Artifact per run; weekly updates |

The reference benchmark uses Windows 11, Python 3.12.13, 50,000 messages, seven iterations,
and a 10,000-message retention bound. Results describe this microbenchmark—not end-to-end network
latency or a production SLO. See the [benchmark methodology](benchmarks/benchmark_report.md),
[audit](docs/AUDIT.md), [architecture](ARCHITECTURE.md), [deployment guide](DEPLOYMENT.MD), and
[production checklist](docs/PRODUCTION_CHECKLIST.md).

## Research benchmark

**Question.** Can bounded, synchronized retention stop unbounded memory growth without exceeding a
15% write-throughput regression budget?

| Metric | Legacy list | Bounded, synchronized store | Relative change |
|---|---:|---:|---:|
| Mean latency / 50k writes | 1,141.831 ms | 1,237.607 ms | +8.4% |
| Median latency / 50k writes | 1,155.519 ms | 1,239.880 ms | +7.3% |
| P95 / P99 latency | 1,221.577 ms | 1,303.501 ms | +6.7% |
| Minimum / maximum latency | 1,063.323 / 1,221.577 ms | 1,180.249 / 1,303.501 ms | observed range |
| Throughput | 43,270.60 msg/s | 40,326.50 msg/s | **−6.8%** |
| Peak Python allocations | 21.205 MiB | 4.228 MiB | **−80.06%** |

**Method.** Seven independent iterations insert 50,000 structurally identical messages. Both
variants generate UUID4 identifiers and UTC timestamps; only storage and synchronization differ.
Latency uses `time.perf_counter`, memory uses `tracemalloc`, and throughput is derived from median
elapsed time. The raw, versioned result is [`benchmarks/latest.json`](benchmarks/latest.json).

**Interpretation.** The optimized store remains inside the pre-declared 15% throughput budget while
substantially reducing peak Python allocations. The experiment does not measure network transport,
JSON serialization, Redis, database persistence, multi-process contention, CPU utilization, or RSS.
CI reruns the benchmark on Ubuntu/Python 3.11 and uploads the raw result for per-commit comparison.

---

Architectural Overview
Expand All @@ -45,7 +98,7 @@ The platform splits operations across an event-driven system architecture to eli

---

## 🚀 Getting Started
## 🚀 Getting Started

### Prerequisites
* Python 3.11 or higher
Expand Down Expand Up @@ -74,20 +127,20 @@ The platform splits operations across an event-driven system architecture to eli
python client.py "Corey"
```

├── chat_core/
├── __init__.py
├── config.py # <-- Application security settings & validation rules
├── crypto_broker.py # <-- Challenge generation and key distribution logic
└── connection_manager.py # <-- Tier 5: High-concurrency socket tracking state loop
├── deployment/
├── gateway.conf # <-- Tier 2: Envoy or Nginx reverse-proxy ingress rules
├── docker-compose.yml # <-- Full local container environment mesh (Redis, App, Postgres)
└── Dockerfile # <-- Minimal production runtime workspace blueprint
├── tests/
├── unit/ # <-- Job #3: Asynchronous socket validation benches
└── schemas/ # <-- Job #7: JSON framing contract tests
├── dailylog.md # <-- Maintenance operations history ledger
└── requirements.txt # <-- Managed dependencies
├── chat_core/
│ ├── __init__.py
│ ├── config.py # <-- Application security settings & validation rules
│ ├── crypto_broker.py # <-- Challenge generation and key distribution logic
│ └── connection_manager.py # <-- Tier 5: High-concurrency socket tracking state loop
├── deployment/
│ ├── gateway.conf # <-- Tier 2: Envoy or Nginx reverse-proxy ingress rules
│ ├── docker-compose.yml # <-- Full local container environment mesh (Redis, App, Postgres)
│ └── Dockerfile # <-- Minimal production runtime workspace blueprint
├── tests/
│ ├── unit/ # <-- Job #3: Asynchronous socket validation benches
│ └── schemas/ # <-- Job #7: JSON framing contract tests
├── dailylog.md # <-- Maintenance operations history ledger
└── requirements.txt # <-- Managed dependencies


Engineering Roadmap
Expand Down
10 changes: 5 additions & 5 deletions app/core/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import os
from datetime import datetime, timedelta, timezone
from typing import Optional

from jose import JWTError, jwt
import jwt
from jwt import InvalidTokenError
from passlib.context import CryptContext

SECRET_KEY = os.getenv("SECRET_KEY")
Expand All @@ -27,7 +27,7 @@ def verify_password(plain_password: str, hashed_password: str) -> bool:
return pwd_context.verify(plain_password, hashed_password)


def create_access_token(data: dict, expires_delta: Optional[timedelta] = None):
def create_access_token(data: dict, expires_delta: timedelta | None = None):
to_encode = data.copy()

expire = datetime.now(timezone.utc) + (
Expand All @@ -42,5 +42,5 @@ def verify_token(token: str):
try:
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
return payload
except JWTError:
return None
except InvalidTokenError:
return None
4 changes: 4 additions & 0 deletions backend/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from fastapi import FastAPI

from backend.config import settings
from backend.routes.chat_routes import router as chat_router
from backend.routes.ws_routes import router as websocket_router


def create_app() -> FastAPI:
"""
Expand All @@ -15,6 +18,7 @@ def create_app() -> FastAPI:

# Include application routes
app.include_router(chat_router, prefix="/chat", tags=["Chat"])
app.include_router(websocket_router, tags=["WebSocket"])

@app.get("/", tags=["Health"])
async def root():
Expand Down
2 changes: 1 addition & 1 deletion backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Settings:
API_VERSION: str = "v1"

# Local development settings
HOST: str = os.getenv("HOST", "0.0.0.0")
HOST: str = os.getenv("HOST", "127.0.0.1")
PORT: int = int(os.getenv("PORT", "10000"))

settings = Settings()
Loading
Loading