# Mechira Trends

Mechira Trends is a PHP/MySQL SaaS-style intelligence dashboard for detecting early TikTok trend momentum in Poland and estimating whether a trend can be used in political social media communication.

## 1. Hosting Requirements

- PHP 8.2+
- MySQL 5.7+ or MariaDB 10.4+
- PDO MySQL extension
- Apache with `.htaccess`
- Cron access
- FTP/SFTP upload access

No Node.js is required in production.

## 2. Create MySQL Database

Create a database and user in the OVH panel. Keep these values ready:

- database host
- database name
- database user
- database password

## 3. Import `database.sql`

Import [database/database.sql](/Users/marcelmarganski/mechira-analysis/database/database.sql) through phpMyAdmin or the MySQL CLI.

## 4. Configure Application

Preferred:

1. Open `/install/` in a browser.
2. Enter database credentials.
3. Create the first administrator.
4. The installer writes `config/config.php` and creates `storage/installed.lock`.

Manual fallback:

1. Copy `config/config.sample.php` to `config/config.php`.
2. Fill database credentials.
3. Keep API keys outside `/public`.

## 5. FTP Upload

Upload the full project directory. Point the domain document root to `/public` when possible.

If OVH forces the domain root to the uploaded directory, keep the root `.htaccess` enabled. It redirects public traffic to `/public` and blocks application folders.

## 6. Permissions

Writable folders:

- `storage/logs`
- `storage/cache`
- `storage/installed.lock` can be created by the installer

## 7. OVH Cron

Run the collector hourly:

```bash
php /home/user/www/cron/collector.php
```

Optional history aggregation:

```bash
php /home/user/www/cron/aggregate_history.php
```

## 8. First Admin

Use the installer, or create a user directly with `password_hash()` and role `admin`.

## 9. Seed Demo Data

After installing the database, run:

```bash
php /home/user/www/database/seed_demo.php
```

This creates 100 trends, 30 hashtags, 30 sounds, 30 political accounts, 25 topics, and seven days of snapshots.

## 10. Data Sources

Configure sources in Admin -> Data Sources. The app ships with:

- `MockTrendSource` for realistic demo collection
- `CsvTrendSource` for CSV imports
- `ManualTrendSource` for analyst-entered trends
- `ApiTrendSource` for future authorized APIs
- `TikTokCreativeCenterSource` as a configurable adapter stub, without bypassing TikTok protections

## 11. AI Configuration

Set AI provider details in Admin -> Settings or in `config/config.php`. Never put API keys in `/public`.

AI analysis is optional. Without an API key, Mechira Trends uses local heuristics for Political Fit, risk, and usage ideas.

## 12. Troubleshooting

- Blank page: check PHP 8.2+, file permissions, and `storage/logs/app.log`.
- Database error: verify `config/config.php` and imported schema.
- Cron overlap: collector uses `storage/cache/collector.lock`.
- Empty dashboard: run `database/seed_demo.php` or `cron/collector.php`.
- 403 on app folders: expected. Only `/public` should be web-accessible.

