A full-stack web application featuring a powerful AI chatbot powered by Together AI, with user authentication and a responsive interface built with React and Django.
-
User Authentication System
- Secure signup and login functionality
- JWT token-based authentication
- Password strength validation
-
AI Chatbot
- Real-time conversation with AI assistant
- Powered by Together AI
- Clean, intuitive chat interface
-
Responsive Design
- Works across desktop and mobile devices
- Modern React-based UI
- Smooth user experience
- Django 5.1.6: High-level Python web framework
- Django REST Framework 3.15.2: Powerful toolkit for building Web APIs
- djangorestframework-simplejwt 5.4.0: JWT authentication for Django REST Framework
- together 1.5.5: Official Together AI Python client
- PostgreSQL: Advanced open-source database system
- React: JavaScript library for building user interfaces
- HTML5/CSS3: Modern web layout and styling
- JavaScript (ES6+): Dynamic client-side functionality
- Fetch API: For making API calls to the backend
- Node.js/npm: Package management and development server
backend/
βββ backend/ # Main Django project settings
βββ users/ # User authentication app
β βββ models.py
β βββ serializers.py
β βββ urls.py
β βββ views.py
βββ chatbot/ # Chatbot functionality app
βββ models.py
βββ serializers.py
βββ urls.py
βββ views.py
frontend/
βββ public/ # Static files
βββ src/ # React source files
β βββ components/ # React components
β βββ pages/ # Page components
β βββ services/ # API services
β βββ styles/ # CSS styles
β βββ App.js # Main React component
β βββ index.js # React entry point
βββ package.json # NPM dependencies and scripts
βββ node_modules/ # Node.js packages
- Python 3.10+
- Node.js and npm
- PostgreSQL database
- Together AI API key
-
Clone the repository:
git clone https://github.com/mel-moun/Chatbot.git cd Chatbot
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Python dependencies:
pip install -r requirements.txt
-
Set up PostgreSQL database:
# Install PostgreSQL if not already installed # On Ubuntu/Debian: sudo apt update sudo apt install postgresql postgresql-contrib # On macOS with Homebrew: brew install postgresql # Start PostgreSQL service # On Ubuntu/Debian: sudo service postgresql start # On macOS: brew services start postgresql
-
Create PostgreSQL database and user:
-- Create database and user CREATE DATABASE test_db; CREATE USER test_user WITH PASSWORD 'test_password'; -- Recommended user settings ALTER ROLE test_user SET client_encoding TO 'utf8'; ALTER ROLE test_user SET default_transaction_isolation TO 'read committed'; ALTER ROLE test_user SET timezone TO 'UTC'; -- Grant privileges GRANT ALL PRIVILEGES ON DATABASE test_db TO test_user; -- Connect to the database \c test_db -- Grant schema and object-level privileges ALTER SCHEMA public OWNER TO test_user; GRANT ALL ON SCHEMA public TO test_user; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO test_user; GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO test_user; GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO test_user; -- Optional extensions CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS pg_trgm; -- Set search path ALTER ROLE test_user SET search_path TO public; -- Exit PostgreSQL \q
-
Configure environment variables:
-
Go to
Together.ai
and sign up. -
Get your API key from the dashboard.
-
Create a
.env
file in theBackend
directory with the following content:SECRET_KEY=django-insecure-dummyt3stingk3y DEBUG=True TOGETHER_API_KEY=your-together-api-key-here DB_ENGINE=django.db.backends.postgresql DB_NAME=test_db DB_USER=test_user DB_PASSWORD=test_password DB_HOST=localhost DB_PORT=5432
π‘ You can use a dummy key like
test-dummy-key-1234
to run the project locally without chatbot functionality.
However, to use the AI features, you need a valid API key from Together.ai. -
-
Run migrations:
cd Backend # Make migrations in correct order python3 manage.py makemigrations users python3 manage.py makemigrations # For other apps # Apply all migrations python3 manage.py migrate
-
Start the Django development server:
python3 manage.py runserver
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
The application should automatically open in your default browser or navigate to the URL shown in your terminal (typically http://localhost:5173/)
- POST
/api/users/register/
: Register a new user - POST
/api/users/login/
: Login and obtain JWT tokens
- POST
/api/chat/
: Send a message to the AI chatbot
- JWT token-based authentication
- Password strength validation
- Form input validation
- CORS protection
- Protection against common web vulnerabilities