# brenoimatos/credit-decision architecture

> Architecture diagram of the GitHub repository brenoimatos/credit-decision, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/brenoimatos/credit-decision
- Repository: https://github.com/brenoimatos/credit-decision

## Overview

#### 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: [`backend-config/app/controllers/policy_controller.py`](https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/controllers/policy_controller.py) (Policy read/update API), [`docker-compose.yml`](https://github.com/brenoimatos/credit-decision/blob/main/docker-compose.yml) (Container orchestration), [`frontend-config/src/Flow.js`](https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/Flow.js) (Policy graph editor), [`execution-engine/app/controllers/execution_controller.py`](https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/controllers/execution_controller.py) (Decision API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Policy Authoring UI"]
  node_ui_app["React app shell<br/>React entry<br/>[App.js]"]
  node_policy_canvas["Policy graph editor<br/>flow editor<br/>[Flow.js]"]
  node_custom_nodes["Policy node types<br/>React nodes<br/>[DecisionNode.js]"]
  node_policy_client["Policy API client<br/>browser API<br/>[policy.js]"]
end

subgraph group_config["Configuration Service"]
  node_config_api["Config FastAPI app<br/>API entry<br/>[main.py]"]
  node_policy_controller["Policy read/update API<br/>controller"]
  node_policy_models["Policy validation model<br/>domain model<br/>[policy_model.py]"]
  node_policy_service["Single-policy service<br/>[policy_service.py]"]
  node_policy_dal["Mongo policy repository<br/>data access<br/>[policy_dal.py]"]
end

subgraph group_execution["Execution Service"]
  node_execution_api["Execution FastAPI app<br/>API entry<br/>[main.py]"]
  node_execution_controller["Decision API<br/>controller"]
  node_customer_model["Customer attributes model<br/>request model<br/>[customer_model.py]"]
  node_execution_service["Policy evaluator<br/>decision service"]
  node_remote_policy_dal["Remote policy client<br/>data access"]
end

node_policy_db[("PolicyDB<br/>external MongoDB")]
node_compose{{"Container orchestration<br/>Docker Compose<br/>[docker-compose.yml]"}}

node_ui_app -->|"hosts editor"| node_policy_canvas
node_policy_canvas -->|"renders"| node_custom_nodes
node_policy_canvas -->|"loads and saves graph"| node_policy_client
node_policy_client -->|"GET / PATCH policy"| node_policy_controller
node_config_api -->|"routes"| node_policy_controller
node_policy_controller -->|"validates"| node_policy_models
node_policy_controller -->|"delegates"| node_policy_service
node_policy_service -->|"persists graph"| node_policy_dal
node_policy_dal -->|"reads and writes"| node_policy_db
node_execution_api -->|"routes"| node_execution_controller
node_execution_controller -->|"validates input"| node_customer_model
node_execution_controller -->|"evaluates"| node_execution_service
node_execution_service -->|"fetches current policy"| node_remote_policy_dal
node_remote_policy_dal -->|"retrieves policy remotely"| node_policy_controller
node_compose -.->|"runs"| node_ui_app
node_compose -.->|"runs"| node_config_api
node_compose -.->|"runs"| node_execution_api

click node_ui_app "https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/App.js"
click node_policy_canvas "https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/Flow.js"
click node_custom_nodes "https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/components/CustomNodes/DecisionNode.js"
click node_policy_client "https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/api/policy.js"
click node_config_api "https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/main.py"
click node_policy_controller "https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/controllers/policy_controller.py"
click node_policy_models "https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/models/policy_model.py"
click node_policy_service "https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/services/policy_service.py"
click node_policy_dal "https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/dal/policy_dal.py"
click node_execution_api "https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/main.py"
click node_execution_controller "https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/controllers/execution_controller.py"
click node_customer_model "https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/models/customer_model.py"
click node_execution_service "https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/services/execution_service.py"
click node_remote_policy_dal "https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/dal/policy_remote_dal.py"
click node_compose "https://github.com/brenoimatos/credit-decision/blob/main/docker-compose.yml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_ui_app,node_policy_canvas,node_custom_nodes,node_policy_client toneBlue
class node_config_api,node_policy_controller,node_policy_models,node_policy_service,node_policy_dal toneAmber
class node_execution_api,node_execution_controller,node_customer_model,node_execution_service,node_remote_policy_dal toneMint
class node_policy_db,node_compose toneNeutral
```

## Components

### Policy Authoring UI

- [React app shell](https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/App.js): React entry · `frontend-config/src/App.js`
- [Policy graph editor](https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/Flow.js): flow editor · Edits and validates policy nodes and connections. · `frontend-config/src/Flow.js`
- [Policy node types](https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/components/CustomNodes/DecisionNode.js): React nodes · Start, conditional decision, and terminal boolean nodes. · `frontend-config/src/components/CustomNodes/DecisionNode.js`
- [Policy API client](https://github.com/brenoimatos/credit-decision/blob/main/frontend-config/src/api/policy.js): browser API · `frontend-config/src/api/policy.js`

### Configuration Service

- [Config FastAPI app](https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/main.py): API entry · `backend-config/app/main.py`
- [Policy read/update API](https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/controllers/policy_controller.py): controller · `backend-config/app/controllers/policy_controller.py`
- [Policy validation model](https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/models/policy_model.py): domain model · `backend-config/app/models/policy_model.py`
- [Single-policy service](https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/services/policy_service.py): service · Orchestrates the repository's single policy instance. · `backend-config/app/services/policy_service.py`
- [Mongo policy repository](https://github.com/brenoimatos/credit-decision/blob/main/backend-config/app/dal/policy_dal.py): data access · `backend-config/app/dal/policy_dal.py`

### Execution Service

- [Execution FastAPI app](https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/main.py): API entry · `execution-engine/app/main.py`
- [Decision API](https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/controllers/execution_controller.py): controller · `execution-engine/app/controllers/execution_controller.py`
- [Customer attributes model](https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/models/customer_model.py): request model · `execution-engine/app/models/customer_model.py`
- [Policy evaluator](https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/services/execution_service.py): decision service · Builds a decision tree and evaluates it per request. · `execution-engine/app/services/execution_service.py`
- [Remote policy client](https://github.com/brenoimatos/credit-decision/blob/main/execution-engine/app/dal/policy_remote_dal.py): data access · Fetches the current policy from ConfigBackend. · `execution-engine/app/dal/policy_remote_dal.py`

### Other components

- **PolicyDB**: external MongoDB · External MongoDB or Atlas policy store.
- [Container orchestration](https://github.com/brenoimatos/credit-decision/blob/main/docker-compose.yml): Docker Compose · Runs the three deployable services. · `docker-compose.yml`

## Connections

- 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
