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.
- 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

- PHP 7.4 or higher
- Git and/or SVN command-line tools (depending on your repositories)
- Web server (Caddy, Apache, Nginx, or similar)
docker run -d \
-p 8088:8088 \
-v codephacts_data:/app/data \
-e ADMIN_PASSWORD=whatever \
bozimmerman/codephacts:latest
-
Clone or download the CodePhacts repository to your web server directory
-
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'
]
];- Set proper permissions:
chmod 755 admin/
chmod 755 public/
mkdir -p data/
chmod 755 data/
chmod 644 conphig.php-
Configure your web server to point to the CodePhacts directory. The application entry point is
index.php, which redirects topublic/index.php. -
Verify Git/SVN access: Ensure your web server user has network access and credentials (if needed) to clone/checkout your repositories.
CRITICAL: Change the default admin password in conphig.php before deploying:
'admin_password' => 'YourSecurePasswordHere123!',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
],The stale_timeout setting (in seconds) determines how long before a previously-processed commit can be reprocessed.:
'stale_timeout' => 1000,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" => [],- Public Interface: Navigate to
http://your-domain.com/public/to view projects and statistics - Admin Interface: Navigate to
http://your-domain.com/admin/index.phpand log in with your configured password
- Log into the admin panel
- Click "Manage Projects"
- Click "Add New Project"
- 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
- Click "Add Project"
CodePhacts processes commits through the phactor.php script. There are two ways to run updates:
- Log into admin panel
- Click "Dashboard" → "Run Update"
- Monitor and wait for completion
php /path/to/codephacts/phactor.phpSet up automated updates with a cron job:
# Run every hour
0 * * * * cd /path/to/codephacts && php phactor.php >> /var/log/codephacts.log 2>&1- Click any project name to see detailed statistics
- View language breakdown, code composition, commit history
- See all five cost estimation models with comparative analysis
- Click "Languages" in the navigation
- View portfolio-wide statistics aggregated by programming language
- See cumulative cost estimates across all projects
- Click "Query Data" to filter statistics
- Select multiple projects and/or languages
- Apply date ranges for historical analysis
- Export results for reporting
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
CodePhacts provides five cost estimation models:
Barry Boehm's Constructive Cost Model using empirical coefficients based on project complexity (organic, semi-detached, embedded).
Updated model incorporating scale factors for modern development practices, reuse, and team dynamics.
Technology-independent functional measurement converting LOC to function points based on language-specific ratios.
Software Lifecycle Management model using Rayleigh curves emphasizing optimal resource allocation over time.
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)
CodePhacts tracks two complementary complexity metrics for code quality analysis:
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.
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.
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).
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.
The weighted metrics approximate QSM (Quantitative Software Management) effective size calculations, which normalize code volume across languages for more accurate effort estimation. These weights are derived from empirical studies of language expressiveness and productivity factors.
codephacts/
├── admin/ # Admin panel files
│ ├── auth.php # Authentication handler
│ ├── edit-project.php # Project editor
│ ├── index.php # Admin dashboard
│ ├── login.php # Login page
│ ├── logout.php # Logout page
│ ├── projects.php # Project management
│ └── run-update.php # Manual update viewer
├── public/ # Public-facing pages
│ ├── contributors.php# Contributors page
│ ├── index.php # Project listing
│ ├── languages.php # Language statistics
│ ├── project.php # Individual project view
│ ├── query.php # Data query interface
│ └── style.css # Stylesheet
├── rules/ # Language analysis rules
│ ├── c.php
│ ├── java.php
│ ├── python.php
│ └── ...
├── images/ # Logo and assets
├── conphig.php # Configuration file
├── phactor.php # Main processing script
├── schema.sql # Database schema
└── index.php # Entry point (redirects to public/)
- Change the default admin password immediately in
conphig.php - Protect
conphig.phpfrom web access (use.htaccessor server config) - Run
phactor.phpvia command line with appropriate system user permissions - Use HTTPS in production environments
- Restrict database user permissions to only the
codephactsdatabase - Consider IP restrictions for the admin panel in production
- Verify Git/SVN is installed and in PATH
- Check repository URL is correct and accessible
- Ensure web server user has network access
- For private repos, configure SSH keys or credentials
- Verify database credentials in
conphig.php - Ensure MySQL/MariaDB is running
- Check that the
codephactsdatabase exists - Verify user has appropriate permissions
- Increase PHP
max_execution_timein php.ini for large repositories - Run
phactor.phpfrom command line instead of web interface - Check system resources (disk space, memory)
- Review excluded directories to skip large folders
- Ensure the file extension is supported (check
rules/directory) - Verify files aren't in excluded directories
- Check for proper commit processing in the database
Copyright 2025 Bo Zimmerman
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
To add support for additional programming languages:
- Create a new rule file in
rules/directory (e.g.,rules/mylang.php) - Follow the existing rule file structure with
extensions,language, andanalyzerkeys - Implement optional
detectorfunction for multi-language file detection - Test with sample code in your language
For issues, questions, or contributions, please contact the project maintainer.