How timapelmesh/corax works
Purpose and Entry Points
CORAX is a LAN-oriented PC inventory and lightweight helpdesk system. Windows agents collect workstation snapshots; a FastAPI backend persists and operates on them; a React SPA provides administration.
• Server entry: run.py; development orchestration: start_all.py, start_all.bat.
• Backend application/lifecycle: backend/app/main.py.
• Browser entry and routing: frontend/src/main.tsx, frontend/src/App.tsx.
• Production serves built SPA and API from one backend process, normally on port 3000; development separates Vite UI (:3000) and API (:3001).
Backend API and Domain Boundary
FastAPI is the system-of-record boundary. It wires middleware, authentication, migrations, routers, and production static UI serving.
• Router layer: backend/app/routers/.
• ORM and shared data contracts: backend/app/models.py, backend/app/schemas.py.
• Configuration and environment/production-secret validation: backend/app/config.py.
• API supports /api/v1 and compatibility /api; integrations should target v1.
Core domains include computers/inventory, dashboard/software, tags, users, service requests, building diagrams, printers, warehouse, agent token/bundle administration, and WikiRAG.
Persistence and Lifecycle
PostgreSQL is mandatory and is accessed asynchronously through SQLAlchemy/asyncpg.
• Connection/session infrastructure: backend/app/database.py, backend/app/async_pool.py.
• Startup schema evolution: backend/app/migrations.py.
• PostgreSQL bootstrap and legacy SQLite migration: scripts/ensure_postgres.py, scripts/migrate_sqlite_to_postgres.py.
Three configured URLs isolate logical concerns—main inventory, diagrams, and warehouse—though all normally point to one inventory database. Raw agent payloads, Bitrix diagnostics, and knowledge documents are filesystem-backed rather than primary database records.
Inventory-Agent Pipeline
Agents POST authenticated JSON inventory to the backend; server-side processing upserts a computer case-insensitively by hostname and replaces current software/peripheral snapshots.
• Ingestion endpoint/domain: backend/app/routers/agent.py.
• Per-agent token issuance, HMAC-hashed storage, revocation, and optional hostname binding: backend/app/routers/agent_tokens.py.
• Server-generated distributable agents: backend/app/agent_bundle.py, backend/app/routers/agent_bundles.py.
• Win10/11 PowerShell collection stages: agent/v3/win10/InventoryClient.ps1, agent/v3/win10/lib/Collect-System.ps1, agent/v3/win10/lib/Invoke-Post.ps1.
• Python/EXE agent basis: agent/python/agent.py.
This boundary uses Bearer agent tokens, payload-size/rate controls, and is exempt from browser CSRF.
Web Application and Collaboration
The React 19/Vite SPA uses a shared API client and auth context, with pages organized around operational domains.
• Cross-cutting API/auth state: frontend/src/api.ts, frontend/src/AuthContext.tsx.
• Shell/navigation: frontend/src/pages/Layout.tsx.
• Primary operational views: frontend/src/pages/ComputersPage.tsx, frontend/src/pages/DashboardPage.tsx, frontend/src/pages/ServiceRequestsPage.tsx.
• Building-map live updates: backend/app/routers/diagrams.py, backend/app/diagram_live.py, frontend/src/useDiagramLive.ts.
Local CORAX users authenticate via JWT cookies plus CSRF for unsafe browser operations; role boundaries are observer, editor, and admin.
Operations, Integrations, and External Services
Service requests connect users, computers, categories, templates, GLPI CSV exchange, and PDF output through backend/app/routers/service_requests.py and backend/app/service_request_tickets.py. Printer discovery/polling uses SNMP: backend/app/printer_scheduler.py, backend/app/printer_snmp.py.
Optional boundaries are LDAP directory synchronization (backend/app/ldap_auth.py), Bitrix24 webhooks/bot events (backend/app/routers/bitrix24_incoming.py), LibreOffice conversion/export for diagrams (backend/app/svg_export.py), and LM Studio’s local OpenAI-compatible endpoint for knowledge-base RAG (backend/app/wikirag_lm.py, backend/app/wikirag_corax.py).
Deployment Runtime
Material runtimes are Python 3.12+, Node 18+/20, PostgreSQL 14+/16, Windows PowerShell agents, and optionally LibreOffice/LM Studio. Linux production uses systemd units in deploy/corax-backend.service; Windows can use the provided batch launchers. PostgreSQL backups are implemented around backend/app/pg_backup.py.
Main entry points: __init__.py API domain routers · main.py Application lifecycle · models.py ORM and contracts · agent.py Inventory ingestion
Components 21
Endpoint agents
- PowerShell collection
agent/v3/win10/InventoryClient.ps1 - Authenticated upload
agent/v3/win10/lib/Invoke-Post.ps1
FastAPI backend
- Application lifecycle · Wires middleware, auth, migrations, routers, and production SPA serving.
backend/app/main.py - API domain routers · Serves versioned inventory, operations, and administration APIs.
backend/app/routers/__init__.py - ORM and contracts
backend/app/models.py - Async database access
backend/app/database.py - Schema evolution
backend/app/migrations.py - Inventory ingestion · Upserts computers by hostname and replaces current snapshots.
backend/app/routers/agent.py - Agent token administration · Issues, revokes, and hostname-binds hashed Bearer tokens.
backend/app/routers/agent_tokens.py - Agent bundle generator · Generates distributable endpoint agents.
backend/app/agent_bundle.py - Live building diagrams
backend/app/diagram_live.py - Service request workflow · Connects requests to templates, GLPI CSV exchange, and PDF output.
backend/app/service_request_tickets.py - Printer discovery and polling
backend/app/printer_scheduler.py
React SPA
- SPA entry and routing
frontend/src/main.tsx - Operational UI shell · Hosts inventory, dashboard, and service-request workflows.
frontend/src/pages/Layout.tsx - API client and auth · Uses JWT cookies and CSRF for unsafe browser operations.
frontend/src/api.ts
External services
- LDAP directory
backend/app/ldap_auth.py - Bitrix24
backend/app/routers/bitrix24_incoming.py - LM Studio · Optional OpenAI-compatible endpoint for WikiRAG.
backend/app/wikirag_lm.py
Other components
- Server entry
run.py - Inventory PostgreSQL · Main, diagrams, and warehouse URLs normally target this database.
Connections 22
- Server entry → Application lifecycle: starts
- Application lifecycle → Schema evolution: runs at startup
- Schema evolution → Inventory PostgreSQL: evolves schema
- Application lifecycle → API domain routers: mounts
- API domain routers → ORM and contracts: uses
- ORM and contracts → Async database access: persists through
- Async database access → Inventory PostgreSQL: asyncpg
- PowerShell collection → Authenticated upload: produces snapshot
- Authenticated upload → Inventory ingestion: Bearer JSON POST
- Agent token administration → Inventory ingestion: authorizes
- Inventory ingestion → ORM and contracts: updates inventory
- Agent bundle generator → PowerShell collection: distributes
- SPA entry and routing → Operational UI shell: renders
- Operational UI shell → API client and auth: uses
- API client and auth → API domain routers: versioned API calls
- Application lifecycle → SPA entry and routing: serves production build
- Live building diagrams → API domain routers: diagram updates
- Service request workflow → ORM and contracts: stores requests
- Printer discovery and polling → ORM and contracts: updates printers
- LDAP directory → Application lifecycle: optional directory auth
- Bitrix24 → API domain routers: webhook events
- API domain routers → LM Studio: WikiRAG queries