How ammar8065/clearpath-global works
1. System shape
- This is a single-process FastAPI application with a static JavaScript frontend bundled in the same repo.
- The backend exposes both REST APIs and the root HTML page; the browser app drives most user interaction.
2. Core architecture layers
- The backend is split into routes/ → services/ → models/ / engine/.
- schemas/ define request/response contracts, models/ map to the database, and services/ coordinate business logic before calling the rules engine.
3. Persistence boundary
- Data is stored in SQLite by default in risk_intelligence.db, with SQLAlchemy as the ORM.
- Alembic manages schema evolution; migrations live in alembic/versions/.
- This repository is designed to support a later database swap via DATABASE_URL, but the current architecture is local-first.
4. Domain model
- The main persisted entities are tenant, knowledge_source, and rule.
- client and asset models exist as legacy data types, along with residency_history, but the current privacy-first mode prevents normal persistence of client financial facts.
- Rules are versioned and time-bounded, with section_reference support for mapping logic back to source material.
5. Rules/evaluation engine
- The evaluation subsystem is separated into engine/conditions.py, selector.py, scorer.py, and report.py.
- The likely flow is: choose applicable rule versions, evaluate rule conditions against submitted client data, compute weighted scoring, then assemble a structured report with citations and warnings.
- This separation is important: selection, scoring, and report assembly are distinct internal stages rather than one monolithic evaluator.
6. Private assessment flow
- The main product flow is stateless evaluation through /evaluate/private and /evaluate/private/preview.
- The browser sends a flat client_data payload plus optional assessment metadata; the server evaluates it in memory and returns results without persisting the client payload.
- This makes the evaluation path the main boundary between ephemeral client facts and durable workspace/rule/source data.
7. API surface
- Functional API groups map to the domain: /tenants, /sources, /rules, and evaluation endpoints.
- /evaluate/rules/{rule_code}/versions supports rule history inspection for the UI.
- /clients and /assets still exist but are effectively disabled in privacy mode, returning 403 to steer users to the stateless workflow.
8. Frontend architecture
- The frontend is a modular vanilla JavaScript app under frontend/, not a framework SPA.
- app.js, navigation.js, dashboard.js, rules.js, sources.js, tenants.js, and the evaluation_* files partition the UI by workflow.
- The private assessment UI includes guided form entry, a live readiness/completeness panel, and optional advanced JSON editing.
9. User-facing data flow
- The typical loop is: manage tenants/sources/rules, then run a private assessment, inspect the generated risk report, and optionally export/import locally in the browser.
- Repeatability is handled client-side through local JSON export/import rather than server-side storage of assessment payloads.
10. Privacy boundary
- PRIVACY_MODE is the key architectural switch.
- When enabled, the platform keeps operational metadata like tenants, rules, and knowledge sources, but blocks persistent storage of client financial data and evaluation results.
- This is the main security/privacy boundary in the repository and materially changes how the API behaves.
11. Operational tooling
- seed_data.py supports local bootstrapping.
- app/database/init_db.py and AUTO_CREATE_SCHEMA exist as dev convenience, but the intended migration path is Alembic-first.
- The included .edge-headless/ and test artifacts suggest local browser-based or headless validation during development.
12. Testing strategy
- tests/ contains evaluator unit tests, regression tests, and live HTTP integration tests against a temporary migrated database.
- That mix reflects the architecture: business logic is testable in isolation, while route behavior and migration compatibility are validated end-to-end.
Main entry points: engine Rules engine · routes API routes · services Services · tests Tests
Components 19
Backend
FastAPI app, API layers, domain logic, and persistence
- FastAPI app · App startup, routing, and static page delivery
app/main.py - API routes · REST endpoints for tenants, sources, rules, clients, assets, and evaluation
app/routes - Services · Coordinates API requests, persistence, and engine calls
app/services - Evaluation svc · Runs stateless private assessments and assembles evaluation results
app/services/evaluation.py - Domain svcs · CRUD and domain operations for tenants, sources, rules, clients, and assets
app/services - Rules engine · Selection, condition checking, scoring, and report assembly
app/engine - Selector · Chooses applicable rule versions for an assessment
app/engine/selector.py - Conditions · Evaluates rule conditions against submitted client data
app/engine/conditions.py - Scorer · Computes weighted scores and intermediate outcomes
app/engine/scorer.py - Report · Builds structured results with citations and warnings
app/engine/report.py - Schemas · Request and response contracts for API boundaries
app/schemas - Models · SQLAlchemy entities for tenants, sources, rules, clients, assets, and residency history
app/models
Frontend
Static browser app for navigation, data entry, and evaluation workflows
- Browser app · Static frontend shell and workflow navigation
frontend/app.js - Admin views · Dashboard, tenants, sources, rules, and asset/client screens
frontend - Assessment UI · Private assessment forms, readiness panel, JSON editing, and report views
frontend/evaluation.js
Data
Database schema, migrations, and local bootstrap
- DB session · Database session and declarative base wiring
app/database - Alembic · Schema evolution and versioned migrations
alembic - Bootstrap · Initial local data seeding and schema convenience helpers
seed_data.py
Quality
Tests and validation coverage
- Tests · Evaluator unit tests, regressions, and live HTTP integration tests
tests
Connections 22
- FastAPI app → API routes: mounts · Registers API routes and serves the browser app
- FastAPI app → Browser app: serves · Delivers the static frontend entrypoints
- API routes → Services: calls · Routes delegate work to services
- Services → Domain svcs: delegates · CRUD and domain workflows flow through entity services
- Services → Evaluation svc: delegates · Evaluation endpoints use the stateless assessment service
- Evaluation svc → Rules engine: runs · Assessment service invokes the rules engine pipeline
- Rules engine → Selector: stage · Selects applicable rule versions first
- Rules engine → Conditions: stage · Checks submitted facts against rule conditions
- Rules engine → Scorer: stage · Computes weighted scores and outcomes
- Rules engine → Report: stage · Assembles the final structured report
- API routes → Schemas: validates · Endpoints exchange typed request and response payloads
- Services → Models: persists · Services load and write domain records through ORM models
- Models → DB session: uses · Models are bound to the SQLAlchemy database layer
- DB session → Alembic: evolves via · Alembic manages schema changes and version history
- Bootstrap → DB session: initializes · Local bootstrap helpers create or seed the database
- Browser app → Admin views: loads · Navigation exposes the administrative workflows
- Browser app → Assessment UI: loads · Private assessment workflow is a main user path
- Assessment UI → API routes: submits · Browser assessment forms call the evaluation endpoints
- Admin views → API routes: manages · Admin screens manage tenants, sources, rules, clients, and assets
- Tests → Rules engine: verifies · Unit tests cover evaluator behavior
- Tests → API routes: verifies · HTTP integration tests exercise route behavior
- Tests → Alembic: verifies · Integration coverage checks migrated database compatibility