A modern, lightweight Content Management System (CMS) built with PHP and JavaScript, designed for flexibility and ease of use. This CMS follows SOLID principles and leverages an MVC architecture, utilizing PHP libraries like Laravel's Eloquent ORM, Twig templating, and a simple router, combined with a robust front-end setup using Webpack, Bootstrap, and jQuery.
Current Version: 1.0.0 (SOLID Refactoring Release)
This CMS has been refactored to follow SOLID design principles for better maintainability and testability:
- Single Responsibility Principle (SRP): Each class has one reason to change
- Open/Closed Principle (OCP): Classes are open for extension, closed for modification
- Liskov Substitution Principle (LSP): Subtypes are substitutable for their base types
- Interface Segregation Principle (ISP): Clients depend only on methods they use
- Dependency Inversion Principle (DIP): High-level modules don't depend on low-level modules
The application uses a service layer with dependency injection:
- Services: Business logic separated into focused, testable units
- Interfaces: Define contracts for services, enabling easy mocking and testing
- Dependency Injection: Controllers receive their dependencies through constructors
- Separation of Concerns: Views, business logic, and data access are properly separated
- SOLID Architecture: Clean, maintainable code following SOLID design principles.
- Service Layer: Business logic separated into focused, testable services.
- Dependency Injection: Loose coupling between components for better testability.
- MVC Architecture: Organized structure with Core and App namespaces for clean code separation.
- Database Support: Uses Laravel's Eloquent ORM (
illuminate/database) for database interactions. - Templating: Powered by Twig (
twig/twig) for dynamic and secure template rendering. - Routing: Simple and fast routing with
pecee/simple-router. - Front-End: Built with Bootstrap 5, jQuery, and Webpack for modern, responsive UI.
- Additional Tools:
- PDF generation with
mpdf/mpdf. - Image processing with
spatie/image. - JWT authentication with
firebase/php-jwt. - Environment configuration with
vlucas/phpdotenv.
- PDF generation with
- Development Tools: Includes GrumPHP for code quality, PHPUnit for unit testing, and Webpack for asset bundling.
- PHP 8.1+: PHP version used in the project
- MVC Architecture: Model-View-Controller pattern architecture
- SOLID Principles: Software design principles
- MySQL: Database management system
- Laravel Eloquent ORM (
illuminate/database ^10.0): ORM for database operations
- Pecee Simple Router (
pecee/simple-router ^5.4): Simple and fast router - PHP-DI (
php-di/php-di ^7.0): Dependency injection container
- Twig (
twig/twig ^3.22): Template engine - Twig Cache Extra (
twig/cache-extra ^3.22): Cache extension for Twig - Twig Extra Bundle (
twig/extra-bundle ^3.22): Additional Twig features
- Firebase JWT (
firebase/php-jwt ^6.11): JWT tokens for authorization - Paragonie Sodium Compat (
paragonie/sodium_compat ^2.1): Cryptography
- Spatie Image (
spatie/image ^3.8): Image processing - Intervention Image (
intervention/image ^2.7): Image manipulation
- mPDF (
mpdf/mpdf ^8.2): PDF document generation
- PHP Dotenv (
vlucas/phpdotenv ^5.6): Environment variable management
- PHPUnit (
phpunit/phpunit ^10.0): Unit testing framework - PHPStan (
phpstan/phpstan ^2.1): Static code analysis - PHP CodeSniffer (
squizlabs/php_codesniffer ^4.0): Coding standards compliance analysis - GrumPHP (
phpro/grumphp ^1.0): Code quality automation - PHPUnit Code Coverage (
phpunit/php-code-coverage ^10.1): Code coverage for tests
- Webpack 5 (
webpack ^5.99.9): Module bundler - Babel (
@babel/core ^7.28.0,@babel/preset-env ^7.28.0): JavaScript ES6+ transpilation - Babel Loader (
babel-loader ^10.0.0): Webpack loader for Babel
- Sass (
sass ^1.89.2,sass-embedded ^1.89.2): CSS preprocessor - Sass Loader (
sass-loader ^16.0.5): Webpack loader for Sass - CSS Loader (
css-loader ^7.1.2): CSS processing in Webpack - Style Loader (
style-loader ^4.0.0): Style injection into DOM - Mini CSS Extract Plugin (
mini-css-extract-plugin ^2.9.2): CSS extraction to separate files - CSS Minimizer Webpack Plugin (
css-minimizer-webpack-plugin ^7.0.2): CSS minimization
- Bootstrap 5 (
bootstrap ^5.3.7): CSS framework - jQuery (
jquery ^3.7.1): JavaScript library - jQuery UI (
jquery-ui-dist ^1.13.3): jQuery widgets and interactions
- Bootstrap Icons (
bootstrap-icons ^1.13.1): Bootstrap icon set - Font Awesome (
@fortawesome/fontawesome-free ^7.0.0): Icon library - Bootstrap Iconpicker (
bootstrap-iconpicker ^1.8.2): Icon selector - PluginJS Icon Picker (
@pluginjs/icon-picker ^0.8.18): Alternative icon picker
- CKEditor 5 (
ckeditor5 ^47.0.0): Advanced WYSIWYG editor - Dropzone (
dropzone ^6.0.0-beta.2): File upload with drag & drop
- Bootstrap Table (
bootstrap-table ^1.24.1): Advanced tables - TableDnD (
tablednd ^1.0.5): Drag & drop for tables - DragTable (
dragtable ^2.0.12): Table column reordering - TableExport jQuery Plugin (
tableexport.jquery.plugin ^1.9.9): Table export to various formats
- jsPDF AutoTable (
jspdf-autotable ^5.0.2): PDF generation with tables
- FancyApps UI (
@fancyapps/ui ^6.0.34): UI component library - jQuery Confirm (
jquery-confirm ^3.3.4): Beautiful dialog boxes - Bootstrap Menu Editor (
@maxsoft/bootstrap_menu_editor ^1.0.4): Bootstrap menu editor
- Copy Webpack Plugin (
copy-webpack-plugin ^13.0.0): File copying - Expose Loader (
expose-loader ^5.0.1): Exposing global variables - File Loader (
file-loader ^6.2.0): File handling - Resolve URL Loader (
resolve-url-loader ^5.0.0): URL resolution in CSS - Webpack CLI (
webpack-cli ^6.0.1): Command-line interface for Webpack - Webpack Dev Server (
webpack-dev-server ^5.2.2): Development server with hot reload
- Git: Version control system
- Composer: PHP dependency manager
- npm: Node.js package manager
- Webpack Dev Server: Development server with automatic reload
Before setting up the project, ensure you have the following installed:
- PHP: 8.1 or higher
- Composer: For PHP dependency management
- Node.js: 16.x or higher
- npm: For JavaScript dependency management
- MySQL: For database storage
- Git: For cloning the repository
Follow these steps to set up the CMS locally:
-
Clone the Repository:
git clone https://github.com/gmaxsoft/cms.git cd cms -
Install PHP Dependencies: Run the following command to install the required PHP packages:
composer install
-
Install JavaScript Dependencies: Install front-end dependencies using npm:
npm install
-
Set Up Environment: Copy the
.env.examplefile (if available) to.envand configure your environment variables:cp .env.example .env
Update the
.envfile with your database credentials and other settings. Example configuration:DEBUG=true DEFAULT_BLOCK_LANG=1 DB_DRIVER=mysql DB_HOST=localhost DB_NAME=YOUR OWN DATABASE NAME DB_USER=root DB_PASS= FRONTEND_URL=http://localhost:3000 SECRET_KEY=your-secure-secret-key DEFAULT_BLOCK_LANG = 1 SLIDERFILESPATH = 'upload/sliderImg/'
-
Set Up the Database: Create a MySQL database named
YOUR OWN DATABASE NAME(or your preferred name, matching theDB_NAMEin.env). To start the database installation process, enterhttp://localhost:3000/install.php. Follow the instructions. -
Build Front-End Assets: Compile and bundle the front-end assets using Webpack:
npm run build
-
Start the Development Server: Start the Webpack development server for front-end development:
npm run dev
Alternatively, serve the PHP application using a local server (e.g., PHP's built-in server):
php -S localhost:8000 -t public
-
Access the CMS: Open your browser and navigate to
http://localhost:3000for the front-end orhttp://localhost:8000for the PHP server, depending on your setup.
- Admin Panel: Access the CMS admin panel (if implemented) via the configured
FRONTEND_URL. - Customizing Templates: Modify Twig templates in the
app/viewsdirectory (assumed based on standard MVC structure). - Adding Routes: Define custom routes in the
appdirectory usingpecee/simple-router. - Asset Management: Update SCSS files in
public/scssor JavaScript files inpublic/jsand rebuild assets withnpm run build.
cms/
├── app/ # Application logic
│ ├── Controllers/ # HTTP request handlers (uses services)
│ ├── Models/ # Eloquent ORM models
│ ├── Services/ # Business logic services
│ │ ├── Interfaces/ # Service contracts (SOLID interfaces)
│ │ ├── *.php # Service implementations
│ └── Views/ # Twig templates
├── core/ # Core CMS functionality (refactored with SOLID)
├── public/ # Publicly accessible files
│ ├── js/ # JavaScript source files
│ ├── scss/ # SCSS source files
├── dist/ # Compiled front-end assets
├── vendor/ # Composer dependencies
├── node_modules/ # npm dependencies
├── .env # Environment configuration
├── composer.json # PHP dependencies
├── package.json # JavaScript dependencies
├── webpack.config.js # Webpack configuration
└── README.md # Project documentation
- SliderService: CRUD operations for sliders
- SliderFileService: File management and image processing
- SliderConfigService: Configuration management
- ImageProcessor: Image manipulation and optimization
- FileUploadService: File validation and upload handling
- LanguageService: Multi-language support
- TextUtilities: Text processing utilities
- TemplateRenderer: Twig template rendering
Controllers receive services through constructor injection, enabling:
- Easy unit testing with mocks
- Loose coupling between components
- Flexible service implementations
- Better separation of concerns
- Testability: Each service can be tested in isolation
- Maintainability: Changes are localized to specific services
- Extensibility: New features can be added without modifying existing code
- Readability: Clear separation of responsibilities
- Reusability: Services can be reused across different controllers
This project includes comprehensive unit tests powered by PHPUnit 11 to ensure SOLID principles compliance and code quality.
tests/
├── bootstrap.php # Test environment setup
├── Unit/
│ ├── Services/ # Service layer tests
│ │ ├── SliderServiceTest.php
│ │ ├── TextUtilitiesTest.php
│ │ └── FileUploadServiceTest.php
│ └── Controllers/ # Controller tests with mocks
│ └── SliderControllerTest.php
- Service Layer: Business logic testing with isolated units
- Controller Layer: HTTP request/response testing with mocked dependencies
- Validation: Input validation and error handling
- Integration: Service interaction testing
- Mock Objects: PHPUnit mocks for dependency isolation
- Data Providers: Parameterized tests for comprehensive coverage
- Test Doubles: Stubs and mocks for external dependencies
- Assertion Methods: Rich set of assertions for behavior verification
- Code Quality: Use GrumPHP for automated code quality checks:
composer run-script grumphp
- Unit Testing: Run PHPUnit tests to ensure SOLID compliance:
./vendor/bin/phpunit
- Test Coverage: Generate coverage report:
./vendor/bin/phpunit --coverage-html reports/
- Run Specific Tests: Execute tests for specific components:
# Test services only ./vendor/bin/phpunit tests/Unit/Services/ # Test controllers only ./vendor/bin/phpunit tests/Unit/Controllers/ # Test single file ./vendor/bin/phpunit tests/Unit/Services/SliderServiceTest.php
- Continuous Integration: Automated testing via GitHub Actions:
- Tests run automatically on push/PR to
masteranddevelopment - Code coverage reports uploaded to Codecov
- Security scans performed weekly
- Code quality checks with PHPStan and PHPCS
- Tests run automatically on push/PR to
- Front-End Development: Run
npm run devfor live reloading during development. - Production Build: Generate optimized assets for production:
npm run build
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature). - Make your changes and commit (
git commit -m 'Add your feature'). - Push to the branch (
git push origin feature/your-feature). - Open a pull request on GitHub.
Report bugs or suggest features via the GitHub Issues page.
This project is licensed under the ISC License. See the LICENSE file for details.
For questions or support, contact the author:
- Name: Maxsoft
- Email: 133238725+gmaxsoft@users.noreply.github.com
- GitHub: gmaxsoft