Skip to content

A comprehensive AI-powered chat system built with modern microservices architecture, featuring LangGraph, FastAPI, and a beautiful Vue.js frontend. The system provides enterprise-grade chat capabilities with advanced AI integration, user management, and administrative controls.

License

Notifications You must be signed in to change notification settings

artaasd95/chat-bot-practice-langchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

47 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

LangGraph Chat System

A comprehensive AI-powered chat system built with modern microservices architecture, featuring LangGraph, FastAPI, and a beautiful Vue.js frontend. The system provides enterprise-grade chat capabilities with advanced AI integration, user management, and administrative controls.

πŸš€ Demo & Screenshots

User Interface Overview

Our chat system features a modern, responsive web interface built with Vue.js and Tailwind CSS:

πŸ” Authentication & Login

Login Panel Secure authentication system with JWT tokens and role-based access control

πŸ“Š Dashboard

Dashboard Comprehensive dashboard with system statistics, user activity, and quick access to all features

πŸ’¬ Chat Interface

Chat Interface Intuitive chat interface with real-time messaging, conversation history, and AI-powered responses

βš™οΈ Admin Panel

Admin Panel Powerful administrative interface for user management, system monitoring, and configuration

Live Demo

🌐 Try the live demo: [Coming Soon]

πŸ“– API Documentation: Available at /docs when running locally

✨ Features

🎯 Core Features

AI & Chat Capabilities

  • πŸ€– Multiple LLM Providers: Support for OpenAI, DeepSeek, and other AI providers
  • 🧠 Enhanced Graph Architecture: Advanced conversation flow with LangGraph
  • πŸ”— REST API Tools: AI can make external API calls during conversations
  • πŸ’Ύ Conversation History: Persistent chat sessions with context management
  • ⚑ Real-time Messaging: WebSocket support for instant communication
  • πŸŽ›οΈ Conversation Management: Create, organize, and manage multiple chat sessions

User Management & Authentication

  • πŸ” JWT Authentication: Secure token-based authentication system
  • πŸ‘₯ Role-Based Access Control: User and admin roles with different permissions
  • πŸ“ User Registration: Self-service user registration with email validation
  • πŸ”‘ Password Management: Secure password change and reset functionality
  • πŸ‘€ Profile Management: User profiles with customizable information

Administrative Features

  • πŸ“Š System Dashboard: Comprehensive system statistics and monitoring
  • πŸ‘¨β€πŸ’Ό User Management: Admin panel for managing users and permissions
  • πŸ“ˆ Analytics: User activity tracking and system performance metrics
  • βš™οΈ System Configuration: Configurable settings and system parameters
  • πŸ—‚οΈ Data Export: Export user data and chat histories

πŸ—οΈ Architecture Features

Microservices Architecture

  • πŸ”§ Service Separation: Dedicated services for auth, chat, admin, and frontend
  • 🐳 Docker Containerization: Full Docker support with docker-compose
  • 🌐 API Gateway: Nginx-based API gateway with load balancing
  • πŸ“‘ Service Communication: RESTful APIs between services
  • πŸ”„ Scalable Design: Horizontal scaling support

Database & Storage

  • πŸ—„οΈ PostgreSQL: Robust relational database for data persistence
  • πŸš€ Redis: Caching and session management
  • πŸ“Š Database Migrations: Automated database schema management
  • πŸ’Ύ Data Backup: Automated backup and recovery procedures

Development & Operations

  • πŸ” Comprehensive Logging: Structured logging with rotation policies
  • πŸ“Š Monitoring: Prometheus and Grafana integration
  • πŸ§ͺ Testing: Comprehensive test suite with pytest
  • πŸš€ CI/CD Ready: GitHub Actions and deployment automation
  • πŸ“– Documentation: Extensive documentation and API references

🎨 Frontend Features

Modern UI/UX

  • 🎨 Responsive Design: Mobile-first responsive interface
  • πŸŒ™ Dark/Light Mode: Theme switching support
  • ⚑ Fast Performance: Optimized Vue.js application with Vite
  • 🎯 Intuitive Navigation: User-friendly interface design
  • πŸ“± Mobile Support: Full mobile device compatibility

Interactive Components

  • πŸ’¬ Real-time Chat: Live chat with typing indicators
  • πŸ”” Notifications: Toast notifications for user feedback
  • πŸ“‹ Data Tables: Advanced tables with sorting and filtering
  • πŸ“Š Charts & Graphs: Visual data representation
  • πŸ” Search & Filter: Advanced search capabilities

