# albertnjobo/procurely architecture

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

- Interactive diagram: https://gitdiagram.com/albertnjobo/procurely
- Repository: https://github.com/albertnjobo/procurely

## Overview

1. **Overall shape:** Procurely is a single-page React application with a TypeScript/Express backend in the same repository. The browser talks to the app server over HTTPS, and the server acts as the orchestration layer for AI calls, workflow execution, persistence, and outbound email.

2. **Frontend surface area:** The main UI lives under `src/pages/` and is organized by procurement function: Agent Chat, Dashboard, Intake, Requisitions, RFQs, Suppliers, Knowledge Base, Workflow Designer, Vendor Portal, Settings, and Request Tracker. Shared UI primitives are in `components/ui/` and the app uses a component-driven design system built around shadcn/ui and Tailwind.

3. **Agent experience boundary:** The agent-facing UI is centered on `src/pages/AgentChat.tsx` and the `src/components/agent/` cards. These cards represent human-in-the-loop checkpoints such as item details, supplier selection, impact analysis, bid matrix review, upload prompts, and process timeline. That means the browser is not just a chat client; it also renders approval and decision artifacts returned by the backend.

4. **Backend/API layer:** `server.ts` is the runtime entry point for the Express server. The server exposes modular route handlers in `src/routes/` for agent actions, documents, email, knowledge base, memory, and workflows. This separates request handling from the domain logic that lives in `src/lib/`.

5. **AI orchestration:** Core LLM behavior is centralized in `src/lib/agent-tools.ts`, `tool-executor.ts`, and `agent-prompts.ts`. The agent can call 30+ procurement tools, delegate specialist sub-tasks, and stream responses back to the chat UI. Qwen Cloud is the primary AI dependency, with multiple models used for reasoning, tool calling, embedding, reranking, speech-to-text, and specialist analysis.

6. **RAG and knowledge governance:** The knowledge base pipeline in `src/lib/rag.ts` and `src/lib/zvec-store.ts` handles document chunking, embedding, retrieval, and reranking. Policy content is injected as mandatory context so the agent can refuse non-compliant requests and cite the relevant rule. This is a critical architectural boundary: the KB is not just search, it is a policy enforcement layer for the agent.

7. **Persistent memory:** User preferences and prior decisions are stored separately from the knowledge base in the memory subsystem (`src/routes/memory.ts`, `src/lib/zvec-store.ts`). This gives the agent long-term recall across sessions without mixing personal memory with organizational policy documents.

8. **Workflow automation:** The workflow subsystem combines a visual designer (`src/pages/WorkflowDesigner.tsx`) with execution logic in `src/lib/workflow-engine.ts`, templates in `workflow-templates.ts`, and triggers in `workflow-triggers.ts`. Workflows model procurement events such as submission, approval, notification, and PO generation, and they produce execution logs for auditability.

9. **Data and identity:** Firebase is the system of record for authentication and Firestore-backed application data. The client auth state is managed through `src/lib/auth-context.tsx`, while server-side protection uses `auth-middleware.ts`. Firestore rules and the demo seeding logic indicate that user/session identity is enforced at the data boundary, not only in the UI.

10. **Outbound communications:** Transactional email is a dedicated subsystem, with React Email templates in `src/emails/` and delivery through `src/lib/email-sender.ts`. Emails cover approval requests, RFQs, POs, invoices, and workflow-complete notifications, so the workflow engine can trigger real-world procurement actions outside the app.

11. **Deployment and ingress:** The repo is containerized with `Dockerfile` and `docker-compose.yml`, and `nginx.conf` sits in front of the Node server in production. Cloudflare provides DNS/SSL termination for the public domain, then forwards traffic to Nginx, which proxies to the Express app on port 3000. This makes the deployment boundary: browser → Cloudflare → Nginx → Express → Firebase/Qwen/Resend.

12. **Supporting artifacts:** The repo also includes documentation for the architecture and workflow design, plus Firebase config files and a local `.env.example`. These files reinforce that the app is designed as a full-stack procurement automation system, not just a UI demo: it has persistent state, AI orchestration, workflow execution, and external integrations built into the architecture.

