|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## What this is |
| 6 | + |
| 7 | +`timeplus-ocsf-simulator` — an independent Python library that generates simulated OCSF |
| 8 | +(Open Cybersecurity Schema Framework) events. Structured to mirror |
| 9 | +[`taxi-route-simulator`](https://github.com/timeplus-io/taxi-route-simulator): a slim |
| 10 | +`pyproject.toml`, `src/ocsf_simulator/` package, and a stdout-by-default CLI. |
| 11 | + |
| 12 | +## Install and run |
| 13 | + |
| 14 | +```bash |
| 15 | +pip install -e . # editable install (requires modern pip; pip 21 fails) |
| 16 | +pip install -e ".[kafka]" # adds optional Kafka output |
| 17 | +pip install -e ".[ocsf]" # adds real ocsf-lib schema lookup |
| 18 | +ocsf-sim --max-events 5 # CLI entry point |
| 19 | +python -m ocsf_simulator # equivalent |
| 20 | +python main.py # example script (4 events) |
| 21 | +``` |
| 22 | + |
| 23 | +There is no test suite yet. There is no `Makefile`, `tox.ini`, or CI. |
| 24 | + |
| 25 | +## Hard rules |
| 26 | + |
| 27 | +- **stdout is reserved for the JSON event stream.** Every event the simulator emits is one |
| 28 | + JSON object per line on stdout. Logging, warnings, schema-load chatter, and `print()` |
| 29 | + diagnostics MUST go to stderr. `JSONSchemaFaker` already does this — preserve the pattern |
| 30 | + in any new code. If you need to add user-facing output, route it to stderr or to the |
| 31 | + `logging` module (which is already configured to stderr in `simulator.py`). |
| 32 | + |
| 33 | +- **Do not reintroduce Timeplus / proton-driver output.** The library was deliberately |
| 34 | + migrated from a Timeplus-coupled version into an independent lib. `TimeplusClient`, |
| 35 | + `proton-driver`, and the old `tp-sync/` SQL were dropped on purpose. Kafka remains as an |
| 36 | + optional extra because it isn't Timeplus-specific. |
| 37 | + |
| 38 | +- **Optional dependencies are loaded via `try/except ImportError`** (see `simulator.py` |
| 39 | + for `kafka`, `json_schema_faker.py` for `ocsf`). Don't move `kafka-python` or `ocsf-lib` |
| 40 | + into base `dependencies` in `pyproject.toml` — they belong under |
| 41 | + `[project.optional-dependencies]`. |
| 42 | + |
| 43 | +- **Package data lives inside the package and is loaded via `importlib.resources`.** |
| 44 | + See `geonames.py` — it loads `data/worldcities.csv` from |
| 45 | + `resources.files(__package__).joinpath(...)`, not a relative path. Relative paths break |
| 46 | + once the package is pip-installed. Any new data file goes under |
| 47 | + `src/ocsf_simulator/data/` and gets added to `[tool.setuptools.package-data]` in |
| 48 | + `pyproject.toml` and `MANIFEST.in`. |
| 49 | + |
| 50 | +## Layout |
| 51 | + |
| 52 | +``` |
| 53 | +src/ocsf_simulator/ |
| 54 | + __init__.py public API exports |
| 55 | + __main__.py enables `python -m ocsf_simulator` |
| 56 | + simulator.py OCSFEventSimulator, SimulatorConfig, Stdout/Kafka clients, main_cli |
| 57 | + json_schema_faker.py event generator (1276 lines, copied verbatim from the migration source) |
| 58 | + geonames.py random city lookup; uses importlib.resources |
| 59 | + data/worldcities.csv package data |
| 60 | +``` |
| 61 | + |
| 62 | +`main_cli` (in `simulator.py`) is the `ocsf-sim` entry point declared in `pyproject.toml`. |
| 63 | +`stream_ocsf_events` is the library-API generator for programmatic use. |
0 commit comments