Skip to content

Latest commit

 

History

History
111 lines (85 loc) · 5.04 KB

CLAUDE.md

File metadata and controls

111 lines (85 loc) · 5.04 KB

NetConsole — Claude Context

Project Overview

Network management platform for configuring switches and routers, tracking MACs/ARPs/interfaces, and managing credentials. Built on FastAPI + SQLModel + PostgreSQL (backend) and React + Chakra UI + TanStack Router/Query (frontend). Deployed via Docker Compose.

Architecture

backend/     FastAPI app (Python)
frontend/    React + Vite + Chakra UI + TanStack Router
mcp_server/  MCP server exposing the REST API as tools (stdio, local process)
docker-compose.yml  — local dev (with docker-compose.override.yml)
docker-compose.traefik.yml  — production

Backend (backend/app/)

Path Purpose
models.py All SQLModel DB models + Pydantic response schemas
api/routes/ FastAPI route handlers (one file per domain)
api/deps.py CurrentUser, SessionDep, get_current_active_superuser — accepts JWT Authorization: Bearer or X-API-Key header
api/main.py Router registration
crud/ DB query functions called from routes
core/config.py Pydantic Settings (reads .env)
core/security.py create_access_token(subject, expires_delta) — both args required
alembic/versions/ Migration chain: e2412789 → 65f8c8c4 → f0418d9e → a3f1b2c4 → b4c5d6e7 → c1d2e3f4 → d1e2f3a4 → e2f3a4b5 → f4a5b6c7 → a7b8c9d0 → 8c234143 → b9d0e1f2 → c5d6e7f8 → d6e7f8a9 → e8f9a0b1 → f9a0b1c2 → a1b2c3d4 → 48a528e5 (head)
automation/ Nornir/NAPALM/Netmiko tasks for live device config

Frontend (frontend/src/)

Path Purpose
client/ Auto-generated OpenAPI client — edit manually only when backend is not running
routes/_layout/ Protected pages (admin, devices, interfaces, logs, credentials, groups, settings…)
routes/ (root) Public pages: login, oauth-callback, recover/reset-password
components/ Grouped by domain: Admin/, Auth/, Common/, Devices/, Interfaces/, etc.
routeTree.gen.ts Auto-generated by Vite TanStack Router plugin — update manually when tsc runs before Vite

Key Conventions

Backend

  • All models live in models.py (DB table models + Public response schemas)
  • Add action: str, Field(index=True) and indexes on columns used for filtering
  • write_audit_log(session, username, action, *, client_ip, message, severity) in crud/audit.py — call after every write operation
  • Request param needed to get request.client.host for audit logs
  • Endpoints using dependencies=[Depends(get_current_active_superuser)] can also accept current_user: CurrentUser as a param for audit logging
  • New migration: down_revision = "48a528e5d66b" (current head)

Frontend

  • Generated client in frontend/src/client/ — when backend changes and Docker is not running, update models.ts and services.ts manually
  • TanStack Query: useSuspenseQuery inside <Suspense> for data fetching
  • Chakra UI — never use defaultChecked on Checkbox with react-hook-form; use defaultValues instead
  • OpenAPI.TOKEN is string | Resolver<string> — check typeof before calling
  • Route files use createFileRoute() — new public routes need manual entry in routeTree.gen.ts if Vite plugin hasn't run

Running Locally

# Start all services
docker compose up -d

# Apply migrations
docker compose exec backend alembic upgrade head

# Regenerate frontend client (when backend is running)
cd frontend && npm run generate-client

# Backend logs
docker compose logs -f backend

# Frontend build
docker compose exec frontend npm run build

Auth Methods

Users can authenticate via:

  1. Email + password (JWT HS256)
  2. Google OAuth2 (GOOGLE_CLIENT_ID/SECRET)
  3. Microsoft Azure AD (MICROSOFT_CLIENT_ID/SECRET/TENANT_ID)
  4. Keycloak OIDC (KEYCLOAK_CLIENT_ID/SECRET/SERVER_URL/REALM)
  5. Passkey/WebAuthn (WEBAUTHN_RP_ID/RP_NAME/ORIGIN)

OAuth state + WebAuthn challenges stored in signed itsdangerous cookies (stateless).

Database Domains

Table Description
user Users with optional hashed_password, password_login_enabled flag
apikey Service-account API keys (bcrypt-hashed) for machine clients like the MCP server
oauthaccount OAuth provider links per user
webauthncredential Passkey credentials per user
auditlog Audit trail for all write operations
device Network devices (hostname, IP, platform, vendor…)
interface Device interfaces with VLAN/duplex/speed config
macaddress MAC address table entries
arp ARP table entries
ipinterface Layer 3 interface assignments
group Device groups for bulk operations
credential SSH/key credentials for device access

Network Automation

backend/app/automation/ uses Nornir with NAPALM/Netmiko drivers. Supported platforms: Cisco IOS, Cisco NX-OS, Juniper JunOS. Tasks: get interfaces, update interface config, shutdown interface, update running config.

Deployment

Production uses Traefik reverse proxy with automatic HTTPS. See docker-compose.traefik.yml. GitHub Actions CI in .github/workflows/.