A multi-page web discussion board forum application built with PHP and MySQL (PDO). This platform allows users to register, log in, create discussion threads, write comments, like posts, and interact with the community. It also features a sidebar announcement widget for administrators managed via a local JSON database.
- User Authentication: Safe registration and login validation with session management.
- Category Slider: Interactive Swiper slider allowing users to filter threads by category.
- Discussion Threads: Ability to create, view, edit, and delete text posts with optional image attachments.
- Likes System: Real-time thread like/unlike system utilizing AJAX (Fetch API).
- Comments Section: Leave replies on threads with support for text content and image uploads.
- Profile Customization: Modify profile settings including first name, last name, avatar, and password.
- User Management: Access list of registered users to edit their profile information, toggle roles (User/Admin), or remove accounts.
- Category Management: Add new discussion categories, delete inactive categories, and update category icons.
- System Announcements: Create and manage special administrator announcements that display in the sidebar widget (stored and fetched from MySQL database).
The project utilizes a Central Router architecture. All traffic passes through index.php.
miniproject-Thread/
βββ docker/ # Docker service configuration
β βββ nginx/
β β βββ nginx.conf # Nginx virtual host config (FastCGI β PHP-FPM)
β βββ php/
β βββ Dockerfile # PHP 8.2-FPM with required extensions
β βββ php.ini # PHP runtime settings (upload size, timezone, errors)
βββ config/ # Application configuration
β βββ server.php # MySQL database connection via PDO (reads from env vars)
β βββ swal_helper.php # SweetAlert helper functions
βββ layouts/ # Shared UI layouts and components
β βββ dataheader.php # Global session verification and user profile loader
β βββ top_layouts.php # Navigation bar and header structure
β βββ category_slide.php # Category swiper slider layout
β βββ con4.php # Sidebar announcement widget component
β βββ bottom_layouts.php # Footer layout and closing HTML tags
βββ assets/ # Static frontend assets
β βββ js/
β βββ script.js # Client-side JavaScript for Swiper and navbar dropdown
βββ src/ # Structured PHP page scripts (View Modules)
β βββ auth/ # login.php, logout.php, register.php
β βββ admin/ # admin.php, manage_users.php, add_category.php, etc.
β βββ user/ # profile.php, edit_profile.php, edit_password.php
β βββ posts/ # homepage.php, post.php, comments and likes actions
βββ docker-compose.yml # Docker Compose: Nginx + PHP-FPM + MySQL + phpMyAdmin
βββ .env # Environment variables (DB credentials β not committed)
βββ .env.example # Template for .env file
βββ db.sql # Database schema definition script (auto-imported by Docker)
βββ db_seed.sql # Unified database seeding script (resets and inserts mock data)
βββ index.php # Central Router (Single entry point)
βββ README.md # Project overview and setup guide
βββ AGENT.md # AI developer guidelines and coding instructions
βββ CONTEXT.md # Business domain context, roles, and schema diagrams
Prerequisites: Install Docker Desktop before proceeding.
git clone <repository-url>
cd miniproject-ThreadCopy the example env file and fill in your credentials:
copy .env.example .envEdit .env:
DB_NAME=dpi_db
DB_USER=dpi_user
DB_PASS=your_password_here
DB_ROOT_PASS=your_root_password_here# First time (build images + start containers)
docker compose up -d --build
# Subsequent runs
docker compose up -dDocker will automatically:
- π Build the PHP 8.2-FPM container with all required extensions
- π Start Nginx on port
8080 - ποΈ Start MySQL and auto-import
db.sqlto initialize the database - π₯οΈ Start phpMyAdmin on port
8081
| Service | URL |
|---|---|
| π Web Application | http://localhost:8080 |
| π₯οΈ phpMyAdmin | http://localhost:8081 |
Login with the pre-seeded administrator account:
- Email:
admin@gmail.com - Password:
123456
To reset and seed the database with mock categories, users, posts, and announcements (using UTC timestamps for PHP-level timezone conversion), run:
docker cp data/db_seed.sql dpi_mysql:/db_seed.sql
docker exec dpi_mysql mysql -u dpi_user -pdpi_password123 --default-character-set=utf8mb4 dpi_db -e "source /db_seed.sql"docker compose down
# Stop and remove database volume (full reset)
docker compose down -v| Container | Image | Port | Role |
|---|---|---|---|
dpi_nginx |
nginx:alpine |
8080:80 |
Web server, serves static files, proxy PHP |
dpi_php |
Custom PHP 8.2-FPM | internal | Executes PHP scripts |
dpi_mysql |
mysql:8.0 |
3307:3306 |
Relational database |
dpi_phpmyadmin |
phpmyadmin:latest |
8081:80 |
Database GUI management |
The config/server.php connection reads credentials from environment variables set in .env:
$host = getenv('DB_HOST') ?: 'mysql';
$dbname = getenv('DB_NAME') ?: 'dpi_db';
$user = getenv('DB_USER') ?: 'dpi_user';
$pass = getenv('DB_PASS') ?: '';Note: The host name is
mysql(the Docker service name), notlocalhost.
If you are developing or refactoring this project, please follow this documentation workflow:
Important
- AGENT.md (Root Guide & Coordinator): Read this first to understand directory layouts, coding rules, environment configurations, and security standards. It guides you on which files to read or update next.
- CONTEXT.md (System Context): Read to understand relational database schemas and logic flows. You MUST update this file whenever you make important changes to database structures or core backend logic.
- DESIGN.md (Design System): You MUST read this whenever building new pages, UI components, or editing CSS styles to ensure compliance with the Forest Green theme.