# franckinani/ai-investment-agent architecture

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

- Interactive diagram: https://gitdiagram.com/franckinani/ai-investment-agent
- Repository: https://github.com/franckinani/ai-investment-agent

## Overview

#### Purpose and Entry Points
Ledgerline is a private, owner-scoped multi-agent investment research workspace. It supports research, evidence review, agent conversations, auditable decisions, and paper proposals—not real-capital execution. The browser app boots at `client/src/main.tsx`, renders application routing in `client/src/App.tsx`, and communicates with the Node server entry point `server/index.ts`. `/welcome` is public; operational views require authentication.

#### Client Operating Workspace
The React/Vite client provides Mission Control as the primary desk view, plus focused specialist conversations, task/decision, portfolio, activity, connection, wallet, and settings views. Core application surfaces reside in `client/src/pages/MissionControl.tsx`, `client/src/pages/Chat.tsx`, and `client/src/pages/DecisionDesk.tsx`. `client/src/components/DashboardLayout.tsx` supplies the common operator shell; `client/src/_core/hooks/useAuth.ts` gates owner-scoped UI; `client/src/contexts/ThemeContext.tsx` manages presentation state.

#### API, Authentication, and Server Composition
The server composes authenticated tRPC procedures and HTTP/Vite hosting. Request context, cookies, authentication integration, and RPC setup are concentrated in `server/_core/context.ts`, `server/_core/oauth.ts`, and `server/_core/trpc.ts`; route aggregation is in `server/routers.ts`. The client RPC boundary is `client/src/lib/trpc.ts`. Server-side ownership checks are the authoritative boundary—client state must not establish access scope.

#### Agent Fabric and Research Runtime
The agent system defines specialist roles, capabilities, orchestration, and bounded research execution. `server/agentFabric.ts` coordinates agent-facing workflows, `server/agentExecutor.ts` runs agent work, and `server/agentCapabilities.ts` resolves permitted capabilities. Shared role/runtime contracts live in `shared/agentRuntime.ts`, `shared/tradingAgents.ts`, and `shared/capabilityRegistry.ts`. Capability and team declarations are externalized in `config/agents/team.yaml`, `config/capabilities/registry.yaml`, and `config/capabilities/mcp-servers.yaml`, forming a policy/configuration boundary around runtime code.

#### Memory, Conversations, and Auditability
Individual conversations are restricted to eligible non-execution research agents. Server-derived context combines authenticated owner, selected agent, active/expiry state, and retrieval limits; it must not trust client-provided memory scope. `server/agentMemoryRouter.ts` exposes the memory API, `server/agentMemoryDb.ts` persists and retrieves scoped records, and `shared/agentMemory.ts` defines shared/private memory semantics. The additive schema evolution is represented by `drizzle/0011_agent_memory_workspace.sql`, with main persistence schema in `drizzle/schema.ts`. Private-to-shared promotion is an explicit reviewed workflow with revision and audit actions.

#### Decision, Policy, and Execution Boundaries
Research results flow into policy review, decisions, paper simulation, and immutable activity rather than live orders. Policy/authority contracts are in `shared/mandateAuthority.ts`, `shared/authorityState.ts`, and `shared/hardGate.ts`; server enforcement and security endpoints reside in `server/authorityRouter.ts`, `server/security.ts`, and `server/securityRouter.ts`. Paper-only execution is implemented through `server/paperRouter.ts`, `server/paperExecutor.ts`, and `server/backends/paper.backend.ts`. Live CEX/on-chain adapters exist under `server/liveAdapter.ts`, `server/backends/cex.backend.ts`, and `server/backends/onchain.backend.ts`, but the compiled real-venue mutation seal remains the material no-go control.

#### Persistence, Operations, and Deployment
Drizzle migrations/schema target PostgreSQL through `server/db.ts`, `drizzle.config.ts`, and `drizzle/schema.ts`. Dockerized deployment is defined by `Dockerfile`, `docker-compose.yml`, and `docker-compose.prod.yml`; Nginx is configured in `nginx/nginx.conf`. Optional operations monitoring uses Prometheus, Alertmanager, and Grafana configuration in `monitoring/prometheus.yml`, `monitoring/alertmanager.yml`, and `monitoring/grafana/dashboard.json`. Environment values originate from `.env.example`; secrets, wallet material, and database credentials remain deployment-managed inputs.

