Wannonces : announcements platform with integrated messaging in PHP

Feb 2025
Web
PHPSQL
Wannonces : announcements platform with integrated messaging in PHP

Wannonces : announcements platform with integrated messaging in PHP (February 2025)

Introduction and context

This project was carried out as part of an individual continuous assessment project in the second year of the Computer Science BUT. The objective: to improve an existing PHP classified announcements platform by adding a complete messaging feature.

The messaging functionality was created in two and a half days, under great constraint. As the interface was secondary, I spent little time on it.

The initial platform allowed viewing announcements, but without any way to contact the authors. I therefore designed and implemented a hierarchical messaging system allowing users to exchange around published announcements.

  • Problem: How to allow users of an announcements platform to communicate with each other in a structured way?
  • Objective: Develop a messaging system with nested replies, while respecting the MVC architecture and clean architecture principles.

Project architecture

The MVC Pattern

The project follows a modified Model-View-Controller (MVC) pattern, with a clear separation of responsibilities:

  • Model (domain/): The entities Post, User, Messages, and UserPosts represent business data
  • View (gui/): The View* classes generate the HTML displayed to the user
  • Controller (control/): Controllers.php handles user actions, Presenter.php prepares data for display
Class diagram

UML class diagram of the project. Domain entities are separated from services and views.

Layered architecture

The code is organized into distinct layers:

📁 Project Root

📂 domain/
Business Entities: Post, User...

📂 service/
Business Logic: PostService...

📂 data/
Data Access: PDO

📂 control/
Controllers and presenter

📂 gui/
HTML Views

This organization allows modifying a layer without impacting the others. For example, changing the database would only require modifying DataAccess.php.

The messaging system

Database design

I created a Messages table with the following fields:

  • messageid: unique identifier
  • postid: link to the relevant announcement
  • senderlogin: author of the message
  • content: message content
  • date: timestamp
  • parentid: reference to the parent message (for replies)

The parentid field allows creating a tree structure: a message can be a reply to another message, thus forming discussion threads.

Building the message tree

The MessageService class contains the tree construction algorithm. The process is done in two passes:

  1. First pass: creation of an array indexed by messageid for quick access
  2. Second pass: attaching each message to its parent via parentid

Messages without a parent (parentid null or 0) become root messages. This approach avoids recursive SQL queries and works in O(n).

Hierarchical display

The Presenter generates the HTML recursively. Each nesting level receives an alternating CSS class (color-primary / color-secondary) to visually distinguish conversation levels.

img15.avif

Display of a discussion thread with several levels of replies. The color alternation facilitates reading.

Implemented features

Authentication

The application has a login system based on PHP sessions. Each protected page verifies the presence of a valid session before displaying its content.

Login page

Login page. The interface remains sober and functional.

Login form

Login form with login and password fields.

List of announcements

After logging in, the user accesses the list of announcements sorted by descending date. Each announcement displays its title and author.

List of available announcements

List of available announcements. Clicking on the title opens the detail.

Viewing an announcement

The detail page displays the title, author, publication date, and complete content of the announcement. A button allows access to messages.

Ad detail

Detail of an announcement with author information and the date formatted in French.

Full view of an announcement

Full view of an announcement with its content.

Creating announcements

Connected users can publish new announcements via a dedicated form.

Ad creation form

Ad creation form with title and content.

Confirmation after announcement publication

Confirmation after publication of an announcement.

Messaging per announcement

Each announcement has its own discussion space. Users can post messages and reply to existing messages.

Ad messaging

Messaging area of an announcement . The form at the top allows posting a new message.

Message on an announcement

Sending a message on an announcement .

Message sending confirmation

Message sent with confirmation.

Nested replies

The system allows replying directly to a message. The reply is displayed below the original message, with a visual offset.

Reply button

Reply button on an existing message.

Reply form

Reply form to a message.

Reply sending

Reply sent and displayed under the parent message.

Discussion thread

Discussion thread with several nested replies.

Centralization of messages

A dedicated page allows the user to see all messages received on their announcements, grouped by announcement.

Centralized view of messages

Centralized view of messages by announcement .

List of received messages

List of messages received on an announcement.

A menu allows access to the different sections: announcements, creation, messages, and logout.

Navigation bar

Navigation bar with quick access to features.

Logout

Logout and return to the login page.

Possible actions

The main possible actions:

  • Log in / Log out
  • View the list of announcements
  • View the detail of an announcement
  • Create a new announcement
  • Send a message on an announcement
  • Reply to an existing message
  • View received messages

Technical choices

PDO and prepared statements

Database access uses PDO with prepared statements for write operations. This approach protects against SQL injections.

Date formatting

Dates are formatted in French directly in the Presenter, with an array of translated months. The display "23 janvier 2025 14:30:00" is more readable than a raw timestamp.

CSS and readability

The style uses a palette of blues (#406882, #2C5876) on a dark background (darkslategray). Golden links (gold) contrast with the background to remain visible.

Summary and skills

This project allowed me to consolidate several skills:

  • Software architecture: practical application of the MVC pattern and layered architecture
  • PHP and OOP: namespaces, classes, inheritance, dependency injection
  • Database: relational schema design, SQL queries, PDO
  • Algorithms: tree construction from flat data, recursive traversal
  • User interface: HTML forms, sessions, navigation

The code produced is maintainable and extensible. Adding a new type of message or a moderation feature would only require localized modifications.