How devfullcycle/imersao21 works
1. This repository is a 3-part home broker system:
- a Go trading/matching engine,
- a NestJS API layer,
- a Next.js frontend.
The architecture is split by responsibility: domain matching in Go, orchestration and I/O in NestJS, and user interaction in the browser.
2. The Go service is the core market engine. Its entrypoint is go/cmd/trade/main.go, and its domain package under go/internal/market models the trading book and matching logic with asset, book, order, investor, transaction, and order_processor. This is the component that appears to decide how orders are matched and how trades are produced.
3. Kafka is the main asynchronous boundary between the API and the Go engine. In Go, internal/infra/kafka/consumer.go and producer.go wrap broker communication. In NestJS, src/kafka/confluent-kafka-server.ts and confluent-kafka-context.ts implement the Kafka transport layer, and src/orders/orders.consumer.ts shows the API also consumes broker events.
4. The NestJS application is the system’s application/API layer. It is organized into feature modules for assets, orders, and wallets, each with controllers, services, DTOs, entities, and presenters. This is the layer that exposes HTTP endpoints and coordinates data flow between the UI, Kafka, and the domain services.
5. Within NestJS, orders is the most integration-heavy module. It has controllers, gateways, a consumer, DTOs for creating orders and trades, and entity classes for orders and trades. This suggests the order lifecycle is partially synchronous through HTTP and partially event-driven through Kafka and websockets.
6. The assets module handles market instruments and their time-series data. It includes an asset-dailies controller/service pair, a gateway, and presenter/entity classes for assets and daily price records. This indicates asset quotes and chart data are separate from order execution.
7. The wallets module represents user holdings. Its entities include a wallet and wallet-asset association, which is the persistence boundary for portfolio state. In the UI, wallet holdings are displayed as a dedicated list, so wallet updates are a first-class part of the user experience.
8. Real-time updates are delivered through websocket-style gateways. NestJS has assets.gateway.ts and orders.gateway.ts, while the frontend has socket-io.ts. This means the UI is not purely polling the API; it subscribes to live updates for prices, orders, and trade status.
9. The Next.js frontend is the presentation layer. Routes under src/app cover the home page, assets list, asset detail pages, and orders. Components like OrderForm, WalletList, ChartComponent, and AssetShow compose the screens, while queries/queries.tsx and store.ts support data access and client state.
10. The frontend is designed around market visualization and trading actions. It renders asset tables, asset charts, current prices, order status/type badges, and wallet balances. This is the user-facing boundary where market data, order submission, and execution feedback come together.
11. Data flow, at a high level, is:
user action in Next.js → NestJS HTTP/API or websocket layer → Kafka eventing → Go matching engine → trade/order results back through Kafka → NestJS updates domain state and pushes live updates to the frontend.
12. The repo also includes operational scaffolding. Each subproject has its own docker-compose.yaml or Docker-related files, and the root README explicitly mentions an “all-in-docker” branch. The presence of a MongoDB Docker setup inside nestjs-api/.docker/mongodb suggests persistence for the API-side domain data is containerized as part of the deployment story.
13. Technically, this is a polyglot system: Go for the trading engine, TypeScript/NestJS for backend orchestration, and TypeScript/React/Next.js for the UI. The architectural diagram should therefore show clear service boundaries rather than a single monolith, with Kafka and websockets as the main integration channels.
Main entry points: orders Orders module · app.module.ts App module · market Market core · assets Assets module
Components 26
Go engine
Trading and matching core
- Trade entry · Starts the trading engine process
go/cmd/trade/main.go - Market core · Order book and matching domain
go/internal/market - Order book · Tracks bids, asks, and match state
go/internal/market/entity/book.go - Order model · Represents incoming and resting orders
go/internal/market/entity/order.go - Matcher · Applies matching rules and produces trades
go/internal/market/entity/order_processor.go - Trade record · Produced trade and settlement data
go/internal/market/entity/transaction.go - Kafka adapter · Consumes and publishes broker events
go/internal/infra/kafka
NestJS API
Application layer and integrations
- API entry · Starts the API application
nestjs-api/src/main.ts - App module · Composes the application modules
nestjs-api/src/app.module.ts - Kafka transport · Custom Kafka server and context
nestjs-api/src/kafka - Orders module · Order lifecycle, events, and live updates
nestjs-api/src/orders - Assets module · Instruments, dailies, and market views
nestjs-api/src/assets - Wallets module · Portfolio holdings and balances
nestjs-api/src/wallets - Order consumer · Consumes broker events from Kafka
nestjs-api/src/orders/orders.consumer.ts - Orders gateway · Pushes order status updates to clients
nestjs-api/src/orders/orders.gateway.ts - Assets gateway · Pushes asset and price updates to clients
nestjs-api/src/assets/assets.gateway.ts
Next.js UI
Browser presentation and interaction
- Home view · Landing page and navigation entry
next-frontend/src/app/page.tsx - Assets view · Lists assets and opens asset detail pages
next-frontend/src/app/assets/page.tsx - Asset detail · Shows chart and current asset price
next-frontend/src/app/assets/[assetSymbol]/page.tsx - Orders view · Displays order actions and order state
next-frontend/src/app/orders/page.tsx - Wallet list · Renders holdings and portfolio balance
next-frontend/src/components/WalletList.tsx - Order form · Submits buy and sell orders
next-frontend/src/components/OrderForm.tsx - Chart view · Renders market charts and price history
next-frontend/src/components/ChartComponent.tsx - Socket client · Receives live updates from the API
next-frontend/src/socket-io.ts - Data queries · Shared client-side data access
next-frontend/src/queries/queries.tsx - Client store · Shared browser state for the app
next-frontend/src/store.ts
Connections 31
- Trade entry → Market core: boots · Entrypoint initializes the market engine
- Market core → Order book: uses · The market core maintains the order book
- Market core → Order model: models · Orders are represented inside the domain
- Market core → Matcher: matches · Matching logic drives execution
- Matcher → Trade record: produces · Matches generate trade transactions
- Trade entry → Kafka adapter: connects · Engine communicates through Kafka
- API entry → App module: boots · Application bootstrap loads the root module
- App module → Orders module: imports · Orders feature is part of the app
- App module → Assets module: imports · Assets feature is part of the app
- App module → Wallets module: imports · Wallets feature is part of the app
- App module → Kafka transport: wires · Kafka transport is registered in the app
- Kafka transport → Order consumer: drives · Kafka transport feeds the order consumer
- Orders module → Orders gateway: publishes · Orders module exposes live updates
- Assets module → Assets gateway: publishes · Assets module exposes live updates
- Orders module → Order consumer: consumes · Orders module processes broker events
- Orders module → Kafka adapter: syncs · Orders flow crosses the Kafka boundary
- Kafka adapter → Kafka transport: bridges · Kafka is the asynchronous boundary between services
- Orders module → Assets module: coordinates · Order execution depends on market data
- Orders module → Wallets module: updates · Executed orders affect portfolio state
- Home view → Assets view: navigates · Users move from landing page into market views
- Assets view → Asset detail: opens · Asset list links to detail pages
- Orders view → Order form: contains · Orders screen centers on order entry
- Asset detail → Chart view: renders · Detail view includes charting
- Orders view → Wallet list: shows · Orders experience surfaces portfolio holdings
- Socket client → Orders gateway: subscribes · Frontend receives live order updates
- Socket client → Assets gateway: subscribes · Frontend receives live asset updates
- Data queries → Orders module: fetches · Client queries the API for order data
- Data queries → Assets module: fetches · Client queries the API for asset data
- Data queries → Wallets module: fetches · Client queries the API for wallet data
- Client store → Orders view: shares state · Order screen consumes shared client state
- Client store → Assets view: shares state · Asset screens consume shared client state