# opexdev/core architecture

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

- Interactive diagram: https://gitdiagram.com/opexdev/core
- Repository: https://github.com/opexdev/core

## Overview

OPEX Core is a Kotlin microservice cryptocurrency exchange and matching engine. A representative order path begins with a user request, is validated by the matching gateway against pair settings and accountant limits, and is submitted as an event; the tree also shows matching, accounting, market-query, wallet, identity, and pricing services. These are distinct product capabilities, not a verified end-to-end deployment sequence. The sampled order service establishes its immediate dependencies; connections among other services are marked unverified because their wiring was not shown.

Main entry points: [`matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`](https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt) (Order Validation), [`wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/TransferService.kt`](https://github.com/opexdev/core/blob/main/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/TransferService.kt) (Wallet Service), [`market/market-app/src/main/kotlin/co/nilin/opex/market/app/controller/UserDataController.kt`](https://github.com/opexdev/core/blob/main/market/market-app/src/main/kotlin/co/nilin/opex/market/app/controller/UserDataController.kt) (Market Queries), [`auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/LoginService.kt`](https://github.com/opexdev/core/blob/main/auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/LoginService.kt) (Authentication)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_trading["Trading and Matching"]
  node_order_controller["Order API<br/>[OrderController.kt]"]
  node_order_service["Order Validation<br/>[OrderService.kt]"]
  node_pair_settings["Pair Settings"]
  node_pair_config["Pair Configuration<br/>[OrderService.kt]"]
  node_order_events["Order Event Submitter<br/>[OrderService.kt]"]
  node_matching_engine["Matching Engine"]
end

subgraph group_accounting["Accounting"]
  node_accountant_api["Accountant Limits<br/>[OrderService.kt]"]
  node_accountant["Accounting Service<br/>[AccountantApp.kt]"]
  node_accounting_core["Trade and Financial Actions"]
  node_accounting_db[("Accounting Records")]
end

subgraph group_market["Market Data"]
  node_market_api["Market Queries"]
  node_market_handler["Market Query Handler"]
  node_user_handler["User Trade History"]
  node_market_db[("Market Records<br/>[TradeRepository.kt]")]
end

subgraph group_wallet["Wallet and Pricing"]
  node_wallet["Wallet Service<br/>[TransferService.kt]"]
  node_withdraw["Withdrawals<br/>[WithdrawService.kt]"]
  node_price["Price Management"]
end

subgraph group_identity["Identity and API"]
  node_auth["Authentication<br/>[LoginService.kt]"]
  node_sessions["Device Sessions"]
  node_api_storage["Storage API"]
  node_otp["One-Time Codes<br/>[OTPService.kt]"]
end

node_user(("Exchange User"))

node_user -.->|"submits order"| node_order_controller
node_order_controller -.->|"handles request"| node_order_service
node_order_service -->|"loads settings"| node_pair_settings
node_order_service -->|"loads pair config"| node_pair_config
node_order_service -->|"checks order limit"| node_accountant_api
node_order_service -->|"submits event"| node_order_events
node_order_events -.->|"routes order event"| node_matching_engine
node_accountant -.->|"runs accounting"| node_accounting_core
node_accounting_core -.->|"persists actions"| node_accounting_db
node_market_api -.->|"queries market"| node_market_handler
node_market_api -.->|"queries history"| node_user_handler
node_market_handler -->|"reads trades"| node_market_db
node_user_handler -->|"reads trades"| node_market_db
node_wallet -.->|"supports withdrawals"| node_withdraw
node_wallet -.->|"uses exchange rates"| node_price
node_auth -->|"uses session service"| node_sessions
node_auth -.->|"uses verification codes"| node_otp
node_api_storage -.->|"accesses wallet storage"| node_wallet

click node_order_controller "https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/controller/OrderController.kt"
click node_order_service "https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt"
click node_pair_settings "https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/service/PairSettingService.kt"
click node_pair_config "https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt"
click node_accountant_api "https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt"
click node_order_events "https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt"
click node_matching_engine "https://github.com/opexdev/core/blob/main/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/MatchingEngineEventListener.kt"
click node_accountant "https://github.com/opexdev/core/blob/main/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/AccountantApp.kt"
click node_accounting_core "https://github.com/opexdev/core/blob/main/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImpl.kt"
click node_accounting_db "https://github.com/opexdev/core/blob/main/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/FinancialActionPersisterImpl.kt"
click node_market_api "https://github.com/opexdev/core/blob/main/market/market-app/src/main/kotlin/co/nilin/opex/market/app/controller/UserDataController.kt"
click node_market_handler "https://github.com/opexdev/core/blob/main/market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/impl/MarketQueryHandlerImpl.kt"
click node_user_handler "https://github.com/opexdev/core/blob/main/market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/impl/UserQueryHandlerImpl.kt"
click node_market_db "https://github.com/opexdev/core/blob/main/market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/dao/TradeRepository.kt"
click node_wallet "https://github.com/opexdev/core/blob/main/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/TransferService.kt"
click node_withdraw "https://github.com/opexdev/core/blob/main/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt"
click node_price "https://github.com/opexdev/core/blob/main/price-management/price-management-core/src/main/kotlin/co/nilin/opex/price/core/service/CrossRateService.kt"
click node_auth "https://github.com/opexdev/core/blob/main/auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/LoginService.kt"
click node_sessions "https://github.com/opexdev/core/blob/main/device-management/device-management-core/src/main/kotlin/co/nilin/opex/device/core/service/UserSessionDeviceService.kt"
click node_api_storage "https://github.com/opexdev/core/blob/main/api/api-ports/api-opex-rest/src/main/kotlin/co/nilin/opex/api/ports/opex/controller/StorageController.kt"
click node_otp "https://github.com/opexdev/core/blob/main/otp/otp-app/src/main/kotlin/co/nilin/opex/otp/app/service/OTPService.kt"

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_order_controller,node_order_service,node_pair_settings,node_pair_config,node_order_events,node_matching_engine,node_user toneBlue
class node_accountant_api,node_accountant,node_accounting_core,node_accounting_db toneAmber
class node_market_api,node_market_handler,node_user_handler,node_market_db toneMint
class node_wallet,node_withdraw,node_price toneRose
class node_auth,node_sessions,node_api_storage,node_otp toneIndigo
```

## Components

### Trading and Matching

- [Order API](https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/controller/OrderController.kt): `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/controller/OrderController.kt`
- [Order Validation](https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt): `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`
- [Pair Settings](https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/service/PairSettingService.kt): `matching-gateway/matching-gateway-port/matching-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/matching/gateway/ports/postgres/service/PairSettingService.kt`
- [Pair Configuration](https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt): `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`
- [Order Event Submitter](https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt): `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`
- [Matching Engine](https://github.com/opexdev/core/blob/main/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/MatchingEngineEventListener.kt): `matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/listener/MatchingEngineEventListener.kt`

### Accounting

- [Accountant Limits](https://github.com/opexdev/core/blob/main/matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt): `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`
- [Accounting Service](https://github.com/opexdev/core/blob/main/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/AccountantApp.kt): `accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/AccountantApp.kt`
- [Trade and Financial Actions](https://github.com/opexdev/core/blob/main/accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImpl.kt): `accountant/accountant-core/src/main/kotlin/co/nilin/opex/accountant/core/service/TradeManagerImpl.kt`
- [Accounting Records](https://github.com/opexdev/core/blob/main/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/FinancialActionPersisterImpl.kt): `accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/impl/FinancialActionPersisterImpl.kt`

### Market Data

- [Market Queries](https://github.com/opexdev/core/blob/main/market/market-app/src/main/kotlin/co/nilin/opex/market/app/controller/UserDataController.kt): `market/market-app/src/main/kotlin/co/nilin/opex/market/app/controller/UserDataController.kt`
- [Market Query Handler](https://github.com/opexdev/core/blob/main/market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/impl/MarketQueryHandlerImpl.kt): `market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/impl/MarketQueryHandlerImpl.kt`
- [User Trade History](https://github.com/opexdev/core/blob/main/market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/impl/UserQueryHandlerImpl.kt): `market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/impl/UserQueryHandlerImpl.kt`
- [Market Records](https://github.com/opexdev/core/blob/main/market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/dao/TradeRepository.kt): `market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/dao/TradeRepository.kt`

### Wallet and Pricing

- [Wallet Service](https://github.com/opexdev/core/blob/main/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/TransferService.kt): `wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/TransferService.kt`
- [Withdrawals](https://github.com/opexdev/core/blob/main/wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt): `wallet/wallet-core/src/main/kotlin/co/nilin/opex/wallet/core/service/WithdrawService.kt`
- [Price Management](https://github.com/opexdev/core/blob/main/price-management/price-management-core/src/main/kotlin/co/nilin/opex/price/core/service/CrossRateService.kt): `price-management/price-management-core/src/main/kotlin/co/nilin/opex/price/core/service/CrossRateService.kt`

### Identity and API

- [Authentication](https://github.com/opexdev/core/blob/main/auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/LoginService.kt): `auth-gateway/auth-gateway-app/src/main/kotlin/co/nilin/opex/auth/service/LoginService.kt`
- [Device Sessions](https://github.com/opexdev/core/blob/main/device-management/device-management-core/src/main/kotlin/co/nilin/opex/device/core/service/UserSessionDeviceService.kt): `device-management/device-management-core/src/main/kotlin/co/nilin/opex/device/core/service/UserSessionDeviceService.kt`
- [Storage API](https://github.com/opexdev/core/blob/main/api/api-ports/api-opex-rest/src/main/kotlin/co/nilin/opex/api/ports/opex/controller/StorageController.kt): `api/api-ports/api-opex-rest/src/main/kotlin/co/nilin/opex/api/ports/opex/controller/StorageController.kt`
- [One-Time Codes](https://github.com/opexdev/core/blob/main/otp/otp-app/src/main/kotlin/co/nilin/opex/otp/app/service/OTPService.kt): `otp/otp-app/src/main/kotlin/co/nilin/opex/otp/app/service/OTPService.kt`

### Other components

- **Exchange User**

## Connections

- Exchange User → Order API: submits order
- Order API → Order Validation: handles request
- Order Validation → Pair Settings: loads settings (evidence: `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`)
- Order Validation → Pair Configuration: loads pair config (evidence: `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`)
- Order Validation → Accountant Limits: checks order limit (evidence: `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`)
- Order Validation → Order Event Submitter: submits event (evidence: `matching-gateway/matching-gateway-app/src/main/kotlin/co/nilin/opex/matching/gateway/app/service/OrderService.kt`)
- Order Event Submitter → Matching Engine: routes order event
- Accounting Service → Trade and Financial Actions: runs accounting
- Trade and Financial Actions → Accounting Records: persists actions
- Market Queries → Market Query Handler: queries market
- Market Queries → User Trade History: queries history
- Market Query Handler → Market Records: reads trades (evidence: `market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/impl/MarketQueryHandlerImpl.kt`)
- User Trade History → Market Records: reads trades (evidence: `market/market-ports/market-persister-postgres/src/main/kotlin/co/nilin/opex/market/ports/postgres/impl/UserQueryHandlerImpl.kt`)
- Wallet Service → Withdrawals: supports withdrawals
- Wallet Service → Price Management: uses exchange rates
- Authentication → Device Sessions: uses session service
- Authentication → One-Time Codes: uses verification codes
- Storage API → Wallet Service: accesses wallet storage
