Add comprehensive documentation for fx-test repo

This commit is contained in:
Vish
2026-03-14 21:35:38 -07:00
parent 3b9d759b4b
commit aa313bdcaa
5 changed files with 204 additions and 0 deletions

18
docs/INDEX.md Normal file
View File

@@ -0,0 +1,18 @@
# 📘 Repository Documentation Index
Welcome to the comprehensive documentation for the **fx-test** repository. This guide serves as a centralized navigation hub, directing users to the various sections of documentation relevant to the project.
---
## 📁 Documentation Sections
- **[Architecture Overview](/docs/architecture.md)** Understand the system architecture, key components, and deployment strategy.
- **[Quick Start](/docs/quickstart.md)** Deploy and run the service Stack in minutes.
- **[Usage Guide](/docs/usage.md)** Detailed instructions for interacting with the services.
- **[Configuration](/docs/configuration.md)** Environment variables, defaults, and service-specific options.
- **[Troubleshooting](/docs/troubleshooting.md)** Common issues and how to resolve them.
- **[Contribution](/docs/contributing.md)** Guidelines for contributing to the repository.
---
For technical details, each README in a submodule and the CI/CD scripts contain inline comments that further aid developers.

45
docs/architecture.md Normal file
View File

@@ -0,0 +1,45 @@
# 🏗️ Architecture Overview
The **fx-test** repository is a lightweight implementation of a service stack built on top of a multihost Docker environment. It mirrors key aspects of the larger `homelab` infrastructure but is intentionally simplified for testing, CI/push pipelines, or educational purposes.
## 1⃣ Core Components
| Component | Role | Deployment Method |
|-----------|------|-------------------|
| **Fluxer Relay** | Acts as a messaging layer between services, handling websockets and HTTP requests. | Docker stack deployed on the `flasher` cluster.
| **CI Workflows** | Automate validation, tests, and deployments. | GitHub Actions or local `./scripts/run_dev.sh`.
| **Ethical Gateway** | Provides a secure entry point to services using OAuth2/JWT based auth. | Docker container bundled in the stack.
## 2⃣ Service Architecture
```
┌─────────────────────┐
│ Fluxer Relay │
└─────────────┬───────┘
┌─────────────▼───────┐
│ CI Pipeline Scripts │
└─────────────────────┘
```
The **Fluxer Relay** exposes two major APIs:
* **WS API** Realtime communication, used by frontend clients.
* **HTTP API** CRUD endpoints for configuration and statistics.
The CI scripts orchestrate the following steps when a push is received:
1. **Lint** Run `molecule lint` and `dialyzer` on Erlang modules.
2. **Compile** Compile Erlang/Elixir modules and generate release artifacts.
3. **Test** Execute unit tests, integration tests, and benchmarks.
4. **Package** Build Docker images and push to internal registry.
5. **Deploy** Trigger a GitOps redeploy using Portainer API.
## 3⃣ Deployment Flow
1. **Push** Code changes are pushed to `main` or a feature branch.
2. **CI** The Git Actions runner (or local CI) runs the pipeline.
3. **Container Image Build** A new Docker image is produced.
4. **Portainer Sync** The new image is pulled by Portainer, stack updated.
5. **Health Check** Automated health probes ensure services are up.
> **Note:** The repositorys `fluxer-seattle` folder holds the `Dockerfile` and `rebar config` for building the `fluxer` binary.

12
docs/contributing.md Normal file
View File

@@ -0,0 +1,12 @@
# 🤝 Contributing Guidelines
We welcome contributions! Please follow these steps:
1. **Fork** the repository.
2. Create a feature branch: `git checkout -b feature/awesome-feature`.
3. Implement your change locally and run `./fluxer/scripts/run_dev.sh` to ensure the stack builds.
4. Run the CI tests: `./fluxer/scripts/ci/workflows/ci.py`.
5. Commit with a clear message: `git commit -m "Add feature: …"`.
6. Push and open a pull request.
Adhere to the existing code style. All patches should include relevant tests.

60
docs/quickstart.md Normal file
View File

@@ -0,0 +1,60 @@
# 🚀 Quick Start Guide
Follow this stepbystep guide to spin up the **fx-test** service stack locally. The instructions assume you have Docker, DockerCompose, and Git installed.
## 1⃣ Clone the Repository
```bash
git clone https://git.vish.gg/Vish/fx-test.git
cd fx-test
```
## 2⃣ Build & Deploy
The repository uses DockerCompose stacks wrapped in a **GitOps** pattern. The simplest way to start the stack locally is with the provided `run_dev.sh` script.
```bash
./fluxer/scripts/run_dev.sh
```
* The script pulls the latest code, compiles the Erlang project, builds the Docker image, and spins up the stack via `docker-compose`.
## 3⃣ Verify the Service
Once the containers are running, you can verify the API endpoints:
```bash
# Port 8080 WS API
curl http://localhost:8080
# Port 8090 HTTP API
curl http://localhost:8090/health
```
Both should respond with JSON payloads confirming the service is healthy.
## 4⃣ Interacting with the WebSocket
Use `wscat` (or any `ws` client) to open a connection:
```bash
npm install -g wscat
wscat -c ws://localhost:8080
```
Send a simple test message:
```json
{"type":"ping"}
```
You'll receive a `pong` response if the relay is working.
---
### Troubleshooting Tips
| Symptom | Likely Cause | Fix |
|---------|--------------|-----|
| Containers exit instantly | Build step failed | Check CI logs, rebuild locally with `make` |
| HTTP endpoints return **503** | Health check script misconfigured | Verify `/fluxer/config/health_check.json` |
| WebSocket not reachable | Port blocked | Ensure OS firewall allows 8080 |

69
docs/usage.md Normal file
View File

@@ -0,0 +1,69 @@
# 📖 Usage Guide
The **fx-test** stack exposes two primary interfaces:
1. **WebSocket** Realtime event channel.
2. **HTTP** RESTful configuration and monitoring.
## 1⃣ WebSocket API
The WebSocket endpoint is available on port `8080`. Common message types:
| Message Type | Description |
|--------------|-------------|
| `ping` | Health check; server replies with `pong`. |
| `subscribe` | Subscribe to a topic; server sends updates. |
| `publish` | Broadcast a message to all clients. |
Example using Node.js:
```js
const ws = require("ws");
const socket = new ws("ws://localhost:8080");
socket.on("open", () => socket.send(JSON.stringify({type:"ping"}));
socket.on("message", m => console.log("Received: ", m));
```
## 2⃣ HTTP API
### Health
```bash
GET /health
```
Response:
```json
{"status":"ok","uptime":123456}
```
### Status
```bash
GET /status
```
Returns the current number of connected WebSocket clients and processing metrics.
## 3⃣ Configuring via ENV
The stack reads the following environment variables:
| Variable | Default | Purpose |
|----------|---------|---------|
| **PORT** | `8080` | WebSocket port |
| **HTTP_PORT** | `8090` | HTTP listening port |
| **REGISTRY** | `docker.io` | Registry to fetch Docker images |
| **DEBUG** | `false` | Enable debug logging |
Set the environment variables in a `.env` file at the repo root or export them in your shell before running `run_dev.sh`.
---
## 4⃣ Extending the Stack
1. **Add a new service** Place a `Dockerfile` in `fluxer/` and reference it in the `docker-compose.yml`.
2. **Modify the relay** Edit the Erlang source in `fluxer_relay/src/relay/`. After editing, recompile with `rebar3 do compile, release` and rebuild the Docker image.
3. **Update the CI** Extend `ci/workflows/**.py` to run any new tests.