Main entry points: [`server/routers.ts`](https://github.com/franckinani/ai-investment-agent/blob/main/server/routers.ts) (Router aggregation), [`server/agentFabric.ts`](https://github.com/franckinani/ai-investment-agent/blob/main/server/agentFabric.ts) (Agent fabric), [`server/agentMemoryRouter.ts`](https://github.com/franckinani/ai-investment-agent/blob/main/server/agentMemoryRouter.ts) (Scoped memory API), [`client/src/pages/MissionControl.tsx`](https://github.com/franckinani/ai-investment-agent/blob/main/client/src/pages/MissionControl.tsx) (Operator workspace)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Operator client"]
  node_client_boot["React/Vite bootstrap<br/>client entry<br/>[main.tsx]"]
  node_app_routing["Application routes<br/>React app<br/>[App.tsx]"]
  node_operator_workspace["Operator workspace<br/>Mission Control and desks<br/>[MissionControl.tsx]"]
  node_client_auth["Client auth gate<br/>auth hook<br/>[useAuth.ts]"]
  node_trpc_client["tRPC client boundary<br/>[trpc.ts]"]
end

subgraph group_server["API and runtime"]
  node_server_entry["Node server<br/>server entry<br/>[index.ts]"]
  node_rpc_auth["Authenticated tRPC<br/>request context and RPC<br/>[trpc.ts]"]
  node_route_registry["Router aggregation<br/>tRPC routers<br/>[routers.ts]"]
end

subgraph group_agents["Agent research fabric"]
  node_agent_fabric["Agent fabric<br/>workflow coordinator<br/>[agentFabric.ts]"]
  node_agent_executor["Bounded agent execution<br/>agent runtime<br/>[agentExecutor.ts]"]
  node_agent_contracts["Agent runtime contracts<br/>shared contracts<br/>[agentRuntime.ts]"]
  node_agent_policy_config["Agent policy declarations<br/>team and capability config<br/>[team.yaml]"]
end

subgraph group_governance["Memory and decision controls"]
  node_memory_api["Scoped memory API<br/>memory router"]
  node_memory_store[("Agent memory store<br/>scoped persistence<br/>[agentMemoryDb.ts]")]
  node_memory_contract["Memory semantics<br/>shared contract<br/>[agentMemory.ts]"]
  node_authority_enforcement["Authority enforcement<br/>policy router<br/>[authorityRouter.ts]"]
  node_paper_execution["Paper execution<br/>simulation executor<br/>[paperExecutor.ts]"]
  node_live_mutation_seal{{"Real-venue mutation seal<br/>compiled no-go control<br/>[liveAdapter.ts]"}}
end

subgraph group_ops["Persistence and deployment"]
  node_postgres[("PostgreSQL persistence<br/>Drizzle database<br/>[db.ts]")]
  node_schema_migrations["Schema and migration<br/>Drizzle schema<br/>[schema.ts]"]
  node_deployment["Container deployment<br/>Docker Compose<br/>[docker-compose.yml]"]
  node_nginx["Nginx edge<br/>reverse proxy<br/>[nginx.conf]"]
end

node_client_boot -->|"renders"| node_app_routing
node_app_routing -->|"routes to"| node_operator_workspace
node_client_auth -->|"gates"| node_operator_workspace
node_operator_workspace -->|"uses"| node_trpc_client
node_trpc_client -->|"RPC over HTTP"| node_server_entry
node_server_entry -->|"composes"| node_rpc_auth
node_rpc_auth -->|"authorizes procedures"| node_route_registry
node_route_registry -->|"research workflows"| node_agent_fabric
node_agent_fabric -->|"dispatches"| node_agent_executor
node_agent_executor -->|"uses"| node_agent_contracts
node_agent_fabric -->|"loads declared policy"| node_agent_policy_config
node_route_registry -->|"memory procedures"| node_memory_api
node_memory_api -->|"enforces semantics"| node_memory_contract
node_memory_api -->|"reads and writes"| node_memory_store
node_memory_store -->|"persists to"| node_postgres
node_route_registry -->|"policy and security procedures"| node_authority_enforcement
node_agent_fabric -->|"submits research outcomes"| node_authority_enforcement
node_authority_enforcement -->|"permits paper proposals"| node_paper_execution
node_paper_execution -.->|"cannot bypass"| node_live_mutation_seal
node_schema_migrations -->|"defines and evolves"| node_postgres
node_nginx -->|"proxies to"| node_server_entry
node_deployment -->|"deploys"| node_nginx

click node_client_boot "https://github.com/franckinani/ai-investment-agent/blob/main/client/src/main.tsx"
click node_app_routing "https://github.com/franckinani/ai-investment-agent/blob/main/client/src/App.tsx"
click node_operator_workspace "https://github.com/franckinani/ai-investment-agent/blob/main/client/src/pages/MissionControl.tsx"
click node_client_auth "https://github.com/franckinani/ai-investment-agent/blob/main/client/src/_core/hooks/useAuth.ts"
click node_trpc_client "https://github.com/franckinani/ai-investment-agent/blob/main/client/src/lib/trpc.ts"
click node_server_entry "https://github.com/franckinani/ai-investment-agent/blob/main/server/index.ts"
click node_rpc_auth "https://github.com/franckinani/ai-investment-agent/blob/main/server/_core/trpc.ts"
click node_route_registry "https://github.com/franckinani/ai-investment-agent/blob/main/server/routers.ts"
click node_agent_fabric "https://github.com/franckinani/ai-investment-agent/blob/main/server/agentFabric.ts"
click node_agent_executor "https://github.com/franckinani/ai-investment-agent/blob/main/server/agentExecutor.ts"
click node_agent_contracts "https://github.com/franckinani/ai-investment-agent/blob/main/shared/agentRuntime.ts"
click node_agent_policy_config "https://github.com/franckinani/ai-investment-agent/blob/main/config/agents/team.yaml"
click node_memory_api "https://github.com/franckinani/ai-investment-agent/blob/main/server/agentMemoryRouter.ts"
click node_memory_store "https://github.com/franckinani/ai-investment-agent/blob/main/server/agentMemoryDb.ts"
click node_memory_contract "https://github.com/franckinani/ai-investment-agent/blob/main/shared/agentMemory.ts"
click node_authority_enforcement "https://github.com/franckinani/ai-investment-agent/blob/main/server/authorityRouter.ts"
click node_paper_execution "https://github.com/franckinani/ai-investment-agent/blob/main/server/paperExecutor.ts"
click node_live_mutation_seal "https://github.com/franckinani/ai-investment-agent/blob/main/server/liveAdapter.ts"
click node_postgres "https://github.com/franckinani/ai-investment-agent/blob/main/server/db.ts"
click node_schema_migrations "https://github.com/franckinani/ai-investment-agent/blob/main/drizzle/schema.ts"
click node_deployment "https://github.com/franckinani/ai-investment-agent/blob/main/docker-compose.yml"
click node_nginx "https://github.com/franckinani/ai-investment-agent/blob/main/nginx/nginx.conf"

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_client_boot,node_app_routing,node_operator_workspace,node_client_auth,node_trpc_client toneBlue
class node_server_entry,node_rpc_auth,node_route_registry toneAmber
class node_agent_fabric,node_agent_executor,node_agent_contracts,node_agent_policy_config toneMint
class node_memory_api,node_memory_store,node_memory_contract,node_authority_enforcement,node_paper_execution,node_live_mutation_seal toneRose
class node_postgres,node_schema_migrations,node_deployment,node_nginx toneIndigo
```

## Components

### Operator client

- [React/Vite bootstrap](https://github.com/franckinani/ai-investment-agent/blob/main/client/src/main.tsx): client entry · `client/src/main.tsx`
- [Application routes](https://github.com/franckinani/ai-investment-agent/blob/main/client/src/App.tsx): React app · `client/src/App.tsx`
- [Operator workspace](https://github.com/franckinani/ai-investment-agent/blob/main/client/src/pages/MissionControl.tsx): Mission Control and desks · Authenticated research, chat, and decision surfaces share an operator shell. · `client/src/pages/MissionControl.tsx`
- [Client auth gate](https://github.com/franckinani/ai-investment-agent/blob/main/client/src/_core/hooks/useAuth.ts): auth hook · Gates owner-scoped UI; it is not the authority boundary. · `client/src/_core/hooks/useAuth.ts`
- [tRPC client boundary](https://github.com/franckinani/ai-investment-agent/blob/main/client/src/lib/trpc.ts): RPC client · `client/src/lib/trpc.ts`

### API and runtime

- [Node server](https://github.com/franckinani/ai-investment-agent/blob/main/server/index.ts): server entry · Hosts HTTP, authenticated RPC, and Vite integration. · `server/index.ts`
- [Authenticated tRPC](https://github.com/franckinani/ai-investment-agent/blob/main/server/_core/trpc.ts): request context and RPC · Cookies and server-derived identity establish authoritative owner scope. · `server/_core/trpc.ts`
- [Router aggregation](https://github.com/franckinani/ai-investment-agent/blob/main/server/routers.ts): tRPC routers · `server/routers.ts`

### Agent research fabric

- [Agent fabric](https://github.com/franckinani/ai-investment-agent/blob/main/server/agentFabric.ts): workflow coordinator · `server/agentFabric.ts`
- [Bounded agent execution](https://github.com/franckinani/ai-investment-agent/blob/main/server/agentExecutor.ts): agent runtime · `server/agentExecutor.ts`
- [Agent runtime contracts](https://github.com/franckinani/ai-investment-agent/blob/main/shared/agentRuntime.ts): shared contracts · Defines roles, runtime behavior, and capability registry contracts. · `shared/agentRuntime.ts`
- [Agent policy declarations](https://github.com/franckinani/ai-investment-agent/blob/main/config/agents/team.yaml): team and capability config · External declarations constrain teams, capabilities, and MCP servers. · `config/agents/team.yaml`

### Memory and decision controls

- [Scoped memory API](https://github.com/franckinani/ai-investment-agent/blob/main/server/agentMemoryRouter.ts): memory router · Derives eligible agent, owner, active state, expiry, and retrieval limits server-side. · `server/agentMemoryRouter.ts`
- [Agent memory store](https://github.com/franckinani/ai-investment-agent/blob/main/server/agentMemoryDb.ts): scoped persistence · Persists private/shared memory and reviewed promotion audit records. · `server/agentMemoryDb.ts`
- [Memory semantics](https://github.com/franckinani/ai-investment-agent/blob/main/shared/agentMemory.ts): shared contract · `shared/agentMemory.ts`
- [Authority enforcement](https://github.com/franckinani/ai-investment-agent/blob/main/server/authorityRouter.ts): policy router · Applies mandate, authority-state, and hard-gate controls. · `server/authorityRouter.ts`
- [Paper execution](https://github.com/franckinani/ai-investment-agent/blob/main/server/paperExecutor.ts): simulation executor · Produces proposals and simulations, not real-capital orders. · `server/paperExecutor.ts`
- [Real-venue mutation seal](https://github.com/franckinani/ai-investment-agent/blob/main/server/liveAdapter.ts): compiled no-go control · Blocks live CEX and on-chain mutation despite adapter presence. · `server/liveAdapter.ts`

### Persistence and deployment

- [PostgreSQL persistence](https://github.com/franckinani/ai-investment-agent/blob/main/server/db.ts): Drizzle database · Holds owner-scoped application, memory, decision, and activity data. · `server/db.ts`
- [Schema and migration](https://github.com/franckinani/ai-investment-agent/blob/main/drizzle/schema.ts): Drizzle schema · Includes additive agent-memory workspace evolution. · `drizzle/schema.ts`
- [Container deployment](https://github.com/franckinani/ai-investment-agent/blob/main/docker-compose.yml): Docker Compose · Deployment-managed environment supplies secrets and credentials. · `docker-compose.yml`
- [Nginx edge](https://github.com/franckinani/ai-investment-agent/blob/main/nginx/nginx.conf): reverse proxy · `nginx/nginx.conf`

## Connections

- React/Vite bootstrap → Application routes: renders
- Application routes → Operator workspace: routes to
- Client auth gate → Operator workspace: gates
- Operator workspace → tRPC client boundary: uses
- tRPC client boundary → Node server: RPC over HTTP
- Node server → Authenticated tRPC: composes
- Authenticated tRPC → Router aggregation: authorizes procedures
- Router aggregation → Agent fabric: research workflows
- Agent fabric → Bounded agent execution: dispatches
- Bounded agent execution → Agent runtime contracts: uses
- Agent fabric → Agent policy declarations: loads declared policy
- Router aggregation → Scoped memory API: memory procedures
- Scoped memory API → Memory semantics: enforces semantics
- Scoped memory API → Agent memory store: reads and writes
- Agent memory store → PostgreSQL persistence: persists to
- Router aggregation → Authority enforcement: policy and security procedures
- Agent fabric → Authority enforcement: submits research outcomes
- Authority enforcement → Paper execution: permits paper proposals
- Paper execution → Real-venue mutation seal: cannot bypass
- Schema and migration → PostgreSQL persistence: defines and evolves
- Nginx edge → Node server: proxies to
- Container deployment → Nginx edge: deploys
