How jannat12-bot/leboncoin works
1. Overall shape: PHP MVC-style marketplace
- The repository is a small PHP/MySQL application organized around a front controller/router, controllers, models, and server-rendered views.
- The main business domain is classified ads: browsing listings, viewing a listing, managing favorites, and authenticating users.
2. Entry points and request routing
- HTTP requests are meant to enter through the front-controller layer (index.php, router.php, and the public/ web root with .htaccess rewrite).
- Apache rewrite rules likely map clean URLs to PHP routes.
- The architecture is synchronous and server-rendered: controller resolves route, calls model(s), then includes a view.
3. Core domain subsystem: listings (Annonce)
- The listing subsystem is centered on Annonce.php / AnnonceController.php.
- It covers:
- listing all ads,
- applying multi-criteria filters,
- loading a single ad detail,
- and incrementing the view counter when an ad is opened.
- The README indicates Annonce::getAll() handles filters and Annonce::getById() increments views.
4. Favorites subsystem
- Favorites are a separate domain boundary with Favori.php and FavoriController.php.
- Responsibilities include:
- adding a favorite,
- removing a favorite,
- checking whether a listing is already favorited,
- and listing “my favorites”.
- This subsystem depends on the authenticated user session and the selected announcement ID.
5. Authentication and user context
- Authentication is handled by controllers/authentification.php and the auth views under views/auth/.
- models/user.php suggests a user model for login/registration data access.
- The rest of the app reads $_SESSION['user_id'] as the boundary for “current user”; it does not appear to implement its own auth framework.
6. Presentation layer
- Views are server-side PHP templates under views/, with shared layout pieces in header.php, footer.php, and views/layout.php.
- There are dedicated pages for:
- auth forms (views/auth/login.php, views/auth/register.php),
- the main listing page (views/hole.php in the tree, likely a naming mismatch with the README’s annonces index),
- and other page-specific rendering.
- Styling is static CSS in public/css/style.css.
7. Data model and persistence
- Persistence is MySQL via PDO, configured in config/database.php and/or database.php.
- Schema files (schema.sql, users.sql) define the database tables, including:
- users,
- annonces,
- favorites,
- and the views counter on announcements.
- The models are the only layer that should talk to SQL directly.
8. Primary data flows
- Browse flow: request hits listing controller → model queries ads with optional filters → view renders cards/list.
- Detail flow: request for one ad → model fetches ad by id and increments views → detail view renders ad + favorite action.
- Favorite flow: authenticated user triggers add/remove → controller checks session → model updates favorite table → redirect back to favorites or detail page.
- Auth flow: login/register forms submit to auth controller → user model validates/persists → session becomes the source of identity for the rest of the app.
9. Access control boundaries
- Public access: listing pages and ad detail pages can be viewed without login.
- Private access: favorites actions and “my favorites” require a valid session.
- The README explicitly notes that the favorite button is checked both in controller and view, so access control is enforced at more than one layer.
10. Implementation conventions that matter architecturally
- Output escaping is done with htmlspecialchars(), so the view layer is security-aware.
- SQL uses PDO named parameters, indicating the model layer is the main security boundary against injection.
- The app is intentionally lightweight: no framework, no client-side SPA, and no separate API layer.
11. Notable repo structure mismatch
- The tree shows some classes at the repository root (Annonce.php, Favori.php, AnnonceController.php, FavoriController.php) while the README describes a more nested controllers/ and models/ layout.
- For an architecture diagram, treat these as the same logical layers: controllers, models, and views around a single PHP app, even if the physical file placement has drifted.
12. What to draw as the main boundaries
- A web server boundary (Apache/public root, rewrite rules).
- A PHP application boundary with router/controller/model/view layers.
- A MySQL persistence boundary accessed only through PDO models.
- A session/auth boundary that gates user-specific features like favorites.
Main entry points: layout.php Layout · AnnonceController.php Annonces · authentification.php Auth · router.php Router
Components 23
Web entry
HTTP entrypoints and rewrite layer
- Rewrite rules · Apache routing into the PHP front controller
.htaccess - Front controller · Main request entry that bootstraps the app
index.php - Router · Dispatches requests to the right controller or view
router.php - Detail page · Entry used for single-listing display
show.php
Application
Controllers and domain models
- Annonces · Listing browse, filter, and detail actions
AnnonceController.php - Favorites · Add, remove, and list user favorites
FavoriController.php - Auth · Login and registration handling
controllers/authentification.php - Annonce · Listing queries, filters, detail fetch, and view counting
Annonce.php - Favori · Favorite membership and favorite-list queries
Favori.php - User · User lookup and registration data access
models/user.php - Session · Current-user identity used by private actions
Presentation
Server-rendered pages and shared templates
- Layout · Shared page shell and page composition
views/layout.php - Listings · Main listing page for browsing ads
views/hole.php - Login · Authentication form for existing users
views/auth/login.php - Register · Account creation form
views/auth/register.php - Header · Common top-of-page template fragment
header.php - Footer · Common bottom-of-page template fragment
footer.php - Styles · Static site styling
public/css/style.css
Data
Database configuration and schema
- DB config · PDO connection setup used by models
config/database.php - DB bootstrap · Alternate database connection bootstrap
database.php - Schema · Database structure for users, annonces, and favorites
schema.sql - Users SQL · User-related SQL definition or seed data
users.sql - MySQL · Persistent store for listings, users, and favorites
Connections 29
- Rewrite rules → Front controller: rewrite · Clean URLs route into the PHP app
- Front controller → Router: dispatch · Bootstraps and sends the request to routing
- Router → Annonces: browse/detail · Listing routes are handled by the annonces controller
- Router → Favorites: favorites · Favorite routes are handled separately
- Router → Auth: auth · Login and registration routes go to auth
- Detail page → Annonces: delegate · Single-listing page uses the annonces domain flow
- Annonces → Annonce: query · Controller asks the model for lists and a single ad
- Favorites → Favori: mutate/query · Favorites actions use the favorites model
- Auth → User: validate/persist · Auth controller delegates user lookup and registration
- Annonce → DB config: pdo · Listing model uses the shared database connection
- Favori → DB config: pdo · Favorites model uses the shared database connection
- User → DB config: pdo · User model uses the shared database connection
- DB config → MySQL: connect · PDO connects to the MySQL backend
- DB bootstrap → MySQL: connect · Alternate DB bootstrap also targets MySQL
- Annonce → Schema: reads shape · Schema defines announcements and counters
- Favori → Schema: reads shape · Schema defines the favorites table
- User → Users SQL: reads shape · User storage is defined in the user SQL file
- Login → Auth: submit · Login form posts to auth
- Register → Auth: submit · Registration form posts to auth
- Layout → Header: includes · Shared shell composes the header fragment
- Layout → Footer: includes · Shared shell composes the footer fragment
- Layout → Styles: loads · Layout uses the global stylesheet
- Listings → Annonces: renders data · Listing view consumes controller-provided ads
- Login → Layout: wraps · Auth page is rendered inside the shared layout
- Register → Layout: wraps · Auth page is rendered inside the shared layout
- Annonces → Session: read user · Private actions inspect current user identity when needed
- Favorites → Session: gate private · Favorites depend on authenticated session state
- Favori → Session: user scope · Favorite queries are scoped to the current user
- Auth → Session: set user · Successful login/register establishes session identity