# 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
# Run with Docker (recommended)
docker-compose up --build
# Or run locally (requires PostgreSQL running)
python manage.py migrate
python manage.py runserver- Python 3.11+
- PostgreSQL 15+
- Docker & Docker Compose (optional)
- Git
chatgpt-backend/
├── backend/ # Django project settings
├── chat/ # Chat app (conversations, messages)
├── users/ # User management app
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── docker-compose.yml # Docker setup
└── Dockerfile # Container configuration
- 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- Database Setup:
- Using Docker:
docker-compose up - Manual: Create PostgreSQL database named
chatgpt_db
- Using Docker:
# Build and start containers
docker-compose up --build
# Run migrations
docker-compose exec backend python manage.py migrate
# Create superuser
docker-compose exec backend python manage.py createsuperuser
# Stop containers
docker-compose down
# Stop and remove volumes
docker-compose down -v| 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 |
- 📊 Interactive API Testing: Swagger UI
- 📖 Readable Reference: ReDoc
- 📋 OpenAPI Schema: schema.json
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>
- Custom user with email as username
- API key storage
- Credit system
- Premium status
- Belongs to a user
- Has many messages
- Title and timestamps
- Belongs to a conversation
- Role (user/assistant/system)
- Content and token count
# Run tests
python manage.py test
# Run specific app tests
python manage.py test users
python manage.py test chat-
Railway.app (recommended)
# Install Railway CLI npm i -g @railway/cli # Login and deploy railway login railway up
-
Render.com
- Connect GitHub repository
- Set environment variables
- Deploy with PostgreSQL addon
-
Fly.io
# Install Fly CLI curl -L https://fly.io/install.sh | sh # Deploy fly launch fly deploy
- Django Admin:
/admin/ - Database: Use Django shell or pgAdmin
- Logs: Check Docker logs or server logs
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
MIT License - see LICENSE file for details
- Issues: GitHub Issues
- Documentation: Check the Wiki
- Email: miharisoadavidfils@gmail.com
Author: Fanampinirina Miharisoa David Fils RATIANDRAIBE