Skip to content

SecCodeSmith/SecCodeSmith-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

162 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SecCodeSmith Backend

CI/CD Pipeline Python 3.10+ Django 5.2+ Django REST Framework PostgreSQL Redis Docker codecov License: MIT Code style: black Imports: isort Security: bandit

This repository contains the Django-powered REST API backend for the SecCodeSmith portfolio website. It provides endpoints for blog posts, project showcases, image properties, and static page content (About, Contact, Skills, Footer Links).

Table of Contents


About

SecCodeSmith Backend serves as the data layer for the portfolio site, supplying JSON over REST endpoints that the front-end consumes for dynamic content. The API is built with Django and Django REST Framework, providing a robust and scalable foundation for the portfolio website.


Features

  • πŸ”₯ Blog Posts: List, paginate, and count pages of blog entries
  • πŸš€ Project Showcase: List projects, view details, and filter by category
  • πŸ–ΌοΈ Image Properties: Serve metadata for portfolio images
  • πŸ“„ Static Pages: Endpoints for About, Contact, Skills, and Footer Links content
  • πŸ”’ CSRF Support: Retrieve CSRF tokens for secure front-end forms
  • πŸ‘¨β€πŸ’Ό Admin Interface: Built-in Django admin at /admin/
  • πŸ§ͺ Comprehensive Testing: Unit tests with pytest and Django TestCase
  • πŸ” Code Quality: Automated linting, formatting, and security checks
  • 🐳 Docker Support: Containerized deployment ready
  • ⚑ Caching: Redis-based caching for improved performance

Tech Stack

  • 🐍 Python 3.10+
  • 🌐 Django 5.2.1
  • πŸ“‘ Django REST Framework 3.16.0
  • πŸ—ƒοΈ PostgreSQL (Production) / SQLite (Development)
  • πŸ”΄ Redis for caching
  • πŸ§ͺ pytest for testing
  • πŸ” flake8, black, isort for code quality
  • πŸ›‘οΈ bandit, safety for security scanning
  • 🐳 Docker for containerization

Requirements

  • Python 3.10 or later
  • pip (Python package installer)
  • Redis (for caching)
  • PostgreSQL (optional, for production)

Quick Start

Get up and running in less than 5 minutes:

Linux/macOS:

# Clone the repository
git clone https://github.com/SecCodeSmith/SecCodeSmith-backend.git
cd SecCodeSmith-backend

# Make script executable and setup
chmod +x dev.sh
./dev.sh setup

# Start the server
./dev.sh runserver

Windows:

# Clone the repository
git clone https://github.com/SecCodeSmith/SecCodeSmith-backend.git
cd SecCodeSmith-backend

# Setup environment
dev.bat setup

# Start the server
dev.bat runserver

Using Make (Linux/macOS):

# Setup development environment
make setup

# Start the server
make runserver

The API will be available at http://127.0.0.1:8000/

🎯 Development Scripts

This project includes convenient development scripts:

  • Linux/macOS: ./dev.sh [command]
  • Windows: dev.bat [command]
  • Make: make [target] (Linux/macOS only)

Available commands:

  • setup - Complete development environment setup
  • test - Run test suite
  • lint - Run code quality checks
  • format - Format code with black and isort
  • runserver - Start Django development server
  • migrate - Run database migrations
  • security - Run security scans

Installation

1. Clone the Repository

git clone https://github.com/SecCodeSmith/SecCodeSmith-backend.git
cd SecCodeSmith-backend

2. Set Up Virtual Environment

Linux/macOS:

python -m venv .venv
source .venv/bin/activate

Windows:

python -m venv .venv
.venv\Scripts\activate

3. Install Dependencies

pip install --upgrade pip
pip install -r requirements.txt

4. Set Up Environment Variables (Optional)

Create a .env file in the project root:

# Django Settings
SECRET_KEY=your_super_secret_key_here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1

# Database (Optional - defaults to SQLite)
DATABASE_TYPE=sqlite  # or 'pgsql' for PostgreSQL
DATABASE_USER=postgres
DATABASE_PASSWORD=your_password
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=seccodesmithbackend

# Redis (Optional - uses fakeredis for development)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0

# Email (Optional)
EMAIL_HOST=smtp.gmail.com
EMAIL_USER=your_email@gmail.com
EMAIL_PASSWORD=your_app_password
EMAIL_USE_TLS=True
EMAIL_SMTP_PORT=587

5. Run Database Migrations

python manage.py migrate

6. Create Superuser (Optional)

python manage.py createsuperuser

Configuration

The project uses environment variables for configuration via django-environ. Create a .env file to override default settings:

Database Configuration

SQLite (Default - Development):

DATABASE_TYPE=sqlite

PostgreSQL (Production):

DATABASE_TYPE=pgsql
DATABASE_USER=postgres
DATABASE_PASSWORD=your_password
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=seccodesmithbackend

Caching Configuration

Development (FakeRedis): No configuration needed - uses in-memory caching.

Production (Redis):

REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=your_redis_password

Running the Server

Development Server

python manage.py runserver

The API will be available at http://127.0.0.1:8000/

Available Endpoints

  • API Root: http://127.0.0.1:8000/api/
  • Admin Panel: http://127.0.0.1:8000/admin/
  • Blog API: http://127.0.0.1:8000/blog-api/
  • Project API: http://127.0.0.1:8000/project-api/
  • Images API: http://127.0.0.1:8000/img/

Testing

Run All Tests

# Using pytest (recommended)
pytest

# Using Django test runner
python manage.py test

Run Specific Tests

# Test specific app
pytest api/test.py

# Test specific test class
pytest api/test.py::SkillCardsViewTests

# Test with verbose output
pytest -v

# Test with coverage
pytest --cov=.

Test Configuration

Tests are configured to use:

  • In-memory SQLite database
  • Local memory cache
  • Isolated test environment

Code Quality

This project maintains high code quality through automated tools:

Linting and Formatting

# Check code style
flake8 .

# Format code
black .

# Sort imports
isort .

# Run all checks
flake8 . && black --check . && isort --check-only .

Security Scanning

# Scan for security issues
bandit -r .

# Check for vulnerable dependencies
safety check

Docker Support

Build and Run with Docker

# Build the image
docker build -t seccodesmithbackend .

# Run the container
docker run -p 8000:8000 seccodesmithbackend

Docker Compose (with PostgreSQL and Redis)

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

VS Code Setup

This project is optimized for Visual Studio Code with comprehensive configuration:

πŸš€ Quick Setup

  1. Open the workspace: Use SecCodeSmith-backend.code-workspace
  2. Install recommended extensions: VS Code will prompt you automatically
  3. Select Python interpreter: Choose .venv/bin/python when prompted

πŸ”§ Pre-configured Features

  • Debugging: Ready-to-use debug configurations for Django
  • Testing: Integrated pytest runner with coverage
  • Linting: Automated code quality checks
  • Formatting: Auto-format on save with Black
  • Tasks: One-click Django commands (F1 β†’ "Tasks: Run Task")

πŸ“‹ Available Debug Configurations

  • Django: Run Server - Start development server with debugging
  • Django: Run Tests - Run test suite with debugging
  • Django: Shell - Open Django shell with debugging
  • Django: Migrate - Run migrations
  • Django: Make Migrations - Create new migrations

⚑ VS Code Tasks

Access via Ctrl+Shift+P β†’ "Tasks: Run Task":

  • Django: Run Server
  • Django: Run Tests (with coverage)
  • Code Quality: Lint/Format
  • Security: Scan with Bandit
  • Install Dependencies

API Reference

General API

Base path: /api/

Endpoint Method Description
/api/csrf GET Retrieve CSRF token
/api/skills-cards GET List skill cards for front-end display
/api/about/ GET Get content for the β€œAbout” page
/api/footer-links GET List social/footer links
/api/contact/ GET Get content for the β€œContact” page

Blog API

Base path: /blog-api/

Endpoint Method Description
/blog-api/post/ GET List all blog posts
/blog-api/count_pages/ GET Retrieve total number of paginated pages
/blog-api/post-page/?page=<n> GET List posts on page <n>

Project API

Base path: /project-api/

Endpoint Method Description
/project-api/projects/ GET List all projects
/project-api/projects/<id>/ GET Get details for project with ID <id>
/project-api/cat GET List available project categories

Images API

Base path: /img/

Endpoint Method Description
/img/Image/<id>/ GET Retrieve properties (metadata) for image <id>

Contributing

We welcome contributions! Please follow these steps:

1. Fork and Clone

git clone https://github.com/your-username/SecCodeSmith-backend.git
cd SecCodeSmith-backend

2. Create Feature Branch

git checkout -b feature/your-feature-name

3. Set Up Development Environment

python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python manage.py migrate

4. Make Changes and Test

# Run tests
pytest

# Check code quality
flake8 .
black --check .
isort --check-only .

# Run security checks
bandit -r .
safety check

5. Commit and Push

git add .
git commit -m "Add your descriptive commit message"
git push origin feature/your-feature-name

6. Create Pull Request

Open a Pull Request on GitHub with:

  • Clear description of changes
  • Reference to any related issues
  • Screenshots if applicable

Code Style Guidelines

  • Follow PEP 8 (enforced by flake8)
  • Use Black for code formatting
  • Sort imports with isort
  • Write comprehensive tests for new features
  • Add docstrings for complex functions
  • Keep line length under 127 characters

CI/CD Pipeline

This project uses GitHub Actions for continuous integration and deployment:

Automated Checks

Every push and pull request triggers:

πŸ§ͺ Testing Pipeline:

  • Tests on Python 3.10, 3.11, and 3.12
  • PostgreSQL and Redis service containers
  • Full test suite execution with pytest
  • Django system checks
  • Code coverage reporting with Codecov

πŸ” Code Quality Pipeline:

  • Linting with flake8
  • Code formatting check with black
  • Import sorting check with isort

πŸ›‘οΈ Security Pipeline:

  • Security vulnerability scanning with bandit
  • Dependency vulnerability check with safety
  • Semgrep static analysis

πŸ€– AI-Powered Review Pipeline:

  • GitHub Copilot code review on PRs
  • Automated code suggestions and improvements
  • Django-specific best practices analysis
  • Performance optimization recommendations
  • Type checking with mypy

🐳 Docker Pipeline:

  • Docker image build and test (on main branch)

Status Badges

The README includes badges showing:

  • βœ… CI/CD pipeline status
  • 🐍 Python version compatibility
  • 🌐 Django version
  • πŸ“œ License information
  • πŸ“Š Code coverage percentage

Automated Code Review

  • πŸ€– GitHub Copilot: Automated code review for PRs
  • πŸ’‘ AI Suggestions: Performance and best practices recommendations
  • πŸ” Code Analysis: Static analysis with pylint, mypy, and vulture
  • πŸ›‘οΈ Security Scanning: Comprehensive security analysis

Branch Protection

  • main and develop branches require:
    • Passing CI checks
    • Code review approval
    • Up-to-date branches

License

This project is licensed under the MIT License. See the LICENSE file for details.


Contact


Acknowledgments

About

This is (optional) backend for my portfolio page

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •