Skip to content

narawit101/miniproject-Thread

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DPI Thread Forum - Web Discussion Board System

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.


🌟 Key Features

πŸ‘€ General User Features

  • 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.

πŸ”‘ Administrator Features

  • 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).

πŸ“ Directory Structure

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

🐳 Installation & Setup (Docker)

Prerequisites: Install Docker Desktop before proceeding.

1. Clone the Repository

git clone <repository-url>
cd miniproject-Thread

2. Configure Environment Variables

Copy the example env file and fill in your credentials:

copy .env.example .env

Edit .env:

DB_NAME=dpi_db
DB_USER=dpi_user
DB_PASS=your_password_here
DB_ROOT_PASS=your_root_password_here

3. Start All Services

# First time (build images + start containers)
docker compose up -d --build

# Subsequent runs
docker compose up -d

Docker will automatically:

  • 🐘 Build the PHP 8.2-FPM container with all required extensions
  • 🌐 Start Nginx on port 8080
  • πŸ—„οΈ Start MySQL and auto-import db.sql to initialize the database
  • πŸ–₯️ Start phpMyAdmin on port 8081

4. Access the Application

Service URL
🌐 Web Application http://localhost:8080
πŸ–₯️ phpMyAdmin http://localhost:8081

5. Default Admin Account

Login with the pre-seeded administrator account:

  • Email: admin@gmail.com
  • Password: 123456

6. Seeding Mock Data

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"

7. Stop Services

docker compose down

# Stop and remove database volume (full reset)
docker compose down -v

βš™οΈ Docker Services Overview

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

πŸ”‘ Database Connection

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), not localhost.


πŸ“– Developer Documentation Guide

If you are developing or refactoring this project, please follow this documentation workflow:

Important

🚨 Workflow & Documentation Rules

  1. 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.
  2. 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.
  3. 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages