Skip to content

Repository files navigation

CyberWiki Backend

Django-based REST API backend for CyberWiki - a collaborative documentation platform with Git integration.

Architecture

Based on the Backend Design Specification, this backend implements:

  • Django 5.2.9 + Django REST Framework 3.16.1
  • Modular app structure: users, wiki, git_provider, source_provider, enrichment_provider
  • SQLite (dev) / PostgreSQL (production)
  • OpenAPI/Swagger documentation via drf-spectacular

Quick Start

1. Setup Virtual Environment

python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

2. Install Dependencies

pip install -r requirements.txt

3. Configure Environment

cp .env.example .env.dev
# Edit .env.dev with your settings

4. Run Migrations

python manage.py migrate

5. Create Superuser

python manage.py createsuperuser

6. Run Development Server

python manage.py runserver

The API will be available at:

Running from Main Repo

From the main cyber-wiki repository root:

./scripts/run-local.sh

This script will:

  1. Start the backend on port 8000
  2. Start the frontend on port 3000 (if available)
  3. Auto-create admin user (admin/admin)

Project Structure

.
├── src/                       # Source code directory
│   ├── config/                # Django project settings
│   │   ├── settings.py        # Main configuration
│   │   ├── urls.py            # Root URL routing
│   │   └── wsgi.py            # WSGI application
│   ├── users/                 # User management & auth
│   ├── wiki/                  # Wiki/document management
│   ├── git_provider/          # Git provider abstraction
│   ├── source_provider/       # Source addressing layer
│   └── enrichment_provider/   # Enrichment system
├── data/                      # Runtime data (SQLite, etc.)
├── venv/                      # Virtual environment (not in git)
├── manage.py                  # Django management script
├── requirements.txt           # Python dependencies
└── requirements-prod.txt      # Production dependencies (PostgreSQL)

API Endpoints

Users

  • GET /api/users/health/ - Health check

Wiki

  • GET /api/wiki/spaces/ - List spaces

Git Provider

  • GET /api/git/repositories/ - List repositories

Source Provider

  • GET /api/source/get/ - Get source content

Enrichment Provider

  • GET /api/enrichment/list/ - List enrichments

Testing

Unit Tests

Run unit tests with coverage:

# From repo root
./scripts/run-unit-tests.sh

# Or from backend directory
./scripts/run-unit-tests.sh

# With coverage report
pytest src/unit_tests/ --cov=src --cov-report=term-missing --cov-report=html

Current Coverage: 21% (35 tests passing)

See COVERAGE.md for detailed coverage report.

Integration Tests

Run integration tests:

# From repo root
./scripts/run-integration-tests.sh

# Or from backend directory
./scripts/run-integration-tests.sh

Note: Integration tests require API token. See integration test documentation.

All Tests

Run both unit and integration tests:

./scripts/run-backend-tests.sh

Pre-commit Hook

Run pre-commit checks (unit tests + coverage):

./scripts/pre-commit-backend-tests.sh

This will:

  • ✅ Run all unit tests
  • ✅ Generate coverage report
  • ✅ Fail if coverage drops below 20%
  • ✅ Create HTML coverage report in htmlcov/

Development

Adding a New App

python manage.py startapp myapp

Then add to INSTALLED_APPS in config/settings.py.

Database Migrations

python manage.py makemigrations
python manage.py migrate

Shell Access

python manage.py shell

Environment Variables

See .env.example for all available configuration options.

Key variables:

  • DJANGO_SECRET_KEY - Django secret key (required)
  • DEBUG - Debug mode (default: True)
  • ALLOWED_HOSTS - Comma-separated list of allowed hosts
  • CORS_ALLOWED_ORIGINS - Comma-separated list of CORS origins
  • DATABASE_URL - PostgreSQL connection string (optional)

Next Steps

This is a minimal stub implementation. See the Backend Design Specification for the full architecture and implementation roadmap

About

CyberWiki backend

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages