# 66Analytics - Project Structure Analysis

## Project Overview

**66Analytics** is a web analytics platform developed by AltumCode. It's a PHP-based application that provides website analytics similar to Google Analytics, with features including visitor tracking, session replays, heatmaps, and comprehensive statistics.

## Technology Stack

- **Backend**: PHP (Object-oriented, MVC architecture)
- **Database**: MySQL/MariaDB (via mysqli)
- **Frontend**: JavaScript, jQuery, Bootstrap, Chart.js
- **Dependencies**: Composer (vendor directory with multiple packages)
- **Theme System**: Custom theme system with SCSS
- **Caching**: File-based caching system

## Directory Structure

```
analytics/
├── app/                          # Main application code
│   ├── controllers/              # MVC Controllers
│   │   ├── admin/                # Admin panel controllers (60 files)
│   │   ├── admin-api/            # Admin API controllers (6 files)
│   │   ├── api/                  # Public API controllers (9 files)
│   │   └── [Main controllers]    # User-facing controllers
│   ├── core/                     # Core framework classes
│   │   ├── App.php               # Main application bootstrap
│   │   ├── Router.php            # URL routing system
│   │   ├── Controller.php        # Base controller class
│   │   ├── Model.php             # Base model class
│   │   ├── Database.php          # Database connection handler
│   │   ├── Authentication.php    # User authentication
│   │   ├── Cache.php             # Caching system
│   │   ├── Language.php          # Multi-language support
│   │   ├── Settings.php          # Application settings
│   │   └── [Other core classes]
│   ├── models/                   # Data models
│   │   ├── User.php
│   │   ├── Website.php
│   │   ├── Plan.php
│   │   ├── Payment.php
│   │   └── [Other models]
│   ├── helpers/                  # Helper functions and classes
│   │   ├── AnalyticsFilters.php
│   │   ├── core.php
│   │   ├── email.php
│   │   ├── links.php
│   │   ├── strings.php
│   │   └── payment-gateways/     # Payment gateway integrations
│   ├── traits/                   # PHP traits for code reuse
│   ├── languages/                # Language files
│   │   ├── english#en.php
│   │   └── admin/
│   ├── includes/                 # Include files
│   │   ├── product.php           # Product information
│   │   ├── debug.php
│   │   └── [Other includes]
│   └── init.php                  # Application initialization
├── themes/                       # Theme files
│   └── altum/                    # Default theme
│       ├── views/                # View templates (384 PHP files)
│       ├── assets/               # CSS, JS, images
│       │   ├── js/               # JavaScript files
│       │   │   ├── pixel/        # Tracking pixel scripts
│       │   │   │   ├── normal/   # Full tracking
│       │   │   │   └── lightweight/ # Lightweight tracking
│       │   │   └── libraries/    # Third-party libraries
│       │   ├── css/              # Stylesheets
│       │   └── images/           # Images and SVGs (291 SVG files)
│       └── [SCSS files]          # Source SCSS files (100 files)
├── plugins/                      # Plugin system
│   ├── affiliate/
│   ├── dynamic-og-images/
│   ├── email-shield/
│   ├── image-optimizer/
│   ├── offload/
│   ├── push-notifications/
│   └── pwa/
├── uploads/                      # User uploads directory
│   ├── blog/
│   ├── cache/
│   ├── cookie_consent/
│   ├── dynamic_og_images/
│   ├── logs/
│   ├── main/
│   ├── offline_payment_proofs/
│   ├── pwa/
│   ├── store/
│   └── users/
├── vendor/                       # Composer dependencies
├── install/                      # Installation wizard
├── update/                       # Update system
├── config.php                    # Configuration file
└── index.php                     # Entry point
```

## Core Architecture

### MVC Pattern

The application follows a Model-View-Controller (MVC) architecture:

1. **Models** (`app/models/`): Handle data access and business logic
2. **Views** (`themes/altum/views/`): Presentation layer (PHP templates)
3. **Controllers** (`app/controllers/`): Handle requests and coordinate between models and views

### Routing System

The routing is handled by `Router.php` which:
- Parses URL parameters from `?altum=...` query string
- Supports language prefixes
- Maps routes to controllers
- Handles admin, API, and public routes separately

**Route Structure:**
- Public routes: `/dashboard`, `/statistics`, `/websites`, etc.
- Admin routes: `/admin/*`
- API routes: `/api/*` and `/admin-api/*`
- Special routes: `/pixel`, `/pixel-track`, `/webhook-*`, `/cron`

### Key Features

1. **Analytics Tracking**
   - Normal tracking (full session data)
   - Lightweight tracking (minimal data)
   - Session replays
   - Heatmaps
   - Real-time analytics

2. **User Management**
   - User registration/login
   - Team collaboration
   - Multi-website support
   - Plan/subscription management

3. **Payment Integration**
   - Multiple payment gateways:
     - Stripe, PayPal, Coinbase
     - Razorpay, Paystack, Mollie
     - YooKassa, Paddle, MercadoPago
     - And many more...

4. **Admin Panel**
   - User management
   - Website management
   - Plan management
   - Payment management
   - Settings configuration
   - Blog/content management

5. **API System**
   - RESTful API for external integrations
   - API documentation
   - API key authentication

6. **Plugins**
   - Modular plugin system
   - Affiliate system
   - Push notifications
   - PWA support
   - Image optimization
   - Dynamic OG images

## Database Structure

