Welcome to the backend API for the VisoWay project. This is a Django (v6.0+) and Django REST Framework application managing Countries and Visas information, including an AI integration in the admin panel to automatically generate and fill data using OpenRouter.
- Prerequisites
- Local Setup
- Environment Variables
- Project Structure
- Development Best Practices
- AI Admin Integration
- Python 3.10+
pipor another package manager (likepipenvorpoetry)- SQLite (default for development) or PostgreSQL (recommended for production)
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables: Copy the example environment variables (if any) or create a new
.envfile at the root of theapifolder.touch .env
-
Run Database Migrations:
python manage.py migrate
-
Create a Superuser (for Admin panel access):
python manage.py createsuperuser
-
Start the Development Server:
python manage.py runserver
The API will be available at
http://localhost:8000/.
For the project to work properly, especially the AI features in the Django admin, you should define the following environment variables in your .env file:
# Core Django settings (Defaults exist for dev, but override in prod)
SECRET_KEY=your_secret_key
DEBUG=True
# OpenRouter / AI Generation Settings
OPENROUTER_API_KEY=your_openrouter_api_key_here
OPENROUTER_MODEL=nvidia/nemotron-3-super-120b-a12b:free
OPENROUTER_TIMEOUT=120config/: Main project configuration (settings, core routing, WSGI/ASGI).countries/: App managing country data (ISO codes, flags, featured countries).visas/: Core app managing visa types, roadmap steps, required documents, FAQs, and tips. Includes theservices/directory for AI generation logic.
- PEP 8: Follow PEP 8 guidelines for Python code.
- Auto-formatters: We recommend using Black and isort for automated code formatting.
- Linting: Use Ruff or Flake8 to enforce code quality.
- Fat Models, Thin Views: Keep business logic in the models, services, or managers rather than crowding the views. The
services/pattern (e.g.,visas/services/ai_generator.py) is encouraged for complex integrations. - Use Django Choices: For fields with predefined options (like
VisaTypeorVisaDifficulty), continue to use Django'sIntegerChoicesorTextChoicesinstead of loose strings. - Optimize Database Queries: Use
select_relatedandprefetch_relatedin serializers and views to prevent N+1 query problems when fetching Visas and their related countries or roadmap steps.
- RESTful Principles: Rely on Django REST Framework's
ModelViewSetand routers for standard CRUD endpoints. - Pagination: The API enforces pagination by default (
PageNumberPaginationwithPAGE_SIZE=20). Maintain this standard for endpoints returning lists. - Validation: Put validation logic inside DRF Serializers, not in the view layer.
- Never commit
.envor sensitive keys (likeOPENROUTER_API_KEYorSECRET_KEY) to version control. - Ensure
DEBUG=Falsein production. - Configure
ALLOWED_HOSTSproperly for production deployments.
This project uses OpenRouter to dynamically fetch and generate visa information directly from the Django Admin panel.
- Ensure your
OPENROUTER_API_KEYis set. - The service prompts OpenRouter's LLM to generate details like Roadmap Steps, Tips, FAQs, and Required Documents.
- The integration is found in
visas/ai_admin.pyandvisas/services/ai_generator.py. Avoid making synchronous external requests in standard client-facing views; keep them restricted to async workers or admin actions where slightly higher latency is acceptable.