# 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
- Python 3.11+
- PostgreSQL 15+
- 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
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
- Open Postman
- Click "Import" β "Upload Files"
- Select both:
docs/api/zenith-ai-api.postman_collection.jsondocs/api/zenith-ai-api.postman_environment.json
- Select "Zenith AI - Development" environment from dropdown
- Start testing!
- Register a new user
- Login to get tokens (automatically saved in environment)
- Create conversation
- Send messages
- View conversations
base_url: API base URL (default: http://127.0.0.1:8000)access_token: Automatically set after loginrefresh_token: Automatically set after loginconversation_id: ID of current conversation
See API Documentation for detailed endpoint information.
- 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:
- Manual: Create PostgreSQL database named
chatgpt_db
- Manual: Create PostgreSQL database named
| 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
- 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