/vigtra_backend

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Vigtra Backend

Vigtra Backend is a reimagined implementation of the openIMIS project, tailored to align with my personal vision for health insurance management systems. This project is built with respect and appreciation for the openIMIS community and their contributions to open-source healthcare solutions.

Overview

Vigtra aims to provide a robust, scalable, and user-friendly backend for managing health insurance processes. It is designed to support healthcare providers, insurers, and beneficiaries by streamlining operations and improving accessibility.

Features

  • Policy Management: Create, update, and manage health insurance policies.
  • Claims Processing: Efficient handling of claims with automated workflows.
  • Insuree Management: Maintain detailed records of insurees and their coverage.
  • Family Management: Advanced family membership tracking with relationship management.
  • Reporting and Analytics: Generate insightful reports to aid decision-making.
  • GraphQL API: Modern GraphQL API with comprehensive mutation and query support.
  • Audit Trail: Complete change logging for compliance and debugging.
  • Customizable Workflows: Adapt the system to meet specific organizational needs.

Technology Stack

  • Backend Framework: Django 4.x with Python 3.8+
  • Database: PostgreSQL (production) / SQLite (development)
  • API: GraphQL with Graphene-Django
  • Authentication: JWT (JSON Web Tokens)
  • Caching: Redis (production) / In-memory (development)
  • Task Queue: Celery with Redis broker
  • Logging: Structured logging with rotation and environment-aware configuration

Requirements

  • Python 3.10 or higher
  • PostgreSQL 12+ (for production)
  • Redis 6+ (for caching and task queue)
  • Virtual environment tool (venv, virtualenv, or uv)

Installation

Quick Start

  1. Clone the repository:

    git clone git@github.com:Legacy-Engineers/vigtra_backend.git
    cd vigtra_backend
  2. Set up environment and install dependencies:

    # Using uv (recommended)
    uv sync
    
    # Or using traditional pip
    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    pip install poetry
    poetry install
  3. Configure environment variables:

    cp .env.example .env
    # Edit .env with your specific settings
  4. Run database migrations:

    python manage.py migrate
  5. Create a superuser (optional):

    python manage.py createsuperuser
  6. Start the development server:

    python manage.py runserver

Or use the Makefile:

  • make # to run server

Environment Configuration

The application supports multiple environments through the ENVIRONMENT variable:

  • Development: ENVIRONMENT=development (default)
  • Testing: ENVIRONMENT=testing
  • Staging: ENVIRONMENT=staging
  • Production: ENVIRONMENT=production

Configuration

Database Configuration

The application supports multiple database engines:

# SQLite (development default)
DB_ENGINE=sqlite

# PostgreSQL (recommended for production)
DB_ENGINE=postgresql
DB_NAME=vigtra_db
DB_USER=vigtra_user
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=5432

Cache Configuration

Multiple cache backends are supported:

# Redis (recommended)
CACHE_BACKEND=redis
CACHE_URL=redis://localhost:6379/1

# Memcached
CACHE_BACKEND=memcached
CACHE_URL=memcached://localhost:11211

# Development (no caching)
CACHE_BACKEND=dummy

Development

Running Tests

# Run all tests
python manage.py test

# Run specific app tests
python manage.py test modules.insuree


### Code Quality

```bash
# Format code
black .

# Check linting
flake8 .

# Type checking
mypy .

Database Management

# Create migrations
python manage.py makemigrations

# Apply migrations
python manage.py migrate

# Reset database (development only)
python manage.py flush

# Create cache table (if using database cache)
python manage.py createcachetable

Environment Variables for Production

ENVIRONMENT=production
DEBUG=false
SECRET_KEY=your-super-secure-secret-key
JWT_SECRET_KEY=your-jwt-secret-key

# Database
DB_ENGINE=postgresql
DB_NAME=vigtra_prod
DB_USER=vigtra_user
DB_PASSWORD=secure_password
DB_HOST=your-db-host.com

# Cache
CACHE_BACKEND=redis
CACHE_URL=redis://your-redis-host:6379/1

# Security
SECURE_SSL_REDIRECT=true
SESSION_COOKIE_SECURE=true
CSRF_COOKIE_SECURE=true

Monitoring and Logging

Logging

Logs are automatically organized by environment:

  • Development: Console + file logging with debug information
  • Production: Structured JSON logs with rotation
  • Files: Located in logs/ directory
    • debug.log: All debug information
    • error.log: Warnings and errors only
    • django.log: Django framework logs
    • vigtra.log: Application-specific logs

Health Checks

# Database health check
python manage.py check --database

# Cache health check
python manage.py shell -c "from django.core.cache import cache; print('Cache OK' if cache.get('test') is not None or cache.set('test', 'ok') is None else 'Cache Failed')"

Troubleshooting

Common Issues

  1. Virtual environment not found

    python -m venv venv
    source venv/bin/activate
  2. Module import errors

    # Check PYTHONPATH
    export PYTHONPATH="${PYTHONPATH}:$(pwd)"
  3. Database connection errors

    # Check database settings in .env
    # Ensure database server is running
  4. Permission errors in production

    # Check file permissions
    chmod +x manage.py
    chown -R www-data:www-data /path/to/project

Debug Mode

Enable detailed debugging:

ENVIRONMENT=development
DEBUG=true
LOG_LEVEL=DEBUG
GRAPHQL_DEBUG=true

Documentation

Comprehensive documentation is available in the DOCS/ directory:

Quick Links

  • GraphQL Endpoint: http://localhost:8000/graphql/
  • GraphiQL IDE: http://localhost:8000/graphiql/ (development only)
  • Admin Interface: http://localhost:8000/admin/

Testing

The project includes comprehensive test coverage across multiple layers:

Running Tests

# Run all tests
python manage.py test

# Run with coverage
coverage run --source='.' manage.py test
coverage report

# Run specific module tests
python manage.py test modules.insuree

# Run integration tests
python manage.py test tests.integration

License

This project is licensed under the GPL-3.0 License.

Acknowledgments

Special thanks to the openIMIS community for their inspiration and dedication to improving healthcare systems worldwide.

Note: This project is under active development. Features and APIs may change between versions.