-
Notifications
You must be signed in to change notification settings - Fork 0
Architecture Component Interactions
dev-mondoshawan edited this page Apr 16, 2026
·
1 revision
**Referenced Files in This Document**
- [backend/src/routes/register.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/routes/register.js)
- [backend/src/routes/verify.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/routes/verify.js)
- [backend/src/routes/agents.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/routes/agents.js)
- [backend/src/routes/badge.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/routes/badge.js)
- [backend/src/services/bagsAuthVerifier.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/services/bagsAuthVerifier.js)
- [backend/src/services/pkiChallenge.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/services/pkiChallenge.js)
- [backend/src/services/saidBinding.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/services/saidBinding.js)
- [backend/src/services/bagsReputation.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/services/bagsReputation.js)
- [backend/src/services/badgeBuilder.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/services/badgeBuilder.js)
- [backend/src/models/queries.js](https://github.com/RunTimeAdmin/AgentID/blob/main/backend/src/models/queries.js)
Loading
Loading
Loading
Loading
Loading
Loading
Loading
- Introduction
- Route-to-Service Interactions
- Service-to-Model Interactions
- External Service Interactions
- Data Flow Patterns
This document details how components interact within the AgentID system, showing the flow of data and control between routes, services, models, and external systems.
sequenceDiagram
participant Route as "register.js"
participant Auth as "bagsAuthVerifier"
participant SAID as "saidBinding"
participant Queries as "queries.js"
Route->>Route: validateRegistrationInput()
Route->>Auth: verifyBagsSignature()
Auth-->>Route: isValid
Route->>Auth: initBagsAuth()
Auth-->>Route: {message, nonce}
Route->>Auth: completeBagsAuth()
Auth-->>Route: apiKeyId
Route->>SAID: registerWithSAID()
SAID-->>Route: saidResult
Route->>Queries: createAgent()
Queries-->>Route: agent
Route->>Route: Return response
sequenceDiagram
participant Route as "verify.js"
participant PKI as "pkiChallenge"
participant Queries as "queries.js"
Route->>Route: POST /verify/challenge
Route->>Queries: getAgent()
Queries-->>Route: agent
Route->>PKI: issueChallenge()
PKI->>Queries: createVerification()
Queries-->>PKI: verification
PKI-->>Route: {nonce, challenge, expiresIn}
Route->>Route: POST /verify/response
Route->>Queries: getVerification()
Queries-->>Route: verification
Route->>PKI: verifyChallenge()
PKI->>Queries: completeVerification()
Queries-->>PKI: result
PKI->>Queries: updateLastVerified()
PKI-->>Route: {verified, pubkey, timestamp}
sequenceDiagram
participant Route as "badge.js"
participant Builder as "badgeBuilder"
participant Rep as "bagsReputation"
participant Redis as "redis.js"
participant Queries as "queries.js"
Route->>Builder: getBadgeJSON()
Builder->>Redis: getCache()
Redis-->>Builder: cachedData|null
alt Cache Miss
Builder->>Queries: getAgent()
Queries-->>Builder: agent
Builder->>Rep: computeBagsScore()
Rep->>Queries: getAgentActions()
Queries-->>Rep: actions
Rep-->>Builder: scoreData
Builder->>Queries: getAgentActions()
Queries-->>Builder: stats
Builder->>Redis: setCache()
end
Builder-->>Route: badgeJSON
Services interact with the database through the queries module:
graph LR
Service["Service Layer"] --> Queries["queries.js"]
Queries --> Pool["PostgreSQL Pool"]
Pool --> DB[("PostgreSQL")]
| Operation | Function | Usage |
|---|---|---|
| Create Agent | createAgent(params) |
Registration |
| Get Agent | getAgent(pubkey) |
All lookups |
| Update Agent | updateAgent(pubkey, data) |
Metadata updates |
| Create Verification | createVerification(data) |
Challenge issuance |
| Complete Verification | completeVerification(nonce) |
Response verification |
| Get Agent Actions | getAgentActions(pubkey) |
Reputation scoring |
sequenceDiagram
participant Service as "bagsAuthVerifier"
participant API as "Bags API"
Service->>API: POST /agent/v2/auth/init
API-->>Service: {message, nonce}
Service->>Service: Client signs message
Service->>API: POST /agent/v2/auth/callback
API-->>Service: {apiKeyId}
sequenceDiagram
participant Service as "saidBinding"
participant Gateway as "SAID Gateway"
Service->>Gateway: POST /agents/register
Gateway-->>Service: {registered, trust_score}
Service->>Gateway: GET /agents/{pubkey}
Gateway-->>Service: {trust_score, trust_label}
Service->>Gateway: GET /discover?capability
Gateway-->>Service: {agents}
sequenceDiagram
participant Service as "bagsReputation"
participant API as "Bags API"
Service->>API: GET /analytics/token/{mint}/fees
API-->>Service: {total_fees_sol}
Standard API request flow:
- Client sends HTTP request
- Express route receives request
- Route validates input
- Route calls service(s)
- Service(s) interact with models/external APIs
- Service returns result to route
- Route formats response
- Response sent to client
Badge data caching flow:
- Request arrives for badge data
- Check Redis cache
- If cache hit: return cached data
- If cache miss:
- Query database
- Compute reputation
- Build badge JSON
- Store in cache
- Return data
Database error handling:
- Query executed
- If error: throw error
- Error caught by route
- Error passed to error handler
- Error logged
- Client receives error response