Skip to content

DavFilsDev/zenithAI_django-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

79 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Backend Repository README

Chatbot Platform - Backend (Django + PostgreSQL)

πŸš€ Quick Start

# Clone the repository
git clone https://github.com/DavFilsDev/zenithAI_django-backend.git
cd zenithAI_django-backend

# Set up virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Set up environment variables
cp .env.example .env
# Edit .env file with your configuration

# Or run locally (requires PostgreSQL running)
python manage.py migrate
python manage.py runserver

πŸ“‹ Prerequisites

  • Python 3.11+
  • PostgreSQL 15+
  • Git

πŸ—οΈ Project Structure

chatgpt-backend/
β”œβ”€β”€ backend/          # Django project settings
β”œβ”€β”€ chat/            # Chat app (conversations, messages)
β”œβ”€β”€ users/           # User management app
β”œβ”€β”€ requirements.txt # Python dependencies
β”œβ”€β”€ .env.example     # Environment variables template

πŸ“š Documentation Structure

docs/
β”œβ”€β”€ api/                                          # API documentation
   β”œβ”€β”€ zenith-ai-api.postman_collection.json       # Postman collection
   β”œβ”€β”€ zenith-ai-api.postman_environment.json      # Postman environment
   └── api-documentation.md                        # Manual API docs

Quick Start

Using Postman

  1. Open Postman
  2. Click "Import" β†’ "Upload Files"
  3. Select both:
    • docs/api/zenith-ai-api.postman_collection.json
    • docs/api/zenith-ai-api.postman_environment.json
  4. Select "Zenith AI - Development" environment from dropdown
  5. Start testing!

Testing Flow

  1. Register a new user
  2. Login to get tokens (automatically saved in environment)
  3. Create conversation
  4. Send messages
  5. View conversations

πŸ”§ Environment Variables

  • base_url: API base URL (default: http://127.0.0.1:8000)
  • access_token: Automatically set after login
  • refresh_token: Automatically set after login
  • conversation_id: ID of current conversation

πŸ“– API Reference

See API Documentation for detailed endpoint information.

πŸ”§ Configuration

  1. Environment Variables (/.env):
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
DB_NAME=chatgpt_db
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=localhost
DB_PORT=5432
CORS_ALLOWED_ORIGINS=http://localhost:3000
  1. Database Setup:
    • Manual: Create PostgreSQL database named chatgpt_db

πŸ“š API Endpoints

Method Endpoint Description Auth Required
POST /api/auth/register/ User registration No
POST /api/auth/token/ Get JWT token No
GET /api/auth/profile/ User profile Yes
GET /api/chat/conversations/ List conversations Yes
POST /api/chat/conversations/ Create conversation Yes
GET /api/chat/conversations/{id}/ Conversation detail Yes
POST /api/chat/chat/ Send message (new conversation) Yes
POST /api/chat/chat/{id}/ Send message (existing conversation) Yes

πŸ”Œ API Documentation

πŸ” Authentication

Uses JWT (JSON Web Tokens) for authentication:

  • Access tokens valid for 1 day
  • Refresh tokens valid for 7 days
  • Include token in headers: Authorization: Bearer <token>

πŸ—„οΈ Database Models

User Model

  • Custom user with email as username
  • API key storage
  • Credit system
  • Premium status

Conversation Model

  • Belongs to a user
  • Has many messages
  • Title and timestamps

Message Model

  • Belongs to a conversation
  • Role (user/assistant/system)
  • Content and token count

πŸ§ͺ Testing

# Run tests
python manage.py test

# Run specific app tests
python manage.py test users
python manage.py test chat

πŸš€ Deployment

Free Options:

  1. Railway.app (recommended)

    # Install Railway CLI
    npm i -g @railway/cli
    
    # Login and deploy
    railway login
    railway up
  2. Render.com

    • Connect GitHub repository
    • Set environment variables
    • Deploy with PostgreSQL addon
  3. Fly.io

    # Install Fly CLI
    curl -L https://fly.io/install.sh | sh
    
    # Deploy
    fly launch
    fly deploy

πŸ“ˆ Monitoring

  • Django Admin: /admin/
  • Database: Use Django shell or pgAdmin

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

πŸ“„ License

MIT License - see LICENSE file for details

πŸ†˜ Support


Author: Fanampinirina Miharisoa David Fils RATIANDRAIBE

About

Backend API for Zenith AI chatbot platform. RESTful architecture with PostgreSQL, fully documented via OpenAPI/Swagger. Ready for OpenAI integration.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages