Documentation

Complete guide to mvcCONTEXT framework

Overview

This framework is designed for developers who want to leverage AI tools like ChatGPT, Claude, or GitHub Copilot to their fullest potential. By keeping the entire codebase compact and well-structured, AI assistants can understand, analyze, and modify your entire application architecture in a single conversation.

Key Features

AI-Optimized

Entire framework < 2,000 lines, fits in AI context windows

Clean MVC

Clear separation of concerns with simple patterns

Flat File Structure

No deep folder structures. No confusion.

Robust Error Handling

Comprehensive logging and user-friendly error pages

AI-Context Window Friendly Architecture

Key Design Principles

1. Minimal File Size

  • Each file is kept intentionally small and focused
  • Easy to paste entire files into AI prompts
  • Every file has a clear purpose you can understand at a glance

2. Clear Single Responsibility

  • Each class has one clear purpose
  • No complex inheritance hierarchies
  • Self-documenting code structure

3. Predictable Patterns

  • Consistent naming conventions
  • Standardized file organization
  • Minimal configuration complexity

Getting Started

Prerequisites

  • PHP 8.0 or higher
  • Apache web server with mod_rewrite enabled

Installation Steps

1. Clone the repository

git clone https://github.com/jaanus-saarnak/mvcCONTEXT.git

2. Configure Application

Edit _config.php:

$appConfig = [
    'app_name' => 'Your App Name',
    'url' => 'https://example.com',
    'show_errors' => true
];

Configuration

Option Type Description
app_name string Application name displayed in UI
url string Base URL of your application
show_errors boolean Show detailed errors in development and friendly pages production

Routing

Route Definition

// Home page
$router->add('', ['controller' => 'HomeController', 'action' => 'index']);

// About page
$router->add('about', ['controller' => 'AboutController', 'action' => 'index']);

How Routing Works

1

URL Rewriting

.htaccess redirects all requests to index.php

2

Route Matching

Router matches URL against defined patterns

3

Controller Dispatch

Matched route instantiates controller and calls action

4

404 Handling

Unmatched routes show 404 page

Controllers

Creating a Controller

<?php
/**
 * mvcCONTEXT Framework
 */
 
class ControllerAbout extends CoreController
{
    public function index(): void
    {
        CoreView::renderTemplate('ViewAbout.php', [
            'title' => 'About Us'
        ]);
    }
}

Controller Features

  • Base Controller: All controllers extend CoreController
  • Error Handling: Exceptions are automatically caught and logged

Views & Layouts

Views

  • Manages the content

Layout System

The main layout wraps all views and provides consistent structure:

  • Header with navigation
  • Footer with links
  • Responsive design

Error Handling

Development Mode

show_errors = true

  • Detailed error information
  • Stack traces
  • File paths and line numbers
  • Unique error ID

Production Mode

show_errors = false

  • User-friendly error page
  • Hides sensitive information
  • Logs complete error details
  • Shows error ID for support

Error Logging

All errors are logged to _errors.log file with:

  • Timestamp and unique error ID
  • Exception type and message
  • Complete stack trace
  • Request information (method, URI, user agent)
  • PHP version

Development

Adding a New Page

  1. 1. Create Controller

    Add new controller in Controller*.php

  2. 2. Create View

    Add view template in View*.php

  3. 3. Add Route

    Define route in _routes.php

Best Practices

  • ✓ Follow MVC pattern - keep logic in controllers
  • ✓ Use PHP 8 type declarations
  • ✓ Handle exceptions with try-catch blocks
  • ✓ Always escape output with htmlspecialchars()
  • ✓ Keep files small for AI context windows

AI-Assisted Development Tips

💡 Maximize AI Assistance

Paste Entire Files

Don't hesitate to paste complete files into AI prompts - they're designed to fit!

Ask for Full Rewrites

AI can rewrite entire components while maintaining the architecture.

Request Pattern Matching

Ask AI to create new features following existing patterns.

Debug with Context

Include error logs + relevant files for accurate debugging.

Project Structure

mvcCONTEXT/
│
├── 📁 www/                  Public web root
│   ├── .htaccess            # URL rewriting rules, redirects all to index.php
│   ├── _config.php          # Application configuration settings
│   ├── _routes.php          # Route definitions and URL mappings
│   ├── _errors.log          # Error log file (auto-generated)
│   ├── ControllerHome.php   # Home page controller
│   ├── CoreController.php   # Base controller class with error handling
│   ├── CoreError.php        # Error handling, logging, and display
│   ├── CoreRouter.php       # Routing engine and dispatcher
│   ├── CoreView.php         # View rendering and templating engine
│   ├── index.php            # Application entry point and bootstrap
│   ├── LayoutMain.php       # Main HTML layout wrapper
│   ├── README-AI.md         # AI development guide and tips
│   ├── style.css            # Custom styles and overrides
│   ├── View404.php          # 404 error page template
│   └── ViewHome.php         # Home page view template
│
└── README.md                # Project documentation and setup guide

Ready to build with AI assistance?

Start developing with the power of AI Friendly architecture