# kamel3d/motriba architecture

> Architecture diagram of the GitHub repository kamel3d/motriba, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kamel3d/motriba
- Repository: https://github.com/kamel3d/motriba

## Overview

##### Main Components

A. Frontend Layer:
- Public Interface (Views)
- Home page with country dropdown
- Country-specific pages
- Voting interface
- Charts/Statistics display
- Admin Interface
- Leader management
- Site maintenance controls
- Statistics monitoring

B. Application Layer (CodeIgniter Framework):
- Controllers
- Site controller (main functionality)
- Vote controller (handling voting logic)
- Country controller (country-specific operations)
- Admin controller (backend operations)
- Cronjob controller (scheduled tasks)

C. Model Layer:
- Site_model (main business logic)
- Admin_model (administration functions)

D. Database Layer:
- MySQL Database with tables:
- admin (system configuration)
- stats (permanent vote records)
- stats_temp (temporary vote storage)
- country_ip (IP range mapping)
- countries and leaders tables

E. External Services:
- Cron Job System
- Image Processing Service
- IP Geolocation System

**[Client Layer (Browser)]**
- ↕
**[Web Server (PHP 5.6.31)]**
- ↕
**[CodeIgniter Framework]**
- ↕
**[Database (MySQL 5.6)]**

##### Key Interactions to Highlight

a) Voting Flow:
**User → Vote Controller → IP Validation → Stats_temp Table → Stats Table (via cron)**

b) Geographic Detection:
**User Request → IP Check → Country_IP Table → Country Determination**

c) Admin Operations:
**Admin → Admin Controller → Image Processing → Database Updates**

##### Technical Details

- CodeIgniter 2.1.0 framework structure
- AMCharts integration for statistics visualization
- Image processing workflow
- Database replication process
- Cron job scheduling

##### Optimization Notes

Notes about:
- IP detection modernization opportunities
- Potential scaling points
- Security enhancement possibilities

Remember to emphasize the separation between public and administrative functions, and clearly show how the cron jobs interact with the system for data maintenance and vote processing.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        Browser["Web Browser"]
        AdminClient["Admin Client"]
    end

    subgraph "Frontend Layer"
        PublicViews["Public Views"]:::frontend
        AdminViews["Admin Views"]:::frontend
        Charts["Charts Display"]:::frontend
    end

    subgraph "Application Layer"
        SiteController["Site Controller"]:::controller
        VoteController["Vote Controller"]:::controller
        CountryController["Country Controller"]:::controller
        AdminController["Admin Controller"]:::controller
        CronController["Cronjob Controller"]:::controller
    end

    subgraph "Model Layer"
        SiteModel["Site Model"]:::model
        AdminModel["Admin Model"]:::model
    end

    subgraph "Database Layer"
        MySQL[(MySQL Database)]:::database
        subgraph "Tables"
            AdminTable["Admin Table"]:::table
            StatsTable["Stats Table"]:::table
            StatsTempTable["Stats Temp Table"]:::table
            CountryIPTable["Country IP Table"]:::table
            CountriesTable["Countries Table"]:::table
            LeadersTable["Leaders Table"]:::table
        end
    end

    subgraph "External Services"
        CronSystem["Cron Job System"]:::external
        ImageProcessor["Image Processing"]:::external
        IPGeoSystem["IP Geolocation"]:::external
    end

    %% Connections
    Browser --> PublicViews
    AdminClient --> AdminViews
    PublicViews --> SiteController
    AdminViews --> AdminController
    Charts --> SiteController

    SiteController --> SiteModel
    VoteController --> SiteModel
    CountryController --> SiteModel
    AdminController --> AdminModel
    CronController --> SiteModel

    SiteModel --> MySQL
    AdminModel --> MySQL

    CronSystem --> StatsTempTable
    CronSystem --> StatsTable
    ImageProcessor --> LeadersTable
    IPGeoSystem --> CountryIPTable

    %% Click Events
    click PublicViews "https://github.com/kamel3d/Motriba/tree/master/application/views/"
    click AdminViews "https://github.com/kamel3d/Motriba/tree/master/application/views/admin/"
    click Charts "https://github.com/kamel3d/Motriba/blob/master/application/views/graph_in_view.php"
    click SiteController "https://github.com/kamel3d/Motriba/blob/master/application/controllers/site.php"
    click VoteController "https://github.com/kamel3d/Motriba/blob/master/application/controllers/vote.php"
    click CountryController "https://github.com/kamel3d/Motriba/blob/master/application/controllers/country.php"
    click CronController "https://github.com/kamel3d/Motriba/blob/master/application/controllers/cronjob.php"
    click SiteModel "https://github.com/kamel3d/Motriba/blob/master/application/models/site_model.php"
    click AdminModel "https://github.com/kamel3d/Motriba/blob/master/application/models/admin_model.php"
    click MySQL "https://github.com/kamel3d/Motriba/blob/master/db_motriba.sql"
    click CronSystem "https://github.com/kamel3d/Motriba/blob/master/script/cron.php"
    click ImageProcessor "https://github.com/kamel3d/Motriba/blob/master/application/libraries/Upload.php"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef controller fill:#2ecc71,stroke:#27ae60,color:white
    classDef model fill:#e67e22,stroke:#d35400,color:white
    classDef database fill:#f1c40f,stroke:#f39c12,color:white
    classDef table fill:#f1c40f,stroke:#f39c12,color:white
    classDef external fill:#e74c3c,stroke:#c0392b,color:white
```