Main entry points: [`src/App.tsx`](https://github.com/albertnjobo/procurely/blob/main/src/App.tsx) (App shell), [`server.ts`](https://github.com/albertnjobo/procurely/blob/main/server.ts) (Server entry), [`src/lib/workflow-engine.ts`](https://github.com/albertnjobo/procurely/blob/main/src/lib/workflow-engine.ts) (Workflow engine), [`src/routes/agent.ts`](https://github.com/albertnjobo/procurely/blob/main/src/routes/agent.ts) (Agent API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_app_shell["App shell<br/>spa entry<br/>[App.tsx]"]
  node_landing_login["Entry pages<br/>public auth<br/>[Landing.tsx]"]
  node_procurement_pages["Procurement pages<br/>feature pages<br/>[Dashboard.tsx]"]
  node_agent_chat["Agent chat<br/>human-in-loop ui<br/>[AgentChat.tsx]"]
  node_workflow_designer["Workflow designer<br/>workflow ui"]
  node_ui_kit["UI kit<br/>shared components<br/>[button.tsx]"]
  node_agent_cards["Agent cards<br/>decision artifacts"]
end

subgraph group_backend["Backend"]
  node_server_entry["Server entry<br/>express runtime<br/>[server.ts]"]
  node_agent_route["Agent API<br/>route handler<br/>[agent.ts]"]
  node_kb_route["KB API<br/>route handler<br/>[kb.ts]"]
  node_memory_route["Memory API<br/>route handler<br/>[memory.ts]"]
  node_workflow_route["Workflow API<br/>route handler<br/>[workflows.ts]"]
  node_agent_tools["Agent tools<br/>tool catalog<br/>[agent-tools.ts]"]
  node_tool_executor["Tool executor<br/>orchestration core<br/>[tool-executor.ts]"]
end

subgraph group_knowledge["Knowledge & Memory"]
  node_rag_pipeline["RAG pipeline<br/>retrieval layer<br/>[rag.ts]"]
  node_vector_store[("Vector store<br/>memory index<br/>[zvec-store.ts]")]
end

subgraph group_automation["Workflow & Comms"]
  node_workflow_engine["Workflow engine<br/>automation core<br/>[workflow-engine.ts]"]
  node_workflow_templates["Workflow templates<br/>workflow defs"]
  node_workflow_triggers["Workflow triggers<br/>event rules"]
  node_email_sender["Email sender<br/>notification service<br/>[email-sender.ts]"]
  node_email_templates["Email templates<br/>react email"]
end

subgraph group_platform["Platform"]
  node_auth_data[("Auth & data<br/>firebase layer<br/>[firebase.ts]")]
  node_auth_middleware["Auth middleware<br/>server guard<br/>[auth-middleware.ts]"]
  node_deployment["Deployment<br/>container edge<br/>[nginx.conf]"]
end

node_app_shell -->|"routes to"| node_landing_login
node_app_shell -->|"renders"| node_procurement_pages
node_app_shell -->|"renders"| node_agent_chat
node_app_shell -->|"renders"| node_workflow_designer
node_app_shell -->|"composes"| node_ui_kit
node_agent_chat -->|"shows"| node_agent_cards
node_server_entry -->|"mounts"| node_agent_route
node_server_entry -->|"mounts"| node_kb_route
node_server_entry -->|"mounts"| node_memory_route
node_server_entry -->|"mounts"| node_workflow_route
node_agent_route -->|"invokes"| node_tool_executor
node_tool_executor -->|"uses"| node_agent_tools
node_agent_tools -->|"queries"| node_rag_pipeline
node_kb_route -->|"serves"| node_rag_pipeline
node_memory_route -->|"stores"| node_vector_store
node_rag_pipeline -->|"reads/writes"| node_vector_store
node_workflow_route -->|"executes"| node_workflow_engine
node_workflow_engine -->|"loads"| node_workflow_templates
node_workflow_engine -->|"reacts to"| node_workflow_triggers
node_workflow_engine -->|"notifies"| node_email_sender
node_email_sender -->|"renders"| node_email_templates
node_server_entry -->|"protects"| node_auth_middleware
node_auth_data -->|"authorizes"| node_agent_route
node_auth_data -->|"hydrates"| node_app_shell
node_deployment -->|"proxies to"| node_server_entry

click node_app_shell "https://github.com/albertnjobo/procurely/blob/main/src/App.tsx"
click node_landing_login "https://github.com/albertnjobo/procurely/blob/main/src/pages/Landing.tsx"
click node_procurement_pages "https://github.com/albertnjobo/procurely/blob/main/src/pages/Dashboard.tsx"
click node_agent_chat "https://github.com/albertnjobo/procurely/blob/main/src/pages/AgentChat.tsx"
click node_workflow_designer "https://github.com/albertnjobo/procurely/blob/main/src/pages/WorkflowDesigner.tsx"
click node_ui_kit "https://github.com/albertnjobo/procurely/blob/main/components/ui/button.tsx"
click node_agent_cards "https://github.com/albertnjobo/procurely/blob/main/src/components/agent/ItemDetailsCard.tsx"
click node_server_entry "https://github.com/albertnjobo/procurely/blob/main/server.ts"
click node_agent_route "https://github.com/albertnjobo/procurely/blob/main/src/routes/agent.ts"
click node_kb_route "https://github.com/albertnjobo/procurely/blob/main/src/routes/kb.ts"
click node_memory_route "https://github.com/albertnjobo/procurely/blob/main/src/routes/memory.ts"
click node_workflow_route "https://github.com/albertnjobo/procurely/blob/main/src/routes/workflows.ts"
click node_agent_tools "https://github.com/albertnjobo/procurely/blob/main/src/lib/agent-tools.ts"
click node_tool_executor "https://github.com/albertnjobo/procurely/blob/main/src/lib/tool-executor.ts"
click node_rag_pipeline "https://github.com/albertnjobo/procurely/blob/main/src/lib/rag.ts"
click node_vector_store "https://github.com/albertnjobo/procurely/blob/main/src/lib/zvec-store.ts"
click node_workflow_engine "https://github.com/albertnjobo/procurely/blob/main/src/lib/workflow-engine.ts"
click node_workflow_templates "https://github.com/albertnjobo/procurely/blob/main/src/lib/workflow-templates.ts"
click node_workflow_triggers "https://github.com/albertnjobo/procurely/blob/main/src/lib/workflow-triggers.ts"
click node_email_sender "https://github.com/albertnjobo/procurely/blob/main/src/lib/email-sender.ts"
click node_email_templates "https://github.com/albertnjobo/procurely/blob/main/src/emails/ApprovalRequest.tsx"
click node_auth_data "https://github.com/albertnjobo/procurely/blob/main/src/lib/firebase.ts"
click node_auth_middleware "https://github.com/albertnjobo/procurely/blob/main/src/lib/auth-middleware.ts"
click node_deployment "https://github.com/albertnjobo/procurely/blob/main/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_app_shell,node_landing_login,node_procurement_pages,node_agent_chat,node_workflow_designer,node_ui_kit,node_agent_cards toneBlue
class node_server_entry,node_agent_route,node_kb_route,node_memory_route,node_workflow_route,node_agent_tools,node_tool_executor toneAmber
class node_rag_pipeline,node_vector_store toneMint
class node_workflow_engine,node_workflow_templates,node_workflow_triggers,node_email_sender,node_email_templates toneRose
class node_auth_data,node_auth_middleware,node_deployment toneIndigo
```

## Components

### Frontend

React SPA, shared UI, and user-facing procurement workflows

- [App shell](https://github.com/albertnjobo/procurely/blob/main/src/App.tsx): spa entry · Top-level client routing and app composition · `src/App.tsx`
- [Entry pages](https://github.com/albertnjobo/procurely/blob/main/src/pages/Landing.tsx): public auth · Landing and login surfaces for the application · `src/pages/Landing.tsx`
- [Procurement pages](https://github.com/albertnjobo/procurely/blob/main/src/pages/Dashboard.tsx): feature pages · Dashboard, intake, requisitions, RFQs, suppliers, catalog, tracker, settings, and vendor portal · `src/pages/Dashboard.tsx`
- [Agent chat](https://github.com/albertnjobo/procurely/blob/main/src/pages/AgentChat.tsx): human-in-loop ui · Chat workspace that renders decisions, approvals, and specialist cards · `src/pages/AgentChat.tsx`
- [Workflow designer](https://github.com/albertnjobo/procurely/blob/main/src/pages/WorkflowDesigner.tsx): workflow ui · Visual authoring surface for procurement workflows · `src/pages/WorkflowDesigner.tsx`
- [UI kit](https://github.com/albertnjobo/procurely/blob/main/components/ui/button.tsx): shared components · Reusable shadcn/ui and Tailwind primitives · `components/ui/button.tsx`
- [Agent cards](https://github.com/albertnjobo/procurely/blob/main/src/components/agent/ItemDetailsCard.tsx): decision artifacts · Specialized cards for item details, supplier selection, impact analysis, bid review, uploads, and timeline · `src/components/agent/ItemDetailsCard.tsx`

### Backend

Express API routes and orchestration logic

- [Server entry](https://github.com/albertnjobo/procurely/blob/main/server.ts): express runtime · Node server bootstrap and HTTPS-facing app runtime · `server.ts`
- [Agent API](https://github.com/albertnjobo/procurely/blob/main/src/routes/agent.ts): route handler · Request handling for chat actions and tool-driven agent flows · `src/routes/agent.ts`
- [KB API](https://github.com/albertnjobo/procurely/blob/main/src/routes/kb.ts): route handler · Document and policy retrieval endpoints · `src/routes/kb.ts`
- [Memory API](https://github.com/albertnjobo/procurely/blob/main/src/routes/memory.ts): route handler · Endpoints for persistent user preferences and prior decisions · `src/routes/memory.ts`
- [Workflow API](https://github.com/albertnjobo/procurely/blob/main/src/routes/workflows.ts): route handler · Workflow execution, templates, and trigger endpoints · `src/routes/workflows.ts`
- [Agent tools](https://github.com/albertnjobo/procurely/blob/main/src/lib/agent-tools.ts): tool catalog · Procurement-specific tool definitions and specialist task delegation · `src/lib/agent-tools.ts`
- [Tool executor](https://github.com/albertnjobo/procurely/blob/main/src/lib/tool-executor.ts): orchestration core · Runs tool calls and streams results back to the chat layer · `src/lib/tool-executor.ts`

### Knowledge & Memory

RAG, policy enforcement, and persistent recall

- [RAG pipeline](https://github.com/albertnjobo/procurely/blob/main/src/lib/rag.ts): retrieval layer · Chunking, embedding, retrieval, reranking, and policy-context injection · `src/lib/rag.ts`
- [Vector store](https://github.com/albertnjobo/procurely/blob/main/src/lib/zvec-store.ts): memory index · Shared vector-backed storage for knowledge and user memory · `src/lib/zvec-store.ts`

### Workflow & Comms

Workflow execution and outbound notifications

- [Workflow engine](https://github.com/albertnjobo/procurely/blob/main/src/lib/workflow-engine.ts): automation core · Executes procurement workflows and writes execution logs · `src/lib/workflow-engine.ts`
- [Workflow templates](https://github.com/albertnjobo/procurely/blob/main/src/lib/workflow-templates.ts): workflow defs · Reusable workflow blueprints · `src/lib/workflow-templates.ts`
- [Workflow triggers](https://github.com/albertnjobo/procurely/blob/main/src/lib/workflow-triggers.ts): event rules · Event-to-workflow trigger definitions · `src/lib/workflow-triggers.ts`
- [Email sender](https://github.com/albertnjobo/procurely/blob/main/src/lib/email-sender.ts): notification service · Transactional delivery for approvals, RFQs, POs, invoices, and completion notices · `src/lib/email-sender.ts`
- [Email templates](https://github.com/albertnjobo/procurely/blob/main/src/emails/ApprovalRequest.tsx): react email · Message templates used by outbound procurement notifications · `src/emails/ApprovalRequest.tsx`

### Platform

Auth, data, and deployment boundary

- [Auth & data](https://github.com/albertnjobo/procurely/blob/main/src/lib/firebase.ts): firebase layer · Client auth state, server protection, and Firestore-backed system of record · `src/lib/firebase.ts`
- [Auth middleware](https://github.com/albertnjobo/procurely/blob/main/src/lib/auth-middleware.ts): server guard · Request-time protection for backend routes · `src/lib/auth-middleware.ts`
- [Deployment](https://github.com/albertnjobo/procurely/blob/main/nginx.conf): container edge · Containerized app and reverse-proxy boundary · `nginx.conf`

## Connections

- App shell → Entry pages: routes to · Hosts unauthenticated entry flows
- App shell → Procurement pages: renders · Main procurement modules in the SPA
- App shell → Agent chat: renders · Agent workspace and decision artifacts
- App shell → Workflow designer: renders · Workflow authoring surface
- App shell → UI kit: composes · Shared UI primitives
- Agent chat → Agent cards: shows · Human-in-the-loop checkpoints and outputs
- Server entry → Agent API: mounts · API surface for agent interactions
- Server entry → KB API: mounts · Knowledge and document endpoints
- Server entry → Memory API: mounts · Persistent memory endpoints
- Server entry → Workflow API: mounts · Workflow endpoints
- Agent API → Tool executor: invokes · Streams tool execution back to the client
- Tool executor → Agent tools: uses · Executes procurement-specific tools
- Agent tools → RAG pipeline: queries · Retrieves policies and knowledge when needed
- KB API → RAG pipeline: serves · Retrieval and policy-governed context
- Memory API → Vector store: stores · Long-term user and decision memory
- RAG pipeline → Vector store: reads/writes · Document chunks, embeddings, and rerank inputs
- Workflow API → Workflow engine: executes · Runs procurement workflows
- Workflow engine → Workflow templates: loads · Blueprints for workflow execution
- Workflow engine → Workflow triggers: reacts to · Event-driven automation entry points
- Workflow engine → Email sender: notifies · Sends approval and completion emails
- Email sender → Email templates: renders · Transactional message content
- Server entry → Auth middleware: protects · Server-side route authorization
- Auth & data → Agent API: authorizes · Authenticated backend requests
- Auth & data → App shell: hydrates · Client auth state for the SPA
- Deployment → Server entry: proxies to · Nginx forwards requests to the Node app
