# matthew-dz/dx-authengine architecture

> Architecture diagram of the GitHub repository matthew-dz/dx-authengine, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/matthew-dz/dx-authengine
- Repository: https://github.com/matthew-dz/dx-authengine

## Overview

DX-AuthEngine is a FastAPI business-operations and decision-support backend. Its main workflow authenticates staff, accepts refund requests, enforces refund-state transitions, records audit data, and exposes operational results; separate branches cover people, orders, analytics, and AI assistance. The README documents the H-P-D-I capabilities, while the source index and excerpts substantiate selected implementation links. Some README-described capabilities, such as role/policy administration and AI human-in-the-loop controls, are retained without speculative wiring where source evidence is limited.

Main entry points: [`app/main.py`](https://github.com/matthew-dz/dx-authengine/blob/main/app/main.py) (API application), [`app/services/refund_service.py`](https://github.com/matthew-dz/dx-authengine/blob/main/app/services/refund_service.py) (Refund workflow), [`app/api/v1/refunds.py`](https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/refunds.py) (Refund API), [`app/database.py`](https://github.com/matthew-dz/dx-authengine/blob/main/app/database.py) (Database sessions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_human["Identity and access"]
  node_auth_api["Authentication API<br/>[auth.py]"]
  node_security["JWT security<br/>[security.py]"]
  node_people_api["Users and employees<br/>[employees.py]"]
  node_user_api["User management<br/>[users.py]"]
  node_employee_schema["Employee schemas<br/>[employee.py]"]
end

subgraph group_process["Refund workflow"]
  node_app["API application<br/>[main.py]"]
  node_refund_api["Refund API<br/>[refunds.py]"]
  node_refund_service["Refund workflow<br/>[refund_service.py]"]
  node_event_bus["Event dispatch<br/>[event_bus.py]"]
  node_refund_handler["Refund event handler<br/>[refund_handler.py]"]
  node_email["Email notifications<br/>[email_service.py]"]
end

subgraph group_data["Business data"]
  node_audit[("Audit records<br/>[models.py]")]
  node_orders_api["Order API<br/>[orders.py]"]
  node_order_repo["Order access"]
  node_analytics_api["Analytics API<br/>[analytics.py]"]
  node_analytics_service["Analytics"]
  node_analytics_repo["Analytics queries"]
  node_models[("Business entities<br/>[models.py]")]
  node_database[("Database sessions<br/>[database.py]")]
  node_schemas["API schemas<br/>[__init__.py]"]
  node_common_schema["Response envelope<br/>[common.py]"]
end

subgraph group_intelligence["AI assistance"]
  node_ai_api["AI API<br/>[ai.py]"]
  node_ai_service["AI assistant<br/>[ai_service.py]"]
  node_ai_tools["Business data tools<br/>[ai_tools.py]"]
  node_ai_data["AI data access<br/>[ai_data_service.py]"]
  node_rag["RAG retrieval<br/>[rag_service.py]"]
  node_knowledge["Knowledge base"]
  node_agent["Refund content assistant<br/>[agent.py]"]
  node_ai_schema["AI schemas<br/>[schemas_ai.py]"]
end

node_staff(("Staff user"))

node_staff -->|"uses API"| node_app
node_app -->|"registers route"| node_auth_api
node_app -->|"registers route"| node_people_api
node_app -->|"registers route"| node_user_api
node_app -->|"registers route"| node_refund_api
node_app -->|"registers route"| node_orders_api
node_app -->|"registers route"| node_analytics_api
node_app -->|"registers route"| node_ai_api
node_auth_api -->|"uses authentication"| node_security
node_people_api -->|"checks identity"| node_security
node_user_api -->|"checks identity"| node_security
node_refund_api -->|"checks identity"| node_security
node_refund_api -->|"delegates workflow"| node_refund_service
node_refund_service -->|"updates entities"| node_models
node_refund_service -->|"commits changes"| node_database
node_refund_service -->|"publishes event"| node_event_bus
node_event_bus -->|"dispatches event"| node_refund_handler
node_refund_handler -->|"sends notification"| node_email
node_refund_service -->|"writes audit log"| node_audit
node_refund_service -->|"generates content"| node_agent
node_orders_api -->|"queries orders"| node_models
node_order_repo -->|"reads and writes"| node_database
node_analytics_api -->|"delegates analysis"| node_analytics_service
node_analytics_repo -->|"queries metrics"| node_database
node_ai_api -->|"delegates assistant"| node_ai_service
node_ai_service -->|"retrieves knowledge"| node_rag
node_ai_service -->|"uses business tools"| node_ai_tools
node_ai_tools -->|"requests data"| node_ai_data
node_ai_tools -->|"invokes workflow"| node_refund_service
node_rag -->|"loads knowledge"| node_knowledge
node_ai_api -->|"validates payloads"| node_ai_schema
node_refund_api -->|"validates requests"| node_schemas
node_schemas -->|"uses envelope"| node_common_schema
node_auth_api -->|"uses employee schemas"| node_employee_schema
node_database -->|"maps entities"| node_models

click node_app "https://github.com/matthew-dz/dx-authengine/blob/main/app/main.py"
click node_auth_api "https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/auth.py"
click node_security "https://github.com/matthew-dz/dx-authengine/blob/main/app/security.py"
click node_people_api "https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/employees.py"
click node_user_api "https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/users.py"
click node_refund_api "https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/refunds.py"
click node_refund_service "https://github.com/matthew-dz/dx-authengine/blob/main/app/services/refund_service.py"
click node_event_bus "https://github.com/matthew-dz/dx-authengine/blob/main/app/events/event_bus.py"
click node_refund_handler "https://github.com/matthew-dz/dx-authengine/blob/main/app/events/handlers/refund_handler.py"
click node_email "https://github.com/matthew-dz/dx-authengine/blob/main/app/email_service.py"
click node_audit "https://github.com/matthew-dz/dx-authengine/blob/main/app/models.py"
click node_orders_api "https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/orders.py"
click node_order_repo "https://github.com/matthew-dz/dx-authengine/blob/main/app/repositories/order_repository.py"
click node_analytics_api "https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/analytics.py"
click node_analytics_service "https://github.com/matthew-dz/dx-authengine/blob/main/app/services/analytics_service.py"
click node_analytics_repo "https://github.com/matthew-dz/dx-authengine/blob/main/app/repositories/analytics_repository.py"
click node_models "https://github.com/matthew-dz/dx-authengine/blob/main/app/models.py"
click node_database "https://github.com/matthew-dz/dx-authengine/blob/main/app/database.py"
click node_ai_api "https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/ai.py"
click node_ai_service "https://github.com/matthew-dz/dx-authengine/blob/main/app/services/ai_service.py"
click node_ai_tools "https://github.com/matthew-dz/dx-authengine/blob/main/app/services/ai_tools.py"
click node_ai_data "https://github.com/matthew-dz/dx-authengine/blob/main/app/services/ai_data_service.py"
click node_rag "https://github.com/matthew-dz/dx-authengine/blob/main/app/services/rag_service.py"
click node_knowledge "https://github.com/matthew-dz/dx-authengine/blob/main/app/services/knowledge_service.py"
click node_agent "https://github.com/matthew-dz/dx-authengine/blob/main/app/agent.py"
click node_schemas "https://github.com/matthew-dz/dx-authengine/blob/main/app/schemas/__init__.py"
click node_common_schema "https://github.com/matthew-dz/dx-authengine/blob/main/app/schemas/common.py"
click node_employee_schema "https://github.com/matthew-dz/dx-authengine/blob/main/app/schemas/employee.py"
click node_ai_schema "https://github.com/matthew-dz/dx-authengine/blob/main/app/schemas_ai.py"

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_auth_api,node_security,node_people_api,node_user_api,node_employee_schema,node_staff toneBlue
class node_app,node_refund_api,node_refund_service,node_event_bus,node_refund_handler,node_email toneAmber
class node_audit,node_orders_api,node_order_repo,node_analytics_api,node_analytics_service,node_analytics_repo,node_models,node_database,node_schemas,node_common_schema toneMint
class node_ai_api,node_ai_service,node_ai_tools,node_ai_data,node_rag,node_knowledge,node_agent,node_ai_schema toneRose
```

## Components

### Identity and access

- [Authentication API](https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/auth.py): `app/api/v1/auth.py`
- [JWT security](https://github.com/matthew-dz/dx-authengine/blob/main/app/security.py): `app/security.py`
- [Users and employees](https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/employees.py): `app/api/v1/employees.py`
- [User management](https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/users.py): `app/api/v1/users.py`
- [Employee schemas](https://github.com/matthew-dz/dx-authengine/blob/main/app/schemas/employee.py): `app/schemas/employee.py`

### Refund workflow

- [API application](https://github.com/matthew-dz/dx-authengine/blob/main/app/main.py): `app/main.py`
- [Refund API](https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/refunds.py): `app/api/v1/refunds.py`
- [Refund workflow](https://github.com/matthew-dz/dx-authengine/blob/main/app/services/refund_service.py): `app/services/refund_service.py`
- [Event dispatch](https://github.com/matthew-dz/dx-authengine/blob/main/app/events/event_bus.py): `app/events/event_bus.py`
- [Refund event handler](https://github.com/matthew-dz/dx-authengine/blob/main/app/events/handlers/refund_handler.py): `app/events/handlers/refund_handler.py`
- [Email notifications](https://github.com/matthew-dz/dx-authengine/blob/main/app/email_service.py): `app/email_service.py`

### Business data

- [Audit records](https://github.com/matthew-dz/dx-authengine/blob/main/app/models.py): `app/models.py`
- [Order API](https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/orders.py): `app/api/v1/orders.py`
- [Order access](https://github.com/matthew-dz/dx-authengine/blob/main/app/repositories/order_repository.py): `app/repositories/order_repository.py`
- [Analytics API](https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/analytics.py): `app/api/v1/analytics.py`
- [Analytics](https://github.com/matthew-dz/dx-authengine/blob/main/app/services/analytics_service.py): `app/services/analytics_service.py`
- [Analytics queries](https://github.com/matthew-dz/dx-authengine/blob/main/app/repositories/analytics_repository.py): `app/repositories/analytics_repository.py`
- [Business entities](https://github.com/matthew-dz/dx-authengine/blob/main/app/models.py): `app/models.py`
- [Database sessions](https://github.com/matthew-dz/dx-authengine/blob/main/app/database.py): `app/database.py`
- [API schemas](https://github.com/matthew-dz/dx-authengine/blob/main/app/schemas/__init__.py): `app/schemas/__init__.py`
- [Response envelope](https://github.com/matthew-dz/dx-authengine/blob/main/app/schemas/common.py): `app/schemas/common.py`

### AI assistance

- [AI API](https://github.com/matthew-dz/dx-authengine/blob/main/app/api/v1/ai.py): `app/api/v1/ai.py`
- [AI assistant](https://github.com/matthew-dz/dx-authengine/blob/main/app/services/ai_service.py): `app/services/ai_service.py`
- [Business data tools](https://github.com/matthew-dz/dx-authengine/blob/main/app/services/ai_tools.py): `app/services/ai_tools.py`
- [AI data access](https://github.com/matthew-dz/dx-authengine/blob/main/app/services/ai_data_service.py): `app/services/ai_data_service.py`
- [RAG retrieval](https://github.com/matthew-dz/dx-authengine/blob/main/app/services/rag_service.py): `app/services/rag_service.py`
- [Knowledge base](https://github.com/matthew-dz/dx-authengine/blob/main/app/services/knowledge_service.py): `app/services/knowledge_service.py`
- [Refund content assistant](https://github.com/matthew-dz/dx-authengine/blob/main/app/agent.py): `app/agent.py`
- [AI schemas](https://github.com/matthew-dz/dx-authengine/blob/main/app/schemas_ai.py): `app/schemas_ai.py`

### Other components

- **Staff user**

## Connections

- Staff user → API application: uses API (evidence: `README.md`)
- API application → Authentication API: registers route (evidence: `app/main.py`)
- API application → Users and employees: registers route (evidence: `app/main.py`)
- API application → User management: registers route (evidence: `app/main.py`)
- API application → Refund API: registers route (evidence: `app/main.py`)
- API application → Order API: registers route (evidence: `app/main.py`)
- API application → Analytics API: registers route (evidence: `app/main.py`)
- API application → AI API: registers route (evidence: `app/main.py`)
- Authentication API → JWT security: uses authentication (evidence: `app/api/v1/auth.py`)
- Users and employees → JWT security: checks identity (evidence: `app/api/v1/employees.py`)
- User management → JWT security: checks identity (evidence: `app/api/v1/users.py`)
- Refund API → JWT security: checks identity (evidence: `app/api/v1/refunds.py`)
- Refund API → Refund workflow: delegates workflow (evidence: `app/api/v1/refunds.py`)
- Refund workflow → Business entities: updates entities (evidence: `app/services/refund_service.py`)
- Refund workflow → Database sessions: commits changes (evidence: `app/services/refund_service.py`)
- Refund workflow → Event dispatch: publishes event (evidence: `app/services/refund_service.py`)
- Event dispatch → Refund event handler: dispatches event (evidence: `app/events/event_bus.py`)
- Refund event handler → Email notifications: sends notification (evidence: `app/events/handlers/refund_handler.py`)
- Refund workflow → Audit records: writes audit log (evidence: `app/services/refund_service.py`)
- Refund workflow → Refund content assistant: generates content (evidence: `app/services/refund_service.py`)
- Order API → Business entities: queries orders (evidence: `app/api/v1/orders.py`)
- Order access → Database sessions: reads and writes (evidence: `app/repositories/order_repository.py`)
- Analytics API → Analytics: delegates analysis (evidence: `app/api/v1/analytics.py`)
- Analytics queries → Database sessions: queries metrics (evidence: `app/repositories/analytics_repository.py`)
- AI API → AI assistant: delegates assistant (evidence: `app/api/v1/ai.py`)
- AI assistant → RAG retrieval: retrieves knowledge (evidence: `app/services/ai_service.py`)
- AI assistant → Business data tools: uses business tools (evidence: `app/services/ai_service.py`)
- Business data tools → AI data access: requests data (evidence: `app/services/ai_tools.py`)
- Business data tools → Refund workflow: invokes workflow (evidence: `app/services/ai_tools.py`)
- RAG retrieval → Knowledge base: loads knowledge (evidence: `app/services/rag_service.py`)
- AI API → AI schemas: validates payloads (evidence: `app/api/v1/ai.py`)
- Refund API → API schemas: validates requests (evidence: `app/api/v1/refunds.py`)
- API schemas → Response envelope: uses envelope (evidence: `app/schemas/__init__.py`)
- Authentication API → Employee schemas: uses employee schemas (evidence: `app/api/v1/auth.py`)
- Database sessions → Business entities: maps entities (evidence: `app/models.py`)
