A full-stack application that enables users to create, visualize, and interact with knowledge diagrams through AI-powered chat assistance. The system combines a FastAPI backend for intelligent document processing with a Next.js frontend for collaborative diagram editing.
This project provides a collaborative platform for knowledge management and visualization through interactive diagrams. Users can upload documents, chat with an AI assistant to extract insights, and create visual representations of complex information using mind maps and flowcharts.
The project is organized into three main components:
backend/: FastAPI + LangChain/LangGraph service for AI chat, retrieval and document processingfrontend/: Next.js app for diagram editing, collaboration, authentication and file managementnginx/: Nginx configuration for Reverse Proxy, Load Balancing and HTTPS
Infrastructure Services:
docker-compose.yml(root): Orchestrates all services (backend, frontend, nginx, pgvector, main database, Ollama, Cloudflare tunnel)scripts/: Utility scripts (e.g.,run-ollama.shfor starting Ollama service with model pre-loading)
The backend API handles AI-powered chat functionality and document processing. Built with FastAPI and LangChain, it provides:
- AI Chat Engine: RAG (Retrieval-Augmented Generation) pipeline for context-aware responses
- Document Processing: PDF and text file parsing with intelligent chunking
- Vector Storage: PGVector-based semantic search for document retrieval
- Workflow Management: LangGraph-powered conversational workflows with PostgreSQL checkpointing
- Nonβstreaming Chat API:
/api/chat,/api/chat-history, and deletion endpoints for history & vector store
The web application provides the user interface for diagram creation and collaboration. Built with Next.js and React, it offers:
- Diagram Editor: Interactive canvas for creating mind maps and flowcharts using React Flow (
@xyflow/react) - Real-time Collaboration: Multi-user editing with Liveblocks
- Authentication: Secure user management with NextAuth.js (Google OAuth)
- File Management: AWS S3-compatible storage (frontend) and Supabase Storage (backend) for document upload & retrieval
- Team Workspaces: Organize diagrams in folders and teams with permission controls
- Internationalization: Multi-language support (English, Japanese, Vietnamese)
- AI-Powered Chat: Interact with an intelligent chatbot to analyze uploaded documents
- Document Upload: Support for PDF and text files with automatic processing
- Knowledge Extraction: RAG-based retrieval for accurate, context-aware answers
- Visual Diagrams: Create mind maps and flowcharts from AI-generated insights
- Real-time Collaboration: Multiple users can edit diagrams simultaneously
- Team Management: Share diagrams and folders with granular permissions (Owner, Editor, Viewer)
- Cloud Storage: Secure document storage with AWS S3 (frontend) and Supabase Storage (backend)
- Responsive Design: Modern UI with dark mode support
- Multilingual: Interface available in multiple languages (EN/JA/VI)
- Secure Access: HTTPS enabled with Nginx Reverse Proxy and Cloudflare Tunnel
- Scalable: Frontend load balancing with Nginx and Docker Replicas
- Framework: FastAPI (async Python web framework)
- AI/ML & Orchestration:
- LangChain (
langchain-core,langchain-community) - LangGraph (workflow management, PostgreSQL checkpoint/store)
- Google Generative AI (Gemini models) via
langchain-google-genai - Ollama via
langchain-ollama(local models, configured throughOLLAMA_BASE_URL)
- LangChain (
- Vector Store: PostgreSQL with PGVector extension (
langchain-postgres) - Document Processing:
pypdf,unstructured - Storage: Supabase Storage (
supabaseclient) for file downloads - Other Services: HTTP client (
httpx) for external API calls - Deployment: Docker & Docker Compose
- Framework: Next.js 16 (React 19, App Router)
- Language: TypeScript
- Styling: Tailwind CSS 4
- Diagram Library: React Flow (
@xyflow/react) - Collaboration: Liveblocks
- Authentication: NextAuth.js 5
- ORM: Prisma (PostgreSQL)
- Forms: React Hook Form with Zod validation
- UI Components: Radix UI, shadcn/ui, custom components
- Animations: Framer Motion, GSAP,
motion - State Management: Zustand
- Markdown: React Markdown with syntax highlighting
- Storage: AWS SDK (
@aws-sdk/client-s3) for S3 file uploads - i18n:
next-intlwith language messages infrontend/languages/messages
- Reverse Proxy: Nginx (handling HTTPS, Gzip, Header security)
- Load Balancing: Nginx + Docker DNS Round Robin
- Tunneling: Cloudflare Tunnel (expose local service to internet securely)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Client Layer β
β (Next.js Frontend) β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ β
β β Diagram β β Chat β β File β β
β β Editor β β Interface β β Management β β
β ββββββββββββββββββ ββββββββββββββββββ ββββββββββββββββββ β
ββββββββββββββββ¬βββββββββββββββββββ¬βββββββββββββββββ¬βββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Nginx (Reverse Proxy) β
β (HTTPS, Load Balancing, Security Headers) β
βββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
ββββββββββββββββ΄βββββββββββββββ
βΌ βΌ
ββββββββββββββββββββββββ βββββββββββββββββββββββββββββββ
β Frontend Replicas β β FastAPI Backend β
β (Next.js x3) β β (AI Chat + RAG) β
ββββββββββββββββββββββββ ββββββββββββββββ¬βββββββββββββββ
β
βββββββββββββββββββββββ΄βββββββββββββββββ
βΌ βΌ
ββββββββββββββββββββββ βββββββββββββββββββββββ
β PostgreSQL β β LLM Providers β
β (App DB, Prisma) β β (Gemini, Ollama) β
ββββββββββββββββββββββ βββββββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββββββββ βββββββββββββββββββββββ
β PGVector β β Supabase Storage β
β (Vector Search) β β (Backend) β
ββββββββββββββββββββββ βββββββββββββββββββββββ
- Node.js 20+ and npm/yarn/pnpm
- Python 3.10+
- Docker 20.10+ and Docker Compose 2.0+
- (Optional for local, if not using Docker) PostgreSQL 16+ with PGVector extension
- AWS Account (for S3 storage - used by frontend for file uploads)
- Supabase Account (for Supabase Storage - used by backend for file downloads)
- Google Cloud Account (for OAuth and Gemini AI)
- Liveblocks Account (for real-time collaboration)
- Cloudflare Account (optional, for tunnel)
At the project root, create a .env file to configure services used by docker-compose.yml:
# Vector store (pgvector service)
POSTGRES_USER=vector_user
POSTGRES_PASSWORD=vector_password
POSTGRES_DB=vector_db
POSTGRES_PORT=5433
PGVECTOR_DATA_DIR=./.data/pgvector
POSTGRES_HOST=pgvector
# Application database (database service)
DATABASE_USER=app_user
DATABASE_PASSWORD=app_password
DATABASE_NAME=app_db
DATABASE_PORT=5434
DATABASE_DATA_DIR=./.data/database
# Frontend / auth
NEXT_PUBLIC_APP_URL=http://localhost # Access via Nginx (port 80/443)
AUTH_URL=http://localhost # Access via Nginx
NEXTAUTH_URL=http://localhost # Access via Nginx
AUTH_SECRET=your_auth_secret
AUTH_GOOGLE_ID=your_google_oauth_client_id
AUTH_GOOGLE_SECRET=your_google_oauth_client_secret
DISABLE_ERD=true
# S3 / object storage (used by frontend for file uploads)
AWS_ENDPOINT=
AWS_BUCKET=
AWS_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
# Liveblocks & email
LIVEBLOCKS_SECRET_KEY=
RESEND_API_KEY=
# LLM providers
GOOGLE_API_KEY=your_google_api_key
OLLAMA_DATA_DIR=./.data/ollama
# Backend integrations (Supabase Storage for file downloads)
SUPABASE_URL=
SUPABASE_KEY=
# Cloudflare tunnel (optional)
TUNNEL_TOKEN=Note:
NEXT_PUBLIC_APP_URL,AUTH_URL,NEXTAUTH_URLshould point tohttp://localhost(or your domain) because Nginx handles port 80/443.
Before running Nginx, you need to set up SSL certificates in nginx/ssl/.
Option 1: Self-signed (Local Development) Run this command to generate a self-signed certificate:
mkdir -p nginx/ssl
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout nginx/ssl/key.pem \
-out nginx/ssl/cert.pem \
-subj "/C=VN/ST=HCM/L=HCM/O=Knovion/CN=localhost"Option 2: Cloudflare Origin Certificate (Production)
- Go to Cloudflare Dashboard -> SSL/TLS -> Origin Server.
- Create Certificate.
- Save as
cert.pemandkey.peminnginx/ssl/.
- Navigate to the backend directory:
cd backend- Create a
.envfile inbackend/(if you don't already have one) with at least:
FRONTEND_URL=http://localhost:3000
POSTGRES_USER=vector_user
POSTGRES_PASSWORD=vector_password
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_DB=vector_db
GOOGLE_API_KEY=your_google_api_key
OLLAMA_BASE_URL=http://localhost:11434
SUPABASE_URL=
SUPABASE_KEY=- Install dependencies:
pip install -r requirements.txt- Navigate to the frontend directory:
cd frontend- Create a
.envfile infrontend/with at least:
# NextAuth base URL (critical for Google OAuth redirect_uri)
AUTH_URL=http://localhost:3000
NEXTAUTH_URL=http://localhost:3000
AUTH_SECRET=your_auth_secret
AUTH_GOOGLE_ID=your_google_oauth_client_id
AUTH_GOOGLE_SECRET=your_google_oauth_client_secret
DISABLE_ERD=true
DATABASE_URL=postgresql://app_user:app_password@localhost:5434/app_db
AWS_ENDPOINT=
AWS_BUCKET=
AWS_REGION=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
LIVEBLOCKS_SECRET_KEY=
RESEND_API_KEY=
NEXT_PUBLIC_APP_URL=http://localhost:3000
BACKEND_URL=http://localhost:8000- Install dependencies:
npm install- Generate Prisma client and run migrations:
npx prisma generate
npx prisma migrate devFrom the project root:
docker-compose up -d --buildWhen all services are healthy:
- Web App:
https://localhost(Nginx handles HTTPS)- Accepts self-signed cert warning on local.
- Backend API:
http://localhost:8000(Direct access) orhttps://localhost/api/backend(via Nginx)- Swagger docs:
http://localhost:8000/docs
- Swagger docs:
- Ollama:
http://localhost:11434
To scale the frontend to multiple instances (e.g., 3 replicas) for load balancing:
docker-compose up -d --scale frontend=3Nginx will automatically load balance requests between these instances.
- Ensure PostgreSQL with PGVector extension is running and matches your backend
.env - Start the FastAPI server:
cd backend
uvicorn src.main:app --reload --host 0.0.0.0 --port 8000cd frontend
npm run devThe web app will be available at http://localhost:3000.
.
βββ backend/ # FastAPI + LangGraph backend
βββ frontend/ # Next.js 16 frontend
βββ nginx/ # Nginx configuration & SSL
β βββ ssl/ # Certificate files (gitignored)
β βββ nginx.conf # Nginx config file
βββ docker-compose.yml # Orchestration for all services
βββ README.md
backend/
βββ src/
β βββ models/ # Data models (vector store, chat, embeddings, text splitter)
β βββ schemas/ # Pydantic schemas (requests, responses, states)
β βββ edges.py # LangGraph workflow nodes & RAG pipeline
β βββ main.py # FastAPI application entry point
βββ requirements.txt # Python dependencies
βββ Dockerfile # Backend Docker configuration
frontend/
βββ app/
β βββ (auth)/ # Authentication pages
β βββ (main)/ # Main application pages
β βββ (diagram-editor)/ # Diagram editing interface
β βββ _actions/ # Server actions (file, folder, team, diagram, chat)
β βββ _components/ # Shared React components
β βββ api/ # API routes (NextAuth, Liveblocks, S3, chat proxy)
βββ components/ # Reusable UI components & sections
βββ prisma/ # Database schema
βββ lib/ # Utility functions & configuration
βββ hooks/ # Custom React hooks
βββ stores/ # Zustand state stores
βββ languages/ # i18n setup & message catalogs
βββ types/ # TypeScript type definitions
βββ public/ # Static assets
βββ Dockerfile # Frontend Docker configuration
- Create a new diagram in the web interface
- Upload a PDF or text file
- Ask questions about the document, for example:
User: "Summarize the key concepts in this document" AI: [Provides summary based on document content]
- Upload a document to a diagram
- Ask the AI to create a mind map:
User: "Create a mind map of the main topics" AI: [Generates structured mind map data] - Visualize and refine the generated structure in the diagram editor
- Share a diagram with team members
- Multiple users can:
- Edit nodes and edges simultaneously
- See live cursors and selections
- Chat about the diagram content
- Create teams for different projects
- Organize diagrams in folders
- Set permissions (Owner, Editor, Viewer) for members
- Export Features: Export diagrams as PNG, SVG, or PDF
- Additional Diagram Types: Support for UML, ER diagrams, and more
- Advanced AI Features:
- Multi-document analysis
- Automatic diagram generation from text
- Smart suggestions for diagram improvements
- Enhanced Collaboration:
- Video/audio calls within the app
- Comments and annotations
- Version history and rollback
- Mobile App: Native iOS and Android applications
- API Integrations: Connect with Notion, Google Docs, Confluence
- Custom Templates: Pre-built diagram templates
- Analytics: Usage insights and diagram analytics
- Offline Mode: Work without internet connection
- Advanced Search: Full-text search across all diagrams
- Workflow Automation: Trigger actions based on diagram changes
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is proprietary software. All rights reserved.
- LangChain for the powerful LLM framework
- Vercel for Next.js and hosting
- Liveblocks for real-time collaboration infrastructure
- React Flow for the diagram editor library
- shadcn/ui for beautiful UI components
For questions or support, please open an issue on GitHub.