The application uses MySQL with tables likely including:
- `users` - User accounts
- `websites` - Tracked websites
- `sessions_events` - Pageview/session events
- `lightweight_events` - Lightweight tracking events
- `websites_visitors` - Visitor information
- `visitors_sessions` - Session data
- `events_children` - Child events
- `plans` - Subscription plans
- `payments` - Payment records
- `teams` - Team collaboration
- `websites_heatmaps` - Heatmap data
- `sessions_replays` - Session replay data
- `websites_goals` - Conversion goals

## Configuration

### Main Configuration (`config.php`)
```php
DATABASE_SERVER   - Database host
DATABASE_USERNAME - Database username
DATABASE_PASSWORD - Database password
DATABASE_NAME     - Database name
SITE_URL          - Site URL
```

### Application Constants (`index.php`)
```php
DEBUG             - Debug mode (0/1)
MYSQL_DEBUG       - MySQL profiling (0/1)
LOGGING           - File logging (0/1)
CACHE             - Caching enabled (0/1)
```

## Key Components

### 1. App Class (`app/core/App.php`)
- Main application bootstrap
- Initializes database, cache, plugins, language
- Handles user authentication
- Manages plan expiration
- Sets up routing and controller execution

### 2. Router Class (`app/core/Router.php`)
- URL parsing and routing
- Language detection
- Controller/method resolution
- Route configuration

### 3. Database Class (`app/core/Database.php`)
- MySQL connection management
- Uses MysqliDb helper for query building
- Supports profiling for debugging

### 4. Tracking System
- **Pixel Controller**: Serves tracking JavaScript
- **PixelTrack Controller**: Receives tracking data
- Supports both normal and lightweight tracking modes
- Session replay using rrweb library
- Heatmap generation

### 5. Authentication System
- Session-based authentication
- CSRF protection
- Team access control
- Admin authentication
- SSO support

## Frontend Assets

### JavaScript Libraries
- jQuery
- Bootstrap
- Chart.js (for analytics charts)
- rrweb (session replay)
- Select2, Pickr, Cropper
- EditorJS (content editor)
- Moment.js (date handling)
- AOS (animations)

### Tracking Scripts
- `pixel-header.js` - Header tracking script
- `pixel-footer.js` - Footer tracking script
- `pixel-helpers.js` - Helper functions
- Separate versions for normal and lightweight tracking

## Security Features

1. **CSRF Protection**: Token-based CSRF protection
2. **XSS Protection**: Input sanitization
3. **SQL Injection Protection**: Prepared statements via MysqliDb
4. **Session Security**: Secure cookie settings
5. **HSTS**: HTTP Strict Transport Security
6. **Content Security Policy**: Frame-ancestors control
7. **Authentication Guards**: Route-level access control

## Payment Gateways

The application integrates with 15+ payment gateways:
- Stripe, PayPal, Coinbase
- Razorpay, Paystack, Mollie, YooKassa
- Paddle, MercadoPago, Midtrans
- Flutterwave, LemonSqueezy, MyFatoorah
- Iyzico, PayU, Crypto.com

Each gateway has its own webhook handler for payment processing.

## Multi-language Support

- Language files in `app/languages/`
- URL-based language switching
- Browser language detection
- User preference storage
- Admin language management

## Caching System

- File-based caching
- Cache tags for invalidation
- Default cache duration: 30 days
- User-specific cache invalidation
- Website-specific cache invalidation

## Plugin System

Plugins are located in `plugins/` directory:
- Each plugin has its own directory
- Config-based plugin loading
- Hooks and filters system
- Extensible architecture

## Installation & Updates

- **Install**: `/install` - Installation wizard
- **Update**: `/update` - Update system
- Database migrations handled during installation/update

## Development Notes

1. **Namespace**: All classes use `Altum` namespace
2. **Autoloading**: Custom autoloader + Composer autoloader
3. **Error Handling**: Custom error pages and logging
4. **Debugging**: Debug mode with MySQL profiling
5. **Code Style**: PSR-like structure with custom conventions

## API Endpoints

### Public API (`/api/`)
- `/api/websites` - Website management
- `/api/statistics` - Analytics data
- `/api/domains` - Domain management
- `/api/teams` - Team management
- `/api/user` - User information
- `/api/payments` - Payment data
- `/api/logs` - Activity logs

### Admin API (`/admin-api/`)
- `/admin-api/users` - User management
- `/admin-api/payments` - Payment management
- `/admin-api/plans` - Plan management
- `/admin-api/sso` - SSO management
- `/admin-api/dynamic-og-images` - OG image management
- `/admin-api/domains` - Domain management

## File Count Summary

- **PHP Files**: 4000+ files
- **Controllers**: 100+ controller files
- **Views**: 384 PHP view files
- **SVG Files**: 291 SVG images
- **SCSS Files**: 100 SCSS files
- **JavaScript**: 68 JS files
- **Plugins**: 7 plugins

## Dependencies (via Composer)

Major dependencies include:
- Payment gateway SDKs (Stripe, PayPal, etc.)
- HTTP clients (Guzzle)
- Image processing libraries
- QR code generation
- JWT handling
- Email libraries (PHPMailer)
- Caching libraries
- And many more...

## License

This is a commercial product by AltumCode. Unauthorized distribution or modification is not permitted.

---

**Last Updated**: Based on code analysis
**Product**: 66Analytics by AltumCode
**Version**: Based on ALTUMCODE constant (66)