πŸ”§ Technical Features

API & Integration

  • 🌐 RESTful APIs: Well-documented REST endpoints
  • πŸ“‘ WebSocket Support: Real-time bidirectional communication
  • πŸ”Œ Webhook Support: External system integration
  • πŸ“‹ OpenAPI/Swagger: Auto-generated API documentation
  • πŸ”„ CORS Support: Cross-origin resource sharing

Security & Performance

  • πŸ›‘οΈ Security Headers: Comprehensive security configurations
  • 🚦 Rate Limiting: API rate limiting and abuse prevention
  • ⚑ Async Processing: Fully asynchronous implementation
  • πŸ—œοΈ Response Compression: Gzip compression for optimal performance
  • πŸ”’ Data Encryption: Secure data handling and storage

Project Structure

.
β”œβ”€β”€ app/                    # Main application package
β”‚   β”œβ”€β”€ __init__.py        # Package initialization
β”‚   β”œβ”€β”€ main.py            # FastAPI application entry point
β”‚   β”œβ”€β”€ config.py          # Configuration management
β”‚   β”œβ”€β”€ api/               # API endpoints and models
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ models.py      # Pydantic models for requests/responses
β”‚   β”‚   └── routes.py      # API route definitions
β”‚   β”œβ”€β”€ database/          # Database models and operations
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ models.py      # SQLAlchemy database models
β”‚   β”‚   └── session.py     # Database session management
β”‚   β”œβ”€β”€ graph/             # LangGraph implementation
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ builder.py     # Graph construction (basic, advanced, enhanced)
β”‚   β”‚   └── nodes.py       # Graph node implementations
β”‚   β”œβ”€β”€ services/          # Core services
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ api_tools.py   # API tools service for external calls
β”‚   β”‚   β”œβ”€β”€ history.py     # Conversation history service
β”‚   β”‚   β”œβ”€β”€ llm.py         # LLM service
β”‚   β”‚   └── webhook.py     # Webhook service
β”‚   └── utils/             # Utility modules
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ logging.py     # Logging configuration
β”‚       β”œβ”€β”€ monitoring.py  # Monitoring and LangSmith integration
β”‚       └── tracking.py    # Request tracking utilities
β”œβ”€β”€ docs/                  # Documentation
β”‚   β”œβ”€β”€ api/              # API documentation
β”‚   β”‚   └── chat-api.md   # Chat API endpoints and models
β”‚   β”œβ”€β”€ ai/               # AI/LangGraph documentation
β”‚   β”‚   β”œβ”€β”€ langgraph-architecture.md  # Graph architecture guide
β”‚   β”‚   β”œβ”€β”€ langsmith-integration.md   # LangSmith integration guide
β”‚   β”‚   └── deepseek-integration.md    # DeepSeek integration guide
β”‚   β”œβ”€β”€ backend/          # Backend documentation
β”‚   β”‚   β”œβ”€β”€ architecture.md  # System architecture
β”‚   β”‚   └── services.md   # Services documentation
β”‚   └── database/         # Database documentation
β”‚       └── schema.md     # Database schema and models
β”œβ”€β”€ tests/                # Test files
β”‚   β”œβ”€β”€ test_enhanced_graph.py     # Enhanced graph tests
β”‚   β”œβ”€β”€ test_deepseek_integration.py # DeepSeek integration tests
β”‚   └── ...               # Other test modules organized by feature
β”œβ”€β”€ requirements.txt      # Consolidated project dependencies
└── requirements-test.txt # Testing dependencies

Setup

Prerequisites

  • Python 3.9+
  • OpenAI API key OR DeepSeek API key (or other LLM provider)

