Skip to content

Commit 003eb3a

Browse files
committed
improve doc
1 parent 693fb25 commit 003eb3a

2 files changed

Lines changed: 119 additions & 3 deletions

File tree

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
DBURL=localhost
2+
DBPORT=3306
23
DBNAME=twitch
34
DBUSER=root
45
DBPASSWORD=
56
DBPREFIX=sandbox_
7+
LOGLEVEL=DEBUG
68

79
BLOB_URL=
810
BLOB_CONNECTION_STRING=

README.md

Lines changed: 117 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ This application manages Twitch widgets for streamers. It specifically supports
88

99
## Prerequisites
1010
To run this application, you will need:
11-
- PHP
11+
- PHP 8.3+
1212
- MySQL
13+
- Node.js (for frontend dependencies)
14+
- Composer (for PHP dependencies)
1315

1416
## Installation
1517

@@ -20,7 +22,18 @@ git clone [repository-url]
2022
cd twitch-widget
2123
```
2224

23-
### Step 2: Configure Your Environment
25+
### Step 2: Install Dependencies
26+
Install PHP dependencies using Composer:
27+
```bash
28+
composer install
29+
```
30+
31+
Install frontend dependencies using npm:
32+
```bash
33+
npm install
34+
```
35+
36+
### Step 3: Configure Your Environment
2437
Copy the example environment file and then edit it with your specific configurations:
2538
```bash
2639
cp .env.example .env
@@ -33,7 +46,7 @@ Database connection details
3346
API keys if applicable
3447
Any other environment-specific variables
3548

36-
### Step 3: Run SQL Migrations
49+
### Step 4: Run SQL Migrations
3750
To set up your database, execute the SQL migrations provided:
3851
```bash
3952
php migrations/run.php
@@ -60,3 +73,104 @@ ngrok http 8000
6073

6174
This command will create a secure tunnel to your localhost server running on port 8000, allowing you to safely test your application's HTTPS functionality. Ensure that your application is running on port 8000 or adjust the port number in the command accordingly.
6275
Also update WEBSITE_DOMAIN from you env file
76+
77+
## Architecture & Code Organization
78+
79+
### Framework & Technologies
80+
- **Backend:** PHP 8.3 with Slim Framework 4
81+
- **Frontend:** Bootstrap 5.3, CountUp.js, Moment.js
82+
- **Database:** MySQL
83+
- **Template Engine:** Twig
84+
- **Dependency Injection:** PHP-DI
85+
- **Cloud Storage:** Azure Blob Storage
86+
- **Email Service:** Mailchimp Transactional (Mandrill)
87+
88+
### Project Structure
89+
90+
```
91+
twitch-widget/
92+
├── public/ # Web root directory
93+
│ ├── css/ # Compiled CSS files
94+
│ ├── js/ # Compiled JavaScript files
95+
│ └── index.php # Application entry point
96+
├── src/ # Application source code
97+
│ ├── Controllers/ # Request handlers
98+
│ ├── Models/ # Data models
99+
│ ├── Repositories/ # Data access layer
100+
│ ├── Services/ # Business logic services
101+
│ ├── Middlewares/ # Request/response middleware
102+
│ └── views/ # Twig templates
103+
├── migrations/ # Database migration files
104+
└── vendor/ # Composer dependencies
105+
```
106+
107+
### Key Components
108+
109+
#### Controllers (`src/Controllers/`)
110+
- **HomeController:** Handles public pages (home, password reset)
111+
- **LoginController:** Manages authentication and OAuth flow
112+
- **AdminController:** Admin panel functionality
113+
- **ApiController:** API endpoints for external integrations
114+
- **WidgetController:** Widget rendering and data endpoints
115+
116+
#### Models (`src/Models/`)
117+
- **User:** User account management
118+
- **Stream:** Stream configuration and data
119+
- **Event:** Event management
120+
- **WidgetAlert/WidgetDonation:** Widget-specific data models
121+
- **AccessToken/AuthorizationCode:** OAuth token management
122+
123+
#### Repositories (`src/Repositories/`)
124+
- **UserRepository:** User data operations
125+
- **StreamRepository:** Stream data operations
126+
- **EventRepository:** Event data operations
127+
- **WidgetRepository:** Widget data operations
128+
- **FileManager:** File upload/management via Azure Blob Storage
129+
130+
#### Services (`src/Services/`)
131+
- **ApiWrapper:** External API integrations and OAuth handling
132+
133+
#### Middlewares (`src/Middlewares/`)
134+
- **AuthMiddleware:** Session-based authentication
135+
- **AuthAdminMiddleware:** Admin role verification
136+
- **AuthApiMiddleware:** API authentication
137+
138+
### Widget System
139+
The application provides two main widget types:
140+
141+
1. **Alert Widget** (`/widget-stream-alert/{id}`)
142+
- Displays real-time donation alerts
143+
- Updates via AJAX polling
144+
- Customizable styling and animations
145+
146+
2. **Donation Bar Widget** (`/widget-stream-donation/{id}`)
147+
- Shows fundraising progress
148+
- Real-time goal tracking
149+
- Animated progress bars
150+
151+
### Database Migrations
152+
Database schema is managed through SQL migration files in the `migrations/` directory:
153+
- `00-init-db.sql`: Initial database setup
154+
- `01-add-goal-widget-text.sql`: Widget text configuration
155+
- `02-add-user-table.sql`: User management
156+
- `03-update-widget-alert-box.sql`: Alert widget improvements
157+
- `04-new-bar.sql`: Donation bar widget
158+
- `05-manage-user-reset-pwd.sql`: Password reset functionality
159+
- `06-manage-event.sql`: Event management
160+
- `07-improve-user-rights.sql`: User permissions
161+
162+
### Frontend Assets
163+
JavaScript and CSS files are organized in `public/js/` and `public/css/`:
164+
- **admin.js:** Admin panel functionality
165+
- **alert.js:** Alert widget logic
166+
- **event.js:** Event widget logic
167+
- **stream.js:** Stream management
168+
- **main.css:** Global styles
169+
170+
### Environment Configuration
171+
Key environment variables include:
172+
- Database connection (DBURL, DBPORT, DBNAME, DBUSER, DBPASSWORD)
173+
- OAuth configuration (CLIENT_ID, CLIENT_SECRET, API_URL)
174+
- Azure Blob Storage (BLOB_CONNECTION_STRING, BLOB_URL)
175+
- Email service (MANDRILL_API)
176+
- Application domain (WEBSITE_DOMAIN)

0 commit comments

Comments
 (0)