Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Project Horizon πŸš€

Modern Django REST API backend with support for multiple frontends (React, Svelte, etc.). Built with scalability, performance, and developer experience in mind.

πŸ“‹ Tech Stack

Backend:

  • Django 4.2+ (Python 3.10+)
  • Django REST Framework
  • PostgreSQL
  • Redis
  • Celery (async tasks & scheduling)
  • Docker & Docker Compose

Features:

  • JWT Authentication (rest_framework_simplejwt)
  • CORS support
  • API documentation (drf-spectacular with Swagger UI)
  • Celery for background tasks
  • Comprehensive logging
  • Security best practices built-in

πŸš€ Quick Start

Prerequisites

  • Python 3.10+
  • Docker & Docker Compose
  • Git

Setup

1. Clone the repository

git clone https://github.com/KLWS-Affiliate-Program/practicing-Svelte.git
cd Project\ Horizon

2. Open in VS Code

  • VS Code will prompt you to install recommended extensions
  • Click "Install All" or manually install extensions from .vscode/extensions.json

3. Create Virtual Environment

python -m venv .venv

# Windows
.venv\Scripts\activate

# macOS/Linux
source .venv/bin/activate

4. Install Dependencies

# From pyproject.toml
pip install -e ".[dev]"

# Or from requirements.txt
pip install -r requirements.txt

5. Environment Setup

# Copy example env file
cp .env.example .env

# Update .env with your local settings if needed

6. Start Development Environment

Option A: Using Docker Compose (Recommended)

# Start all services (PostgreSQL, Redis, Django, Celery, Celery Beat)
docker compose up -d

# Run migrations
docker compose exec web python manage.py migrate

# Create superuser
docker compose exec web python manage.py createsuperuser

# Load fixtures (if available)
docker compose exec web python manage.py loaddata fixtures/initial_data.json

Option B: Using VS Code Task (if configured)

  • Open the Command Palette: Ctrl/Cmd + Shift + P
  • Run: ▢️ START: Full Dev Environment

Option C: Manual Local Setup

python manage.py migrate
python manage.py createsuperuser
python manage.py runserver

7. Access the Application

πŸ“ Project Structure

Project Horizon/
β”œβ”€β”€ config/                 # Project settings & configuration
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ settings.py        # Django settings
β”‚   β”œβ”€β”€ urls.py            # URL routing
β”‚   β”œβ”€β”€ wsgi.py            # WSGI for production
β”‚   β”œβ”€β”€ asgi.py            # ASGI for WebSockets
β”‚   └── celery.py          # Celery configuration
β”‚
β”œβ”€β”€ apps/                   # Django applications
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── urls.py            # API endpoint routing
β”‚
β”œβ”€β”€ tests/                  # Test suite
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── conftest.py        # Pytest configuration
β”‚
β”œβ”€β”€ fixtures/              # Database fixtures
β”‚
β”œβ”€β”€ static/                # Static files (CSS, JS, images)
β”œβ”€β”€ media/                 # User-uploaded media
β”œβ”€β”€ logs/                  # Application logs
β”‚
β”œβ”€β”€ manage.py              # Django management script
β”œβ”€β”€ pyproject.toml         # Project metadata & dependencies
β”œβ”€β”€ requirements.txt       # Python dependencies
β”œβ”€β”€ .env.example           # Environment variables template
β”œβ”€β”€ docker-compose.yml     # Docker Compose configuration
β”œβ”€β”€ Dockerfile             # Docker image definition
β”œβ”€β”€ .gitignore             # Git ignore rules
└── README.md              # This file

πŸ›  Development Commands

Django Management

# Make migrations
python manage.py makemigrations

# Apply migrations
python manage.py migrate

# Create superuser
python manage.py createsuperuser

# Load fixtures
python manage.py loaddata fixtures/initial_data.json

# Collect static files
python manage.py collectstatic

Testing

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ -v --cov=. --cov-report=html

# Run specific test file
pytest tests/test_users.py -v

# Run with markers
pytest -v -m "smoke"

Code Quality

# Lint with Ruff
ruff check . --fix

# Format with Ruff
ruff format .

# Type check with mypy
mypy apps config

Docker Management

# Start services
docker compose up -d

# Stop services
docker compose down

# View logs
docker compose logs -f

# Run command in container
docker compose exec web python manage.py migrate

Celery (Background Tasks)

# Start worker
celery -A config worker --loglevel=info

# Start beat scheduler
celery -A config beat --loglevel=info

# With Docker
docker compose up -d celery celery-beat

πŸ“ API Endpoints

Authentication

POST   /api/v1/token/              - Get JWT token
POST   /api/v1/token/refresh/      - Refresh token

Documentation

GET    /api/schema/                - OpenAPI schema
GET    /api/docs/                  - Swagger UI

Add your app-specific endpoints in apps/urls.py.

πŸ”’ Security

Security is built-in with:

  • CSRF protection
  • CORS configuration
  • Secure headers (HSTS, CSP, X-Frame-Options)
  • JWT authentication
  • SQL injection prevention (parameterized queries)
  • Input validation

Review config/settings.py for production security settings.

πŸ“Š Logging

Application logs are stored in logs/django.log. Logging is configured in settings.py with:

  • Console output for development
  • Rotating file handler for production
  • Structured logging for errors and requests

🐳 Docker Deployment

Build Image

docker build -t project-horizon:latest .

Run Container

docker run -p 8000:8000 -e DEBUG=False project-horizon:latest

πŸ“¦ Dependencies

Key dependencies are listed in pyproject.toml:

  • Django & DRF
  • JWT authentication
  • PostgreSQL driver
  • Redis client
  • Celery
  • API documentation tools

See pyproject.toml for complete list including dev dependencies.

πŸ§ͺ Testing

Tests are configured with pytest. Example test structure:

# tests/test_example.py
import pytest
from django.test import Client

@pytest.mark.django_db
def test_api_endpoint():
    client = Client()
    response = client.get('/api/v1/example/')
    assert response.status_code == 200

🀝 Contributing

  1. Create a feature branch: git checkout -b feature/your-feature
  2. Write tests for your changes
  3. Format code: ruff format .
  4. Lint: ruff check . --fix
  5. Run tests: pytest tests/
  6. Commit: git commit -am "feat: your feature"
  7. Push: git push origin feature/your-feature
  8. Create a Pull Request

πŸ“„ License

MIT License - See LICENSE file for details

πŸ‘₯ Team

KLWS Affiliate Program

πŸ“ž Support

For issues and questions, open a GitHub issue or contact the team.


Happy coding! πŸŽ‰

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages