Skip to content

Releases: bozimmerman/codephacts

Release 1.0.1

05 Dec 01:31

Choose a tag to compare

Fixed the schema file.

Release 1.0.0

03 Dec 19:23

Choose a tag to compare

CodePhacts

Overview

CodePhacts is a PHP-based web application alternative to tokei/cloc/sloc that analyzes source
code repositories (Git and SVN) to give you historical commit tracking, cyclomatic & cognitive
complexity, weighted LOC, and built-in COCOMO/SLIM/Putnam/Function Point cost estimation.

Key Features

  • Multi-Language Support: Analyzes 30+ programming languages including Java, C/C++, Python, JavaScript, PHP, Assembly, and more
  • Repository Integration: Direct integration with Git and SVN repositories
  • Historical Tracking: Tracks code evolution through commits, files, and code lines over time
  • Cost Estimation Models: Five estimation models with comparative analysis
  • Visual Analytics: Interactive charts showing code growth, composition, and commit activity
  • Project Management: Multi-project support with individual statistics and reporting
  • Flexible Exclusions: Configurable directory exclusions (e.g., node_modules, vendor)
  • Code Complexity: Show Cognitive and Cyclomatic complexity by language and graphed
  • Code Weights: Show weighted lines of code, and weighted code 'statement' charts and graphs
  • Contributors: Show commits and code statistics broken down by various contributors
    Screenshot of project page

Installation

Prerequisites

  • PHP 7.4 or higher
  • Git and/or SVN command-line tools (depending on your repositories)
  • Web server (Caddy, Apache, Nginx, or similar)

Running in Docker (from Dockerhub)

docker run -d \
  -p 8088:8088 \
  -v codephacts_data:/app/data \
  -e ADMIN_PASSWORD=whatever \
  bozimmerman/codephacts:latest

Manual Setup Steps

  1. Clone or download the CodePhacts repository to your web server directory

  2. Configure the application by editing conphig.php:

   return [
       // IMPORTANT: Change this password immediately!
       'admin_password' => 'put-your-admin-password-here---this-is-not-the-default',
       
      'db' => [
        'type'     => 'sqlite', // sqlite or mysql
        'host'     => 'localhost',        // MySQL host
        'port'     => 3306,               // Optional: MySQL port
        'name'     => 'codephacts',      // Database name
        'user'     => 'root',           // DB username
        'pass'     => 'secretpassword',   // DB password
        'charset'  => 'utf8',          // Recommended charset
        'path'     => __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'codephacts.db', // sql lite path
      ],
       
       // How long to wait (in seconds) before reprocessing a commit
       'stale_timeout' => 1000,
       
         // Languages to not count as 'code' for 'Code Line' counting.
        "not_code_lines" => ["text", "xml", "json", "css", "html", "properties"],
        
         // Languages to not count as 'code' for 'Code Statement' counting.
        "not_code_statements" => [],
       
       'tables' => [
           'projects'   => 'projects',
           'statistics' => 'statistics',
           'commits'    => 'commits'
       ]
   ];
  1. Set proper permissions:
   chmod 755 admin/
   chmod 755 public/
   mkdir -p data/
   chmod 755 data/
   chmod 644 conphig.php
  1. Configure your web server to point to the CodePhacts directory. The application entry point is index.php, which redirects to public/index.php.

  2. Verify Git/SVN access: Ensure your web server user has network access and credentials (if needed) to clone/checkout your repositories.

Configuration

Admin Password

CRITICAL: Change the default admin password in conphig.php before deploying:

'admin_password' => 'YourSecurePasswordHere123!',

Database Configuration

Update the database credentials in conphig.php:

    'db' => [
        'type'     => 'sqlite', // sqlite or mysql
        'host'     => 'localhost',        // MySQL host
        'port'     => 3306,               // Optional: MySQL port
        'name'     => 'codephacts',      // Database name
        'user'     => 'root',           // DB username
        'pass'     => 'secretpassword',   // DB password
        'charset'  => 'utf8',          // Recommended charset
        'path'     => __DIR__ . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'codephacts.db', // sql lite path
    ],

Stale Timeout

The stale_timeout setting (in seconds) determines how long before a previously-processed commit can be reprocessed.:

'stale_timeout' => 1000,

Not Code

The not_code_lines setting is a list of languages (see the rules directory) that do not have their lines counted
as "Code Lines". They will still be counted as "Total Lines".

"not_code_lines" => ["text", "xml", "json", "css", "html", "properties"],

The not_code_statements setting is a list of languages (see the rules directory) that do not have their statements
counted as "Code Statements".

"not_code_statements" => [],

Usage

Accessing the Application

  1. Public Interface: Navigate to http://your-domain.com/public/ to view projects and statistics
  2. Admin Interface: Navigate to http://your-domain.com/admin/index.php and log in with your configured password

Adding Projects

  1. Log into the admin panel
  2. Click "Manage Projects"
  3. Click "Add New Project"
  4. Fill in the form:
    • Project Name: A descriptive name
    • Source Type: Git or SVN
    • Repository URL: Full URL to the repository (e.g., https://github.com/user/repo.git)
    • Excluded Directories: Comma-separated paths to exclude (e.g., /vendor,/node_modules,/build)
    • Manager: Optional project manager name
  5. Click "Add Project"

Running Updates

CodePhacts processes commits through the phactor.php script. There are two ways to run updates:

Via Admin Interface

  1. Log into admin panel
  2. Click "Dashboard""Run Update"
  3. Monitor and wait for completion

Via Command Line (Recommended for Cron)

php /path/to/codephacts/phactor.php

Set up automated updates with a cron job:

# Run every hour
0 * * * * cd /path/to/codephacts && php phactor.php >> /var/log/codephacts.log 2>&1

Viewing Statistics

Project View

  • Click any project name to see detailed statistics
  • View language breakdown, code composition, commit history
  • See all five cost estimation models with comparative analysis

Languages View

  • Click "Languages" in the navigation
  • View portfolio-wide statistics aggregated by programming language
  • See cumulative cost estimates across all projects

Query Data

  • Click "Query Data" to filter statistics
  • Select multiple projects and/or languages
  • Apply date ranges for historical analysis
  • Export results for reporting

Supported Languages

CodePhacts analyzes 30+ programming languages:

Compiled: C, C++, C#, Java, Kotlin, Rust, Go, Swift, Scala, Dart
Scripting: PHP, Python, JavaScript, TypeScript, Ruby, Shell, Batch
Assembly: x86, ARM, 6502, and other assembly dialects
Markup: HTML, XML, CSS, JSON
Legacy: BASIC, Visual Basic
Configuration: Properties, INI files
Specialized: QuestMaker scripts, MobProg scripts

Cost Estimation Models

CodePhacts provides five cost estimation models:

1. COCOMO (1981)

Barry Boehm's Constructive Cost Model using empirical coefficients based on project complexity (organic, semi-detached, embedded).

2. COCOMO II (2000)

Updated model incorporating scale factors for modern development practices, reuse, and team dynamics.

3. Function Point Analysis

Technology-independent functional measurement converting LOC to function points based on language-specific ratios.

4. SLIM Model

Software Lifecycle Management model using Rayleigh curves emphasizing optimal resource allocation over time.

5. Putnam Model

Lifecycle prediction model based on the software equation with technology factors and minimum development time constraints.

Each model provides:

  • Effort (person-months)
  • Schedule (months)
  • Team Size (average people)
  • Cost Estimate (at $75/hour by default)

Code Complexity Metrics

CodePhacts tracks two complementary complexity metrics for code quality analysis:

Cyclomatic Complexity

McCabe's cyclomatic complexity measures the number of linearly independent paths through code by counting
decision points (if statements, loops, case statements, logical operators). Higher values indicate more
complex control flow and more test cases needed for full coverage.

Cognitive Complexity

SonarSource's cognitive complexity measures how difficult code is to understand by assigning higher weights to
nested control structures. Unlike cyclomatic complexity, it penalizes deeply nested logic more heavily, better
reflecting the mental effort required to comprehend code.

Code Weighting System

Weighted Lines of Code

CodePhacts applies language-specific multipliers to raw line counts to normalize code volume across different
programming paradigms. For example, assembly code (0.80×) requires more lines to achieve the same functionality
as Python (3.10×), while high-level languages like Scala (2.30×) accomplish more per line than C (1.00×, baseline).

Weighted Code Statements

Statement counts are multiplied by the same language-specific factors to measure actual executable logic rather
than physical lines. This accounts for languages where multiple statements can appear on one line or where single
statements span multiple lines, providing a more accurate measure of code complexity than raw line counts.

QSM Effective Size

The weighted m...

Read more