|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +hier-config-api is a FastAPI REST API providing an interface to the [hier_config](https://github.com/netdevops/hier_config) network configuration management library. It enables comparing, analyzing, and generating remediation commands for network device configurations across platforms (Cisco IOS, NX-OS, IOS-XR, Juniper Junos, Arista EOS). |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Install dependencies |
| 13 | +poetry install # production deps |
| 14 | +poetry install --with dev # include dev deps |
| 15 | + |
| 16 | +# Run development server (with hot reload) |
| 17 | +poetry run uvicorn hier_config_api.main:app --reload |
| 18 | + |
| 19 | +# Linting & formatting |
| 20 | +poetry run ruff check . # lint |
| 21 | +poetry run ruff check . --fix # lint with auto-fix |
| 22 | +poetry run ruff format . # format |
| 23 | +poetry run ruff format --check . # check formatting |
| 24 | + |
| 25 | +# Type checking |
| 26 | +poetry run mypy hier_config_api |
| 27 | + |
| 28 | +# Tests |
| 29 | +poetry run pytest # all tests (includes coverage) |
| 30 | +poetry run pytest tests/test_configs.py -v # single test file |
| 31 | +poetry run pytest tests/test_configs.py::test_parse_config -v # single test |
| 32 | + |
| 33 | +# Documentation |
| 34 | +poetry run mkdocs serve # local preview with live reload |
| 35 | +poetry run mkdocs build # build static site |
| 36 | +``` |
| 37 | + |
| 38 | +## Architecture |
| 39 | + |
| 40 | +**Layered design:** Routers → Services → hier_config library, with Pydantic models for request/response validation. |
| 41 | + |
| 42 | +- `hier_config_api/main.py` — FastAPI app setup, CORS middleware, router registration. Custom doc URLs at `/api/docs`, `/api/redoc`, `/api/openapi.json`. |
| 43 | +- `hier_config_api/routers/` — API endpoint definitions. Each router uses `prefix="/api/v1/{domain}"`. Routers delegate to service classes and wrap errors in `HTTPException`. |
| 44 | +- `hier_config_api/services/` — Business logic as classes with **static methods**. Each service maps to a router: `ConfigService`, `RemediationService`, `ReportService`, `PlatformService`. |
| 45 | +- `hier_config_api/models/` — Pydantic `BaseModel` classes for request/response validation, organized by domain (`config.py`, `remediation.py`, `report.py`, `platform.py`). All fields use `Field()` with descriptions. |
| 46 | +- `hier_config_api/utils/storage.py` — In-memory dictionary storage (no persistence). Global `storage` singleton used by services for reports, jobs, and remediations. |
| 47 | + |
| 48 | +**API endpoint groups** (all under `/api/v1/`): |
| 49 | +- `/configs` — parse, compare, predict, merge, search configurations |
| 50 | +- `/remediation` — generate remediation/rollback, apply tags, filter by tags |
| 51 | +- `/reports` — multi-device reports with summary, changes, export (JSON/CSV/YAML) |
| 52 | +- `/platforms` — list platforms, get rules, validate configs |
| 53 | +- `/batch` — batch remediation jobs with status tracking |
| 54 | + |
| 55 | +## Code Quality |
| 56 | + |
| 57 | +- **Ruff**: linter and formatter, line length 100, target Python 3.10 |
| 58 | +- **MyPy**: strict mode enabled; `hier_config.*` has `ignore_missing_imports` |
| 59 | +- **Pytest**: asyncio_mode="auto", coverage configured via `--cov=hier_config_api` |
| 60 | +- Tests use `FastAPI.TestClient` with fixtures in `tests/conftest.py` |
| 61 | + |
| 62 | +## CI |
| 63 | + |
| 64 | +GitHub Actions runs on push/PR to `main`/`develop`: |
| 65 | +- **Lint job**: ruff check, ruff format --check, mypy |
| 66 | +- **Test job**: pytest across Python 3.10, 3.11, 3.12 |
0 commit comments