GEMVC Architecture
Understand the complete architecture of GEMVC framework. Learn about directory structure, request flow, components, and how everything works together.
What You'll Learn
Directory Structure
Framework organization and component layout
Request Flow
How requests flow through the system
Component Breakdown
Understanding each layer and component
Video Coming Soon...
Directory Structure
GEMVC follows a clean, organized directory structure that separates concerns and makes the framework easy to understand and maintain.
src/ ├── CLI/ # Command-line interface & code generation ├── core/ # Core framework classes (Bootstrap, ApiService, Security) ├── http/ # HTTP layer (Request, Response, JWT) ├── database/ # Database layer (ORM, migrations, query builders) ├── helper/ # Utility classes (TypeChecker, FileHelper, CryptHelper) ├── startup/ # Platform-specific initialization files └── stubs/ # IDE type stubs (OpenSwoole, Redis)
Each directory has a specific purpose and contains related components that work together to provide the framework's functionality.
Core Design Principles
Webserver-Agnostic Application Code
The app/ folder code never changes when switching webservers. The framework handles all platform differences, so the same API endpoints work on Apache, OpenSwoole, and Nginx.
Automatic Security (90% Automatic)
No configuration needed - Security works out of the box. Path protection, input sanitization, and SQL injection prevention are all automatic. Developers only need to call definePostSchema() and auth() methods.
Environment-Aware Architecture
Automatic webserver detection, automatic database manager selection, and automatic request adapter selection. The framework adapts to your environment automatically.
Code Generation CLI
Generate Services, Controllers, Models, Tables, and CRUD operations via CLI commands. Template-based generation system with Docker-compose generation support.
Request Flow Architecture
Understanding how requests flow through GEMVC is crucial for building effective applications. The flow differs slightly between Apache/Nginx and OpenSwoole, but your application code remains the same.
Apache/Nginx Flow
OpenSwoole Flow
Component Breakdown
GEMVC is organized into several key components, each handling specific responsibilities:
CLI/ - Code Generation & Project Management
Handles command-line interface, code generation, and project initialization.
Command.php- Base command classAbstractInit.php- Template method for project initializationCreateService.php,CreateController.php- Code generators
core/ - Framework Core
Core framework classes for routing, security, and request handling.
Bootstrap.php/SwooleBootstrap.php- Request routingApiService.php- Base API service classesSecurityManager.php- Path access protectionApiDocGenerator.php- Auto-generate API documentation
http/ - HTTP Layer
Handles HTTP requests, responses, authentication, and sanitization.
Request.php- Unified request object (all inputs sanitized)ApacheRequest.php/SwooleRequest.php- Platform adaptersJWTToken.php- JWT creation, verification, renewal- Automatic input sanitization (XSS prevention)
database/ - Database Layer
ORM, query builders, migrations, and database management.
Table.php- Main ORM class (fluent interface)UniversalQueryExecuter.php- Enforces prepared statementsDatabaseManagerFactory.php- Auto-selects DB manager- 100% SQL injection prevention (all queries use prepared statements)
helper/ - Utility Classes
Utility classes for type checking, file operations, encryption, and more.
TypeChecker.php- Runtime type validationFileHelper.php- File operations + encryptionCryptHelper.php- Password hashing (Argon2I) + AES-256-CBC encryptionImageHelper.php- Image processing + signature detection
Security Architecture
GEMVC provides 90% automatic security with no developer configuration needed. Security is built into the framework at every layer.
Automatic Security (No Developer Action)
/app, /vendor, .env, etc.
Developer-Enabled Security (Simple Method Calls)
definePostSchema() (prevents mass assignment)
$request->auth() (JWT validation)
$request->auth(['role']) (role checking)
URL-to-Code Mapping
GEMVC automatically maps URLs to code using a simple, predictable pattern:
/api/User/createapp/api/User.phpUser::create()Configuration (via .env):
SERVICE_IN_URL_SECTION=1(default: 1)METHOD_IN_URL_SECTION=2(default: 2)
Performance Features
OpenSwoole Optimizations
- ✓ Connection pooling (database)
- ✓ Persistent processes (no PHP bootstrap overhead)
- ✓ Hot reload (development)
- ✓ Async capabilities
- ✓ WebSocket support
Apache/Nginx Optimizations
- ✓ Optional persistent PDO connections
- ✓ Cached environment detection
- ✓ Singleton patterns for managers
- ✓ Prepared statement reuse
🎉 Architecture Complete!
Now that you understand GEMVC's architecture, let's learn about the request lifecycle!