|
| 1 | +# AGENTS.md: Drasi Platform |
| 2 | + |
| 3 | +## 1. High-Level Overview |
| 4 | + |
| 5 | +- **Purpose**: Drasi is a platform for building real-time, change-driven systems using continuous queries. |
| 6 | +- **Architecture**: Polyglot microservices system designed for Kubernetes. |
| 7 | +- **Core Technologies**: Rust (backend), Go (CLI), Dapr (inter-service communication). |
| 8 | +- **Repository**: `https://github.com/drasi-project/drasi-platform/`. |
| 9 | +- **Contribution Workflow**: Fork repo, commit to your fork and submit pull request. |
| 10 | + |
| 11 | +### Architectural Flow Diagram |
| 12 | + |
| 13 | +This diagram shows two primary flows: management (solid lines) and data pipeline (dashed lines). |
| 14 | + |
| 15 | +```mermaid |
| 16 | +graph TD |
| 17 | + subgraph "User Interaction" |
| 18 | + User["User/Developer"] --> CLI["cli/"]; |
| 19 | + end |
| 20 | +
|
| 21 | + subgraph "Platform Management" |
| 22 | + CLI -->|Manages Resources via API| ControlPlane["control-planes/"]; |
| 23 | + ControlPlane -->|Deploys & Configures| DeployedServices; |
| 24 | + end |
| 25 | +
|
| 26 | + subgraph "Deployed Services (on Kubernetes)" |
| 27 | + direction LR |
| 28 | + DeployedServices("Sources, Query Containers, Reactions"); |
| 29 | + end |
| 30 | +
|
| 31 | + subgraph "Core Data Pipeline" |
| 32 | + direction LR |
| 33 | + ExternalDataSource["External Data Source"] -.-> Sources["sources/"]; |
| 34 | + Sources -.-> QueryContainer["query-container/"]; |
| 35 | + QueryContainer -.-> Reactions["reactions/"]; |
| 36 | + Reactions -.-> ExternalSystem["External System (e.g., API, DB)"]; |
| 37 | + end |
| 38 | +``` |
| 39 | + |
| 40 | +## 2. Critical Development Notes |
| 41 | + |
| 42 | +### **Git Submodule: `drasi-core`** |
| 43 | + |
| 44 | +The `query-container/query-host` service depends on the `drasi-core` git submodule. Before building the `query-container`, the submodule **must** be initialized. Other components (`reactions`, `sources`, `control-planes`) can be built without it. |
| 45 | + |
| 46 | +- **Location**: `query-container/query-host/drasi-core/` |
| 47 | +- **Source Repository**: `https://github.com/drasi-project/drasi-core` |
| 48 | +- **Initialization Command**: `git submodule update --init --recursive` |
| 49 | + |
| 50 | +Failure to initialize will cause compilation errors in `query-container`. For details on the engine, see the `README.md` within the submodule directory. |
| 51 | + |
| 52 | +### **Data Contracts: `typespec/`** |
| 53 | + |
| 54 | +The `typespec/` directory is the **single source of truth** for all inter-service data contracts. |
| 55 | + |
| 56 | +- **DO NOT** edit generated model files elsewhere. |
| 57 | +- All data model changes **must** be made in the source `.tsp` files. |
| 58 | +- After editing `.tsp` files, run the full generation workflow: |
| 59 | + 1. `npm install && npm run build` (in `typespec/`). |
| 60 | + 2. Run `quicktype` commands (defined in component `Makefile`s) to generate language-specific code from the updated JSON Schema. |
| 61 | + |
| 62 | +Failure to follow this workflow will cause data contract mismatches. |
| 63 | + |
| 64 | +## 3. Component Directory Guide |
| 65 | + |
| 66 | +- **`cli/`**: Go CLI (`drasi`) for platform installation and management. |
| 67 | +- **`control-planes/`**: Rust backend. Contains the `mgmt_api` and the `kubernetes_provider`. |
| 68 | +- **`query-container/`**: Rust microservices for the continuous query execution environment (`publish-api`, `query-host`, `view-svc`). |
| 69 | +- **`reactions/`**: Rust microservices that act on query results. Contains built-in reactions and SDKs. |
| 70 | +- **`sources/`**: Rust microservices that ingest data from external systems. Contains built-in sources and SDKs. |
| 71 | +- **`typespec/`**: Source of truth for all data contracts. |
| 72 | +- **`e2e-tests/`**: Jest/TypeScript end-to-end tests. |
| 73 | + |
| 74 | +## 4. Build and Test |
| 75 | + |
| 76 | +The root `Makefile` provides top-level targets for the primary development workflows: |
| 77 | +- **`make docker-build`**: Builds all container images for the platform. |
| 78 | +- **`make test`**: Runs the test suites for all components. |
| 79 | +- **`make lint-check`**: Performs all code quality and lint checks. |
| 80 | + |
| 81 | +For local Kubernetes workflows, `make kind-load` and `make k3d-load` are available to load built images into a cluster. |
| 82 | + |
| 83 | +The build system uses a recursive `make` structure. The root `Makefile` delegates targets (e.g., `docker-build`, `test`) to Makefiles in component subdirectories (`control-planes/`, `query-container/`, etc.), which in turn delegate to their own subdirectories. This orchestrates a full repository build from the top down. |
| 84 | + |
| 85 | +## 5. Core Architecture & Runtime |
| 86 | + |
| 87 | +- **Pluggable Resource Providers**: The control plane is platform-agnostic. The `mgmt_api` communicates with a resource provider via a shared contract (`resource_provider_api`). The `kubernetes_provider` is the current implementation, translating Drasi resources into Kubernetes objects. This design allows for future platform providers. |
| 88 | + |
| 89 | +- **Dapr Integration**: Dapr is a mandatory dependency for the backend, handling all inter-service communication (Pub/Sub) and resource lifecycle management (Dapr Actors). `drasi init` installs Dapr if needed. |
| 90 | + |
| 91 | +- **Deployment Modes**: |
| 92 | + - **Kubernetes**: The standard deployment target. `drasi init` installs into the current `kubectl` context. |
| 93 | + - **Docker**: `drasi init --docker` provides a self-contained environment using a K3d (Kubernetes in Docker) cluster. |
| 94 | + |
| 95 | +- **User Workflow**: |
| 96 | + 1. Deploy the platform using `drasi init`. |
| 97 | + 2. Define `Source`, `ContinuousQuery`, and `Reaction` resources in YAML. |
| 98 | + 3. Deploy and manage resources using `drasi apply -f <file>.yaml`. |
0 commit comments