Dual-Sided B2B Commerce Agent
DealGraph automates both procurement (buying) and proposals (selling) workflows using LangGraph AI orchestration, from purchase requests to vendor quotes, and RFP responses to deal closures.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DealGraph MVP β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Frontend (Next.js) β AI Service (FastAPI + LangGraph) β
β ββ Authentication β ββ Procurement Workflows β
β ββ Multi-tenant UI β ββ Sales Proposal Workflows β
β ββ Vendor/Client Mgmt β ββ Quote/RFP Processing β
β ββ Quote Comparison β ββ Email Integration β
β ββ Proposal Generation β ββ Document Processing β
β ββ Approval Workflows β ββ Payment Orchestration β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Shared Database Layer β
β ββ PostgreSQL + RLS (Multi-tenant) β
β ββ Prisma ORM (TypeScript + Python) β
β ββ Redis/Valkey (Caching + Queues) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Node.js 18+ with
pnpm - Python 3.11+ with
uv - PostgreSQL 15+
- Redis/Valkey
- Ollama (for local LLM) or OpenAI API key
git clone <repository>
cd dealgraph
# Install shared database package
cd packages/db
pnpm install
# Setup database schema
cp .env.example .env
# Edit .env with your database credentials
pnpm db:generate
pnpm db:push
pnpm db:seedcd apps/ai-service
uv sync
cp .env.example .env
# Edit .env with your configuration
# Start the service
uv run uvicorn src.main:app --reload --port 8000cd apps/web
pnpm install
cp .env.example .env.local
# Edit .env.local with your configuration
# Start development server
pnpm dev- Frontend: http://localhost:3000
- AI Service API: http://localhost:8000
- API Docs: http://localhost:8000/docs
dealgraph/
βββ packages/
β βββ db/ # Shared Prisma schema + client
β βββ schema.prisma # Canonical database schema
β βββ package.json # TypeScript client config
β βββ seed.ts # Database seeding
β
βββ apps/
β βββ web/ # Next.js frontend + BFF
β β βββ src/ # Feature-based architecture
β β β βββ features/ # Procurement & Sales features
β β β βββ shared/ # Common utilities
β β βββ app/ # App Router pages
β β βββ components/ # React components (deprecated, moving to src/)
β β βββ lib/ # Utilities and configs (deprecated, moving to src/)
β β βββ package.json # Frontend dependencies
β β
β βββ ai-service/ # FastAPI + LangGraph backend
β βββ src/
β β βββ workflows/ # LangGraph workflow definitions
β β βββ services/ # Business logic services
β β βββ routers/ # FastAPI route handlers
β β βββ main.py # Application entry point
β βββ tests/ # Test suite
β βββ pyproject.toml # Python dependencies
β
βββ docker-compose.yml # Local development services
βββ README.md # This file
βββ prd.md # Product Requirements Document
graph LR
A[Create Request] --> B[Select Vendors]
B --> C[Send RFQs]
C --> D[Monitor Responses]
D --> E[Process Quotes]
E --> F[Compare & Review]
F --> G[Approve Quote]
G --> H[Process Payment]
H --> I[Complete Request]
LangGraph States: CREATED β QUOTES_REQUESTED β QUOTES_RECEIVED β APPROVED β PAID β COMPLETED
graph LR
A[Receive RFP] --> B[Create Client]
B --> C[Draft Proposal]
C --> D[Generate PDF]
D --> E[Send Proposal]
E --> F[Follow Up]
F --> G[Win/Lose Deal]
Proposal States: DRAFT β SENT β WON/LOST
graph LR
A[Receive Email] --> B[Extract Content]
B --> C[Process Documents]
C --> D[Normalize Data]
D --> E[Validate Quote]
E --> F[Store Results]
AI-Powered: Uses Docling + LLM for intelligent document processing and data extraction.
- Framework: Next.js 15 with App Router
- Auth: Better Auth with Google OAuth
- UI: shadcn/ui + Tailwind CSS
- State: TanStack Query + Zustand
- Database: Prisma Client (TypeScript)
- Framework: FastAPI with async support
- Workflows: LangGraph for state management
- AI: LangChain + OpenAI/Ollama
- Documents: Docling for PDF/document processing
- Database: Prisma Client Python
- Queue: Celery + Redis/Valkey
- Database: PostgreSQL with Row-Level Security
- ORM: Prisma (multi-language support)
- Cache: Redis/Valkey
- Email: Gmail API integration
- Payments: Stripe (test mode)
Every database table includes orgId with PostgreSQL RLS policies:
CREATE POLICY tenant_isolation ON procurement_requests
FOR ALL TO authenticated
USING (org_id = current_setting('app.current_tenant')::text);- User signs in via Better Auth (Google OAuth)
- Organization context established
- All API calls include
X-Tenant-IDheader - Database queries automatically scoped to tenant
- Multi-tenant authentication (Better Auth)
- Procurement request creation (Buying)
- Vendor management
- Client management (Selling)
- Proposal creation and management (Selling)
- LangGraph workflow orchestration
- Email integration (Gmail API)
- Document processing (Docling + LLM)
- Quote/RFP extraction and normalization
- Quote comparison interface
- Proposal generation interface
- Approval workflows
- Payment integration (Stripe)
- Audit logging
- Row-level security (RLS)
- Real-time notifications
- Advanced vendor selection algorithms
- Mobile-responsive UI
- Comprehensive test coverage
- Performance optimization
- ERP integrations
- Advanced analytics dashboard
- Vendor performance scoring
- Bulk operations
- Mobile app
- Marketplace vendor discovery
cd apps/ai-service
uv run pytest --cov=srccd apps/web
pnpm test# Start test databases
docker run -d --name test-postgres -e POSTGRES_DB=dealgraph_test -p 5433:5432 postgres:16-alpine
docker run -d --name test-redis -p 6380:6379 redis:7-alpine
# Run full test suite
pnpm test:integration# Start all services
docker-compose up -d postgres redis ollama
# Start applications
pnpm dev:all- Frontend: Vercel/Netlify
- AI Service: Railway/Render/AWS
- Database: Supabase/PlanetScale/AWS RDS
- Cache: Upstash Redis/AWS ElastiCache
All services use structured JSON logging:
{
"timestamp": "2024-01-15T10:30:00Z",
"level": "INFO",
"service": "ai-service",
"workflow": "procurement",
"org_id": "org_123",
"message": "Workflow completed successfully"
}/health/- Basic health/health/ready- Readiness probe/health/live- Liveness probe
- Workflow execution times
- Quote processing accuracy
- Email processing volume
- User engagement metrics
- Red: Write failing tests first (TDD)
- Green: Implement minimal code to pass
- Refactor: Improve while keeping tests green
- Repeat: Continue for each feature
- TypeScript: Strict mode, proper typing
- Python: Type hints, async/await patterns
- Testing: >80% coverage target
- Documentation: Inline comments + README updates
- Product Requirements Document
- AI Service Documentation
- Database Schema
- API Documentation (when running)
-
Database Connection Errors
# Check PostgreSQL is running docker ps | grep postgres # Verify connection string psql $DATABASE_URL
-
Prisma Client Issues
# Regenerate client cd packages/db pnpm db:generate
-
LLM/Ollama Errors
# Check Ollama is running curl http://localhost:11434/api/tags # Pull required model ollama pull llama3.2
-
Gmail API Issues
- Verify OAuth credentials in Google Console
- Check redirect URIs match configuration
- Ensure Gmail API is enabled
# Enable debug logging
export LOG_LEVEL=DEBUG
# Run with detailed output
pnpm dev:debugMIT License - see LICENSE for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@dealgraph.com
Built with β€οΈ using Next.js, FastAPI, LangGraph, and Prisma