Installation

  1. Clone the repository:

    git clone https://github.com/artaasd95/chat-bot-practice-langchain.git
    cd chat-bot-practice-langchain
  2. Create a virtual environment:

    python -m venv venv
    # On Windows
    .\venv\Scripts\activate
    # On Unix/MacOS
    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Create a .env file in the project root with your configuration:

    # API Settings
    API_HOST=0.0.0.0
    API_PORT=8000
    API_WORKERS=4
    
    # CORS Settings
    CORS_ALLOW_ORIGINS=http://localhost:3000,http://localhost:8080
    
    # LLM Settings - Choose your provider
    LLM_PROVIDER=openai  # or "deepseek" for DeepSeek API
    LLM_MODEL=gpt-3.5-turbo  # or "deepseek-chat" for DeepSeek
    LLM_TEMPERATURE=0.7
    LLM_MAX_TOKENS=1000
    
    # OpenAI Configuration
    OPENAI_API_KEY=your_openai_api_key
    
    # DeepSeek Configuration (alternative to OpenAI)
    DEEPSEEK_API_KEY=your_deepseek_api_key
    
    # Logging Settings
    LOG_LEVEL=INFO
    LOG_RETENTION=7 days
    LOG_ROTATION=100 MB
    
    # Webhook Settings
    WEBHOOK_MAX_RETRIES=3
    WEBHOOK_RETRY_DELAY=2
    

Running the Application

Development

uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Production

gunicorn app.main:app -k uvicorn.workers.UvicornWorker -w 4 --bind 0.0.0.0:8000

API Usage

Health Check

curl http://localhost:8000/health

Enhanced Chat (Recommended)

The enhanced chat endpoint provides full conversation history and API tool calling capabilities:

curl -X POST http://localhost:8000/api/chat \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Hello, how are you?"}],
    "conversation_id": "optional-session-id"
  }'

Response includes enhanced metadata:

{
  "response": "Hello! I'm doing well, thank you for asking.",
  "request_id": "req_123456",
  "conversation_id": "conv_789",
  "metadata": {
    "api_calls_made": 0,
    "history_loaded": true,
    "messages_in_context": 5,
    "api_call_details": null
  }
}

Direct Chat (Legacy)

curl -X POST http://localhost:8000/api/chat/direct \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "Hello, how are you?"}]}'

Webhook Chat

curl -X POST http://localhost:8000/api/chat/webhook \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{"role": "user", "content": "Tell me about LangGraph"}],
    "callback_url": "https://your-callback-url.com/webhook"
  }'

Check Webhook Status

curl http://localhost:8000/api/chat/webhook/status/{track_id}

Enhanced Graph Features

API Tool Calling

The enhanced graph can automatically detect when the LLM wants to make external API calls and execute them:

# Example conversation that triggers API call
user_message = "Get the current weather in New York"
# LLM response: "API_CALL: GET https://api.weather.com/v1/current?location=New+York"
# System automatically makes the API call and incorporates the response

Conversation History

Conversations are automatically saved and loaded:

  • Automatic Loading: Previous messages are loaded when a conversation_id is provided
  • Context Management: The system maintains conversation context across sessions
  • Persistent Storage: All conversations are stored in PostgreSQL database

Graph Types

  1. Basic Graph: Simple linear flow for standard conversations
  2. Advanced Graph: Extensible graph with custom nodes
  3. Conditional Graph: Smart routing based on message content
  4. Enhanced Graph: Full-featured graph with API tools and history management

Extending the Graph

The system is designed to be easily extensible. To add new nodes to the graph:

  1. Define new node functions in app/graph/nodes.py
  2. Update the graph builder in app/graph/builder.py to include your new nodes
  3. Modify the API routes as needed to support new functionality

Example of adding a new node:

# In app/graph/nodes.py
async def my_new_node(state: GraphState) -> GraphState:
    # Process state
    return updated_state

# In app/graph/builder.py
async def build_custom_graph(llm: BaseLLM) -> StateGraph:
    # ... existing code ...
    graph.add_node("my_new_node", my_new_node)
    graph.add_edge("generate", "my_new_node")
    graph.add_edge("my_new_node", "postprocess")
    # ... rest of the code ...

Documentation

Comprehensive documentation is available in the docs/ directory:

  • API Documentation: Complete API reference with examples
  • Architecture Guide: Detailed system architecture and design patterns
  • Services Documentation: In-depth service descriptions and implementations
  • Database Schema: Database models and relationships
  • LangGraph Architecture: Graph design patterns and node implementations
  • LangSmith Integration: Comprehensive guide for tracing, monitoring, debugging, and evaluating LLM applications
  • DeepSeek Integration: Guide for using DeepSeek models as an alternative LLM provider

License

MIT

About

A comprehensive AI-powered chat system built with modern microservices architecture, featuring LangGraph, FastAPI, and a beautiful Vue.js frontend. The system provides enterprise-grade chat capabilities with advanced AI integration, user management, and administrative controls.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published