Skip to content

Commit 0c0b21f

Browse files
authored
docs, api, other stuff update (#101)
* docs, api, other stuff update * fixes
1 parent f2307de commit 0c0b21f

12 files changed

Lines changed: 365 additions & 477 deletions

File tree

backend/.env

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@ KAFKA_HEARTBEAT_INTERVAL_MS=10000
2929
KAFKA_REQUEST_TIMEOUT_MS=40000
3030
KAFKA_MAX_POLL_RECORDS=500
3131

32-
# WebSocket Configuration
33-
WEBSOCKET_PING_INTERVAL=30
34-
WEBSOCKET_PING_TIMEOUT=10
32+
# SSE Configuration
33+
SSE_CONSUMER_POOL_SIZE=10
34+
SSE_HEARTBEAT_INTERVAL=30
3535

3636
# Logging Configuration
3737
LOG_LEVEL=DEBUG
38-
WEBSOCKET_MAX_CONNECTIONS_PER_USER=5
39-
WEBSOCKET_STALE_CONNECTION_TIMEOUT=300
4038

4139
# Distributed Tracing
4240
ENABLE_TRACING=true

backend/.env.test

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ KAFKA_HEARTBEAT_INTERVAL_MS=3000
3030
KAFKA_REQUEST_TIMEOUT_MS=15000
3131
KAFKA_MAX_POLL_RECORDS=500
3232

33-
# WebSocket Configuration
34-
WEBSOCKET_PING_INTERVAL=30
35-
WEBSOCKET_PING_TIMEOUT=10
33+
# SSE Configuration
34+
SSE_CONSUMER_POOL_SIZE=10
35+
SSE_HEARTBEAT_INTERVAL=30
3636

3737
# Logging Configuration
3838
LOG_LEVEL=WARNING
39-
WEBSOCKET_MAX_CONNECTIONS_PER_USER=5
40-
WEBSOCKET_STALE_CONNECTION_TIMEOUT=300
4139

4240
# Distributed Tracing
4341
ENABLE_TRACING=true

backend/app/settings.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ class Settings(BaseSettings):
112112
# App URL for notification links
113113
APP_URL: str = "https://integr8scode.cc"
114114

115-
# WebSocket configuration
116-
WEBSOCKET_PING_INTERVAL: int = 30
117-
WEBSOCKET_PING_TIMEOUT: int = 10
118-
119115
# Redis Configuration
120116
REDIS_HOST: str = "redis"
121117
REDIS_PORT: int = 6379
@@ -131,8 +127,6 @@ class Settings(BaseSettings):
131127
RATE_LIMIT_BURST_MULTIPLIER: float = 1.5
132128
RATE_LIMIT_REDIS_PREFIX: str = "rate_limit:"
133129
RATE_LIMIT_ALGORITHM: str = "sliding_window" # sliding_window or token_bucket
134-
WEBSOCKET_MAX_CONNECTIONS_PER_USER: int = 5
135-
WEBSOCKET_STALE_CONNECTION_TIMEOUT: int = 300
136130

137131
# Service metadata
138132
SERVICE_NAME: str = "integr8scode-backend"

docs/SECURITY.md

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,19 @@
11
# Security Policy
22

3-
Integr8sCode takes the security of our software and our users' data seriously. We are committed to ensuring a secure
4-
environment and following best practices for vulnerability management and disclosure.
3+
Security patches go into `main` and the latest release. If you're running something older, upgrade.
54

6-
## Supported Versions
5+
## Reporting vulnerabilities
76

8-
We currently support security updates for the following versions of Integr8sCode:
7+
Found a security issue? Don't open a public GitHub issue - email [max.azatian@gmail.com](mailto:max.azatian@gmail.com) instead.
98

10-
| Version | Supported |
11-
|----------------|--------------------|
12-
| `main` | :white_check_mark: |
13-
| Latest Release | :white_check_mark: |
9+
Include what you can: vulnerability type, where it occurs, reproduction steps, PoC if you have one. You'll get an acknowledgment within 48 hours. If confirmed, we'll patch it and credit you in the disclosure (unless you prefer to stay anonymous).
1410

15-
If you are running an older version, we strongly recommend upgrading to the latest release to ensure you have the most
16-
recent security patches.
11+
## Automated scanning
1712

18-
## Reporting a Vulnerability
13+
The CI pipeline runs [Bandit](https://bandit.readthedocs.io/) on the Python backend for static analysis, and [Dependabot](https://docs.github.com/en/code-security/dependabot) keeps dependencies patched across Python, npm, and Docker. For SBOM generation and vulnerability scanning, see [Supply Chain Security](security/supply-chain.md).
1914

20-
If you discover a security vulnerability within Integr8sCode, please **DO NOT** create a public GitHub issue. Instead,
21-
please report it privately to our security team.
15+
## Runtime hardening
2216

23-
### How to Report
17+
Executor pods run user code with non-root users, read-only filesystems, dropped capabilities, and no service account tokens. Network policies deny all traffic by default. Details in [Network Isolation](security/policies.md).
2418

25-
1. **Email:** Send a detailed report to <mailto:max.azatian@gmail.com>.
26-
2. **Details:** Please include as much information as possible:
27-
* Type of vulnerability (e.g., XSS, SQL Injection, RCE).
28-
* Full path or URL where the vulnerability occurs.
29-
* Step-by-step instructions to reproduce the issue.
30-
* Proof of concept (PoC) code or screenshots, if available.
31-
* Any specific configuration required to reproduce the issue.
32-
33-
### Our Response Process
34-
35-
1. **Acknowledgment:** We will acknowledge receipt of your report within 48 hours.
36-
2. **Assessment:** We will investigate the issue to confirm its validity and impact.
37-
3. **Resolution:** If confirmed, we will work on a patch. We will keep you updated on our progress.
38-
4. **Disclosure:** Once a fix is released, we will publicly disclose the vulnerability (with your permission, crediting
39-
you for the discovery).
40-
41-
## Security Measures
42-
43-
We employ several automated tools and practices to maintain the security of our codebase:
44-
45-
* **Static Application Security Testing (SAST):** We use **Bandit** to scan our Python backend code for common security
46-
issues.
47-
* **Dependency Management:** We use **Dependabot** to automatically monitor and update vulnerable dependencies in our
48-
`package.json`, `pyproject.toml`, and Docker files.
49-
* **Container Security:** We follow best practices for containerization, including using minimal base images and
50-
non-root users where possible.
51-
* **Secrets Management:** We do not commit secrets to the repository. Please ensure `.env` files and other secrets are
52-
properly managed in your deployment environment.
53-
54-
## Software Bill of Materials (SBOM)
55-
56-
We strive to maintain transparency regarding our dependencies. You can inspect our direct dependencies in:
57-
58-
* `backend/pyproject.toml` (Python)
59-
* `frontend/package.json` (Node.js/Svelte)
60-
* `helm/integr8scode/Chart.yaml` (Kubernetes/Helm)
61-
62-
Thank you for helping keep Integr8sCode safe!
19+
Secrets stay out of the repo - `.env` files and credentials are your responsibility to manage in deployment.

docs/components/sse/sse-architecture.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,37 @@ Key metrics: `sse.connections.active`, `sse.messages.sent.total`, `sse.connectio
8383

8484
WebSockets were initially implemented but removed because SSE is sufficient for server-to-client communication, simpler connection management, better proxy compatibility (many corporate proxies block WebSockets), excellent browser support with automatic reconnection, and works great with HTTP/2 multiplexing.
8585

86+
## Testing SSE endpoints
87+
88+
Testing SSE endpoints in E2E tests is tricky. Our tests use `httpx.AsyncClient` with `ASGITransport` to run against the FastAPI app in-process without starting a real server. The problem is that httpx's ASGITransport buffers entire responses before returning, which causes tests to hang indefinitely when streaming SSE — the response never "completes" because SSE streams are infinite by design.
89+
90+
This is a [known limitation](https://github.com/encode/httpx/issues/2186) with no fix in sight (there's an open PR since January 2024 but it hasn't been merged).
91+
92+
The solution is [async-asgi-testclient](https://github.com/vinissimus/async-asgi-testclient), an alternative ASGI test client that properly handles streaming. It's added as a dev dependency and used alongside httpx — httpx for regular requests, async-asgi-testclient for SSE endpoints.
93+
94+
The test fixtures copy authentication cookies and CSRF tokens from the httpx client to the SSE client, so both share the same session:
95+
96+
```python
97+
@pytest_asyncio.fixture
98+
async def sse_client(app: FastAPI, test_user: AsyncClient) -> SSETestClient:
99+
client = SSETestClient(app)
100+
for name, value in test_user.cookies.items():
101+
client.cookie_jar.set(name, value)
102+
if csrf := test_user.headers.get("X-CSRF-Token"):
103+
client.headers["X-CSRF-Token"] = csrf
104+
return client
105+
```
106+
107+
Tests then verify that SSE endpoints return the correct content-type and stream data:
108+
109+
```python
110+
async def test_notification_stream(self, sse_client: SSETestClient) -> None:
111+
async with sse_client:
112+
response = await sse_client.get("/api/v1/events/notifications/stream", stream=True)
113+
assert response.status_code == 200
114+
assert "text/event-stream" in response.headers.get("content-type", "")
115+
```
116+
86117
## Key files
87118

88119
| File | Purpose |

docs/getting-started.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# Getting Started
2+
3+
This guide walks you through running Integr8sCode locally and executing your first script. You'll need Docker and Docker Compose installed - that's it.
4+
5+
## What you're deploying
6+
7+
The full stack includes a Svelte frontend, FastAPI backend, MongoDB, Redis, Kafka with Schema Registry, and seven background workers. Sounds like a lot, but `docker compose` handles all of it. First startup takes a few minutes to pull images and initialize services; subsequent starts are much faster.
8+
9+
## Start the stack
10+
11+
```bash
12+
git clone https://github.com/HardMax71/Integr8sCode.git
13+
cd Integr8sCode
14+
./deploy.sh dev
15+
```
16+
17+
Wait for the services to come up. You can watch progress with `docker compose logs -f` in another terminal. When you see the backend responding to health checks, you're ready.
18+
19+
Verify everything is running:
20+
21+
```bash
22+
curl -k https://localhost/api/v1/health/live
23+
```
24+
25+
If everything is up, you'll get:
26+
27+
```json
28+
{"status":"ok","uptime_seconds":42,"timestamp":"2025-01-25T12:00:00Z"}
29+
```
30+
31+
## Access the UI
32+
33+
Open [https://localhost:5001](https://localhost:5001) in your browser. You'll get a certificate warning since it's a self-signed cert - accept it and continue.
34+
35+
Log in with the default credentials:
36+
37+
- **Username:** `user`
38+
- **Password:** `user123`
39+
40+
For admin access (user management, system settings, event browser), use `admin` / `admin123`.
41+
42+
!!! warning "Development only"
43+
These credentials are seeded automatically for local development. For production, set `DEFAULT_USER_PASSWORD` and `ADMIN_USER_PASSWORD` environment variables before deploying.
44+
45+
## Run your first script
46+
47+
The editor opens with a Python example. Click **Run** to execute it. You'll see output streaming in real-time as the script runs in an isolated Kubernetes pod (or Docker container in dev mode).
48+
49+
Try modifying the script or switching languages using the dropdown. Each execution gets its own isolated environment with configurable resource limits.
50+
51+
## What's happening under the hood
52+
53+
When you click Run:
54+
55+
1. The frontend sends your script to the backend API
56+
2. Backend validates it, creates an execution record, and publishes an event to Kafka
57+
3. The coordinator worker picks up the event and starts a saga
58+
4. K8s worker spins up an isolated pod with the appropriate runtime
59+
5. Pod monitor watches for completion and captures output
60+
6. Result processor stores the result and publishes it to Redis
61+
7. Your browser receives the result via Server-Sent Events
62+
63+
All of this happens in a few seconds. The event-driven architecture means you can scale each component independently and replay events for debugging.
64+
65+
## Explore the stack
66+
67+
With the stack running, you can poke around:
68+
69+
| Service | URL | What it shows |
70+
|---------|-----|---------------|
71+
| Kafdrop | [http://localhost:9000](http://localhost:9000) | Kafka topics and messages |
72+
| Grafana | [http://localhost:3000](http://localhost:3000) | Metrics dashboards (admin/admin123) |
73+
| Jaeger | [http://localhost:16686](http://localhost:16686) | Distributed traces |
74+
75+
## Troubleshooting
76+
77+
**CPU/memory metrics show as `null`**
78+
79+
The metrics server isn't installed by default in most local Kubernetes setups. Enable it:
80+
81+
```bash
82+
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
83+
```
84+
85+
**Certificate warnings in browser**
86+
87+
Expected - the stack uses self-signed certs for local development. Accept the warning and continue.
88+
89+
**Services failing to start**
90+
91+
Check logs for the specific service: `docker compose logs backend` or `docker compose logs kafka`. Most issues are either port conflicts (something else using 443, 5001, or 9092) or Docker running out of resources.
92+
93+
**Kafka connection errors**
94+
95+
Kafka takes longer to initialize than most services. Give it a minute after `deploy.sh dev` finishes, or watch `docker compose logs kafka` until you see "started" messages.
96+
97+
## Stop the stack
98+
99+
```bash
100+
./deploy.sh down
101+
```
102+
103+
To also remove persistent data (MongoDB, Redis volumes):
104+
105+
```bash
106+
docker compose down -v
107+
```
108+
109+
## Next steps
110+
111+
- [Architecture Overview](architecture/overview.md) - How the pieces fit together
112+
- [Deployment](operations/deployment.md) - Production deployment with Helm
113+
- [API Reference](reference/api-reference.md) - Full endpoint documentation
114+
- [Environment Variables](reference/environment-variables.md) - Configuration options

0 commit comments

Comments
 (0)