How brenoimatos/credit-decision works
Purpose and deployable entry points
Credit Decision Engine lets users author a graph-based credit policy and expose its boolean evaluation as an API. It is split into three deployables: React configuration UI (frontend-config/src/index.js, frontend-config/src/App.js), policy-config FastAPI service (backend-config/app/main.py), and execution FastAPI service (execution-engine/app/main.py). docker-compose.yml orchestrates them; MongoDB is an external PolicyDB.
Policy authoring UI
The configuration frontend renders and edits a flowchart policy: canvas/interaction logic is concentrated in frontend-config/src/Flow.js, with shell-level integration in frontend-config/src/App.js. Custom graph node types define start, conditional decision, and terminal boolean nodes in frontend-config/src/components/CustomNodes/DecisionNode.js, frontend-config/src/components/CustomNodes/StartNode.js, and frontend-config/src/components/CustomNodes/EndNode.js. The UI validates/configures nodes and connections before persisting the graph.
Policy configuration API and persistence
backend-config/app/controllers/policy_controller.py exposes the policy read/update boundary. Requests pass through policy-domain validation/models in backend-config/app/models/policy_model.py, orchestration in backend-config/app/services/policy_service.py, and MongoDB access in backend-config/app/dal/policy_dal.py. This service intentionally manages a single policy type/instance rather than general policy CRUD. Dependency assembly and runtime settings live in backend-config/app/deps/dependencies.py and backend-config/app/utils/settings.py.
Frontend-to-policy flow
The browser loads the existing policy and PATCHes edited graph data through frontend-config/src/api/policy.js. The config API persists the node/edge-oriented representation in MongoDB. This is the authoring boundary: frontend graph semantics and editable configuration remain separate from runtime decision evaluation.
Execution API and remote policy retrieval
The execution service accepts arbitrary customer attributes using execution-engine/app/controllers/execution_controller.py and execution-engine/app/models/customer_model.py. Rather than accessing MongoDB directly, it obtains the current policy from ConfigBackend through execution-engine/app/dal/policy_remote_dal.py. This establishes ConfigBackend as the policy source of truth and keeps execution decoupled from the persistence implementation.
Decision transformation and evaluation
execution-engine/app/services/execution_service.py transforms the stored nodes/connections into a decision tree, traverses it against input attributes, applies configured comparison operators and values, and returns {decision: boolean}. The transformation occurs per execution request, so each evaluation reflects the latest fetched policy but places graph-to-tree work on the request path.
Runtime and infrastructure boundaries
Both backend services are Python/FastAPI containers (backend-config/Dockerfile, execution-engine/Dockerfile) with Pydantic-backed request modeling implied by their FastAPI structure. The UI is a React container (frontend-config/Dockerfile). Service URLs, ports, database connection, and related environment configuration are supplied through per-service .env files modeled by backend-config/.env.example, execution-engine/.env.example, and frontend-config/.env.example. MongoDB/Atlas is required externally rather than provisioned in the repository.
Main entry points: policy_controller.py Policy read/update API · docker-compose.yml Container orchestration · Flow.js Policy graph editor · execution_controller.py Decision API
Components 16
Policy Authoring UI
- React app shell
frontend-config/src/App.js - Policy graph editor · Edits and validates policy nodes and connections.
frontend-config/src/Flow.js - Policy node types · Start, conditional decision, and terminal boolean nodes.
frontend-config/src/components/CustomNodes/DecisionNode.js - Policy API client
frontend-config/src/api/policy.js
Configuration Service
- Config FastAPI app
backend-config/app/main.py - Policy read/update API
backend-config/app/controllers/policy_controller.py - Policy validation model
backend-config/app/models/policy_model.py - Single-policy service · Orchestrates the repository's single policy instance.
backend-config/app/services/policy_service.py - Mongo policy repository
backend-config/app/dal/policy_dal.py
Execution Service
- Execution FastAPI app
execution-engine/app/main.py - Decision API
execution-engine/app/controllers/execution_controller.py - Customer attributes model
execution-engine/app/models/customer_model.py - Policy evaluator · Builds a decision tree and evaluates it per request.
execution-engine/app/services/execution_service.py - Remote policy client · Fetches the current policy from ConfigBackend.
execution-engine/app/dal/policy_remote_dal.py
Other components
- PolicyDB · External MongoDB or Atlas policy store.
- Container orchestration · Runs the three deployable services.
docker-compose.yml
Connections 17
- React app shell → Policy graph editor: hosts editor
- Policy graph editor → Policy node types: renders
- Policy graph editor → Policy API client: loads and saves graph
- Policy API client → Policy read/update API: GET / PATCH policy
- Config FastAPI app → Policy read/update API: routes
- Policy read/update API → Policy validation model: validates
- Policy read/update API → Single-policy service: delegates
- Single-policy service → Mongo policy repository: persists graph
- Mongo policy repository → PolicyDB: reads and writes
- Execution FastAPI app → Decision API: routes
- Decision API → Customer attributes model: validates input
- Decision API → Policy evaluator: evaluates
- Policy evaluator → Remote policy client: fetches current policy
- Remote policy client → Policy read/update API: retrieves policy remotely
- Container orchestration → React app shell: runs
- Container orchestration → Config FastAPI app: runs
- Container orchestration → Execution FastAPI app: runs