Implementation Timeline
This page documents the chronological order in which the CI4 Modern Architecture was built. Understanding this sequence helps you see how the pieces connect and provides a roadmap for building your own projects.
Table of Contents
- Overview Diagram
- Phase 1: Foundation
- Phase 2: Attribute Routing
- Phase 3: Domain Layer
- Phase 4: Infrastructure
- Phase 5: Modules
- Phase 6: View Components
- Phase 7: Monitoring
- Phase 8: Documentation
- Phase 9: Optimizations & Fixes
- Phase 10: Security & Auth
- Phase 11: Feature Expansion
- Docker Verification
1. Overview Diagram
2. Phase 1: Foundation
Goal: Set up development environment and base project.
| Step | What Was Created | Purpose |
|---|---|---|
| 1.1 | docker-compose.yml | Define PHP, Nginx, MySQL, Redis containers |
| 1.2 | docker/php/Dockerfile | PHP 8.2 with extensions (redis, opcache, etc.) |
| 1.3 | docker/nginx/nginx.conf | Nginx configuration for CI4 |
| 1.4 | CI4 Installation | composer create-project codeigniter4/appstarter |
| 1.5 | Folder structure | Created Domain/, Infrastructure/, Modules/ |
Verification Command
# Start Docker environment
docker-compose up -d
# Check containers are running
docker-compose ps
# Expected: php, nginx, mysql, redis all "Up"3. Phase 2: Attribute Routing
Goal: Enable declarative routing with PHP 8 Attributes.
| Step | File Created | Purpose |
|---|---|---|
| 2.1 | app/Attributes/Route.php | Define #[Route] attribute class |
| 2.2 | app/Attributes/Middleware.php | Define #[Middleware] attribute class |
| 2.3 | app/Core/Routing/RouteScanner.php | Scan controllers for attributes |
| 2.4 | app/Core/Routing/RouteCache.php | Cache discovered routes |
| 2.5 | app/Core/Routing/ModuleChangeDetector.php | Invalidate cache on file changes |
| 2.6 | Updated Config/Routes.php | Call RouteScanner::scan() |
Verification Command
# List all registered routes
docker-compose exec php php spark routes
# Should show routes from #[Route] attributes4. Phase 3: Domain Layer
Goal: Create pure business logic with no framework dependencies.
| Step | File Created | Purpose |
|---|---|---|
| 3.1 | Domain/User/Entities/User.php | Core User entity with business methods |
| 3.2 | Domain/Shared/ValueObjects/Email.php | Email validation in one place |
| 3.3 | Domain/User/Repositories/UserRepositoryInterface.php | Data access contract |
| 3.4 | Domain/User/Services/UserService.php | Business operations |
| 3.5 | Domain/User/Policies/PasswordPolicy.php | Password validation rules |
| 3.6 | Domain/User/Exceptions/*.php | Domain-specific exceptions |
Verification Command
# Test EmailValue Object
docker-compose exec php php spark tinker
> $email = new \App\Domain\Shared\ValueObjects\Email('TEST@EXAMPLE.COM');
> echo $email->getValue(); // "test@example.com"5. Phase 4: Infrastructure
Goal: Implement interfaces defined in Domain.
| Step | File Created | Purpose |
|---|---|---|
| 4.1 | Infrastructure/Persistence/UserRepository.php | MySQL implementation of UserRepositoryInterface |
| 4.2 | Infrastructure/Cache/RedisCache.php | Redis caching adapter |
Verification Command
# Test Redis connection
docker-compose exec redis redis-cli PING
# Output: PONG6. Phase 5: Modules
Goal: Create self-contained feature packages.
| Step | Module | Features |
|---|---|---|
| 5.1 | Modules/Admin/ | Dashboard, User Management |
| 5.2 | Modules/Web/ | Home, About, Contact, Docs |
| 5.3 | Modules/Member/ | Member dashboard, Profile |
| 5.4 | Modules/Api/ | REST API endpoints, Metrics |
Verification Command
# List modules
docker-compose exec php ls /var/www/html/app/Modules/
# Output: Admin Api Member Web7. Phase 6: View Components
Goal: Create reusable UI building blocks.
| Step | File Created | Purpose |
|---|---|---|
| 6.1 | Layouts (admin, public, member) | Base templates for each module |
| 6.2 | sidebar.php | Navigation sidebar |
| 6.3 | header.php | Page header with user menu |
| 6.4 | stat_card.php | Dashboard statistics card |
| 6.5 | JavaScript components | Sidebar toggle, Dropdown, Modal |
Verification Command
# Check component files exist
docker-compose exec php ls /var/www/html/app/Modules/Admin/Shared/Components/8. Phase 7: Monitoring & Observability
Goal: Built-in performance tracking and tracing.
| Step | File Created | Purpose |
|---|---|---|
| 7.1 | app/Attributes/Trace.php | Distributed tracing attribute |
| 7.2 | app/Attributes/Monitor.php | Performance monitoring attribute |
| 7.3 | Core/Monitoring/Profiling/ServiceProfiler.php | Timing and memory collection |
| 7.4 | Core/Monitoring/Tracing/SpanManager.php | Trace span management |
| 7.5 | Core/Monitoring/Metrics/MetricCollector.php | Prometheus-style metrics |
| 7.6 | Core/Monitoring/Export/PrometheusExporter.php | Prometheus text format export |
| 7.7 | Infrastructure/Monitoring/RedisMetricStorage.php | Short-term Redis storage |
| 7.8 | Infrastructure/Monitoring/MySQLMetricStorage.php | Long-term MySQL storage |
| 7.9 | app/Filters/TracingFilter.php | Request tracing filter |
| 7.10 | app/Filters/PerformanceFilter.php | Request performance filter |
| 7.11 | app/Commands/MonitorAnalyze.php | CLI hotspot analysis |
| 7.12 | app/Commands/MonitorFlush.php | Redis → MySQL sync CLI |
| 7.13 | Modules/Api/Controllers/MetricsController.php | /metrics endpoint |
| 7.14 | docker/grafana/dashboards/ci4_dashboard.json | Pre-built Grafana dashboard |
| 7.15 | Database/Migrations/*_CreatePerformanceLogsTable.php | MySQL table for long-term storage |
Verification Commands
# Fetch Prometheus metrics
curl http://localhost:81/metrics
# Analyze performance
docker-compose exec php php spark monitor:analyze
# Check Redis keys
docker-compose exec redis redis-cli KEYS "perf:*"9. Phase 8: Documentation
Goal: Self-documenting application with web-based guide.
| Step | What Was Created |
|---|---|
| 8.1 | Markdown docs in docs/ folder |
| 8.2 | Modules/Web/Docs/ — Web-based documentation module |
| 8.3 | DocsController.php — Routes for all doc pages |
| 8.4 | Layouts/docs.php — CI4-style layout |
| 8.5 | 10 View files for each topic |
Verification Command
# Access documentation
curl http://localhost:81/docs
# Check all doc pages exist
docker-compose exec php ls /var/www/html/app/Modules/Web/Docs/Views/10. Phase 9: Optimizations & Fixes
Goal: Improve performance and stability.
| Step | Action | Details |
|---|---|---|
| 9.1 | Performance Optimization | Resolved N+1 query issues in register_courses and courses methods |
| 9.2 | Session Management | Fixed intermittent logout and token errors |
| 9.3 | PDF Generation | Fixed Cashflow and Balance Report PDF rendering issues |
11. Phase 10: Security & Auth
Goal: Secure the application and environment.
| Step | Action | Details |
|---|---|---|
| 10.1 | Malicious Code Removal | Identified and removed obfuscated scripts and backdoors |
| 10.2 | Docker Security | Hardened container configurations |
| 10.3 | Access Control | Refined role-based access for Admin, Member, and Public users |
12. Phase 11: Feature Expansion
Goal: Enhance UI/UX and Documentation.
| Step | Feature | Details |
|---|---|---|
| 11.1 | Notification Media | Added support for image/file attachments in notifications |
| 11.2 | Component Library | Integrated FilePond (uploads), GLightbox (zoom), Trumbowyg (editor) |
| 11.3 | AJAX Components | Implemented partial page rendering, auto-refresh polling, and AJAX-based Notification List |
| 11.4 | Documentation Module | Added dedicated pages for Component Library, Notifications, RBAC, and Logging |
13. Docker Verification
Complete System Check
# 1. Check all containers running
docker-compose ps
# 2. Check PHP extensions
docker-compose exec php php -m | grep -E "(redis|pdo_mysql)"
# 3. Check routes registered
docker-compose exec php php spark routes | wc -l
# 4. Check database connection
docker-compose exec php php spark db:table users
# 5. Check Redis connection
docker-compose exec redis redis-cli PING
# 6. Check metrics endpoint
curl -s http://localhost:81/metrics | head -20
# 7. Check documentation
curl -s http://localhost:81/docs | grep -o "<h1>.*</h1>"File Count Summary
# Count files in each major area
docker-compose exec php bash -c "
echo 'Attributes: ' && find /var/www/html/app/Attributes -name '*.php' | wc -l
echo 'Core: ' && find /var/www/html/app/Core -name '*.php' | wc -l
echo 'Domain: ' && find /var/www/html/app/Domain -name '*.php' | wc -l
echo 'Infrastructure: ' && find /var/www/html/app/Infrastructure -name '*.php' | wc -l
echo 'Modules: ' && find /var/www/html/app/Modules -name '*.php' | wc -l
echo 'Filters: ' && find /var/www/html/app/Filters -name '*.php' | wc -l
echo 'Commands: ' && find /var/www/html/app/Commands -name '*.php' | wc -l
"When extending this architecture, follow the same pattern:
- Define interfaces in Domain first
- Implement in Infrastructure
- Create Module with Controllers and Views
- Add monitoring and documentation