# jannat12-bot/leboncoin architecture

> Architecture diagram of the GitHub repository jannat12-bot/leboncoin, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jannat12-bot/leboncoin
- Repository: https://github.com/jannat12-bot/leboncoin

## Overview

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: [`views/layout.php`](https://github.com/jannat12-bot/leboncoin/blob/main/views/layout.php) (Layout), [`AnnonceController.php`](https://github.com/jannat12-bot/leboncoin/blob/main/AnnonceController.php) (Annonces), [`controllers/authentification.php`](https://github.com/jannat12-bot/leboncoin/blob/main/controllers/authentification.php) (Auth), [`router.php`](https://github.com/jannat12-bot/leboncoin/blob/main/router.php) (Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web entry"]
  node_apache_rewrite["Rewrite rules<br/>web config<br/>[.htaccess]"]
  node_front_controller["Front controller<br/>php entrypoint<br/>[index.php]"]
  node_router["Router<br/>php routing<br/>[router.php]"]
  node_detail_page["Detail page<br/>php page<br/>[show.php]"]
end

subgraph group_app["Application"]
  node_annonce_controller["Annonces<br/>controller"]
  node_favori_controller["Favorites<br/>controller"]
  node_auth_controller["Auth<br/>controller"]
  node_annonce_model[("Annonce<br/>model<br/>[Annonce.php]")]
  node_favori_model[("Favori<br/>model<br/>[Favori.php]")]
  node_user_model[("User<br/>model<br/>[user.php]")]
  node_session(("Session<br/>runtime state"))
end

subgraph group_ui["Presentation"]
  node_layout["Layout<br/>[layout.php]"]
  node_list_view["Listings<br/>view<br/>[hole.php]"]
  node_login_view["Login<br/>view<br/>[login.php]"]
  node_register_view["Register<br/>view<br/>[register.php]"]
  node_header["Header<br/>shared view<br/>[header.php]"]
  node_footer["Footer<br/>shared view<br/>[footer.php]"]
  node_styles["Styles<br/>css<br/>[style.css]"]
end

subgraph group_data["Data"]
  node_db_config["DB config<br/>pdo config<br/>[database.php]"]
  node_legacy_db["DB bootstrap<br/>pdo config<br/>[database.php]"]
  node_schema["Schema<br/>[schema.sql]"]
  node_users_schema["Users SQL<br/>sql seed<br/>[users.sql]"]
  node_mysql[("MySQL<br/>database")]
end

node_apache_rewrite -->|"rewrite"| node_front_controller
node_front_controller -->|"dispatch"| node_router
node_router -->|"browse/detail"| node_annonce_controller
node_router -->|"favorites"| node_favori_controller
node_router -->|"auth"| node_auth_controller
node_detail_page -->|"delegate"| node_annonce_controller
node_annonce_controller -->|"query"| node_annonce_model
node_favori_controller -->|"mutate/query"| node_favori_model
node_auth_controller -->|"validate/persist"| node_user_model
node_annonce_model -->|"pdo"| node_db_config
node_favori_model -->|"pdo"| node_db_config
node_user_model -->|"pdo"| node_db_config
node_db_config -->|"connect"| node_mysql
node_legacy_db -->|"connect"| node_mysql
node_annonce_model -.->|"reads shape"| node_schema
node_favori_model -.->|"reads shape"| node_schema
node_user_model -.->|"reads shape"| node_users_schema
node_login_view -->|"submit"| node_auth_controller
node_register_view -->|"submit"| node_auth_controller
node_layout -->|"includes"| node_header
node_layout -->|"includes"| node_footer
node_layout -->|"loads"| node_styles
node_list_view -->|"renders data"| node_annonce_controller
node_login_view -->|"wraps"| node_layout
node_register_view -->|"wraps"| node_layout
node_annonce_controller -->|"read user"| node_session
node_favori_controller -->|"gate private"| node_session
node_favori_model -.->|"user scope"| node_session
node_auth_controller -->|"set user"| node_session

click node_apache_rewrite "https://github.com/jannat12-bot/leboncoin/blob/main/.htaccess"
click node_front_controller "https://github.com/jannat12-bot/leboncoin/blob/main/index.php"
click node_router "https://github.com/jannat12-bot/leboncoin/blob/main/router.php"
click node_detail_page "https://github.com/jannat12-bot/leboncoin/blob/main/show.php"
click node_annonce_controller "https://github.com/jannat12-bot/leboncoin/blob/main/AnnonceController.php"
click node_favori_controller "https://github.com/jannat12-bot/leboncoin/blob/main/FavoriController.php"
click node_auth_controller "https://github.com/jannat12-bot/leboncoin/blob/main/controllers/authentification.php"
click node_annonce_model "https://github.com/jannat12-bot/leboncoin/blob/main/Annonce.php"
click node_favori_model "https://github.com/jannat12-bot/leboncoin/blob/main/Favori.php"
click node_user_model "https://github.com/jannat12-bot/leboncoin/blob/main/models/user.php"
click node_db_config "https://github.com/jannat12-bot/leboncoin/blob/main/config/database.php"
click node_legacy_db "https://github.com/jannat12-bot/leboncoin/blob/main/database.php"
click node_schema "https://github.com/jannat12-bot/leboncoin/blob/main/schema.sql"
click node_users_schema "https://github.com/jannat12-bot/leboncoin/blob/main/users.sql"
click node_layout "https://github.com/jannat12-bot/leboncoin/blob/main/views/layout.php"
click node_list_view "https://github.com/jannat12-bot/leboncoin/blob/main/views/hole.php"
click node_login_view "https://github.com/jannat12-bot/leboncoin/blob/main/views/auth/login.php"
click node_register_view "https://github.com/jannat12-bot/leboncoin/blob/main/views/auth/register.php"
click node_header "https://github.com/jannat12-bot/leboncoin/blob/main/header.php"
click node_footer "https://github.com/jannat12-bot/leboncoin/blob/main/footer.php"
click node_styles "https://github.com/jannat12-bot/leboncoin/blob/main/public/css/style.css"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_apache_rewrite,node_front_controller,node_router,node_detail_page toneBlue
class node_annonce_controller,node_favori_controller,node_auth_controller,node_annonce_model,node_favori_model,node_user_model,node_session toneAmber
class node_layout,node_list_view,node_login_view,node_register_view,node_header,node_footer,node_styles toneMint
class node_db_config,node_legacy_db,node_schema,node_users_schema,node_mysql toneRose
```

## Components

### Web entry

HTTP entrypoints and rewrite layer

- [Rewrite rules](https://github.com/jannat12-bot/leboncoin/blob/main/.htaccess): web config · Apache routing into the PHP front controller · `.htaccess`
- [Front controller](https://github.com/jannat12-bot/leboncoin/blob/main/index.php): php entrypoint · Main request entry that bootstraps the app · `index.php`
- [Router](https://github.com/jannat12-bot/leboncoin/blob/main/router.php): php routing · Dispatches requests to the right controller or view · `router.php`
- [Detail page](https://github.com/jannat12-bot/leboncoin/blob/main/show.php): php page · Entry used for single-listing display · `show.php`

### Application

Controllers and domain models

- [Annonces](https://github.com/jannat12-bot/leboncoin/blob/main/AnnonceController.php): controller · Listing browse, filter, and detail actions · `AnnonceController.php`
- [Favorites](https://github.com/jannat12-bot/leboncoin/blob/main/FavoriController.php): controller · Add, remove, and list user favorites · `FavoriController.php`
- [Auth](https://github.com/jannat12-bot/leboncoin/blob/main/controllers/authentification.php): controller · Login and registration handling · `controllers/authentification.php`
- [Annonce](https://github.com/jannat12-bot/leboncoin/blob/main/Annonce.php): model · Listing queries, filters, detail fetch, and view counting · `Annonce.php`
- [Favori](https://github.com/jannat12-bot/leboncoin/blob/main/Favori.php): model · Favorite membership and favorite-list queries · `Favori.php`
- [User](https://github.com/jannat12-bot/leboncoin/blob/main/models/user.php): model · User lookup and registration data access · `models/user.php`
- **Session**: runtime state · Current-user identity used by private actions

### Presentation

Server-rendered pages and shared templates

- [Layout](https://github.com/jannat12-bot/leboncoin/blob/main/views/layout.php): view layout · Shared page shell and page composition · `views/layout.php`
- [Listings](https://github.com/jannat12-bot/leboncoin/blob/main/views/hole.php): view · Main listing page for browsing ads · `views/hole.php`
- [Login](https://github.com/jannat12-bot/leboncoin/blob/main/views/auth/login.php): view · Authentication form for existing users · `views/auth/login.php`
- [Register](https://github.com/jannat12-bot/leboncoin/blob/main/views/auth/register.php): view · Account creation form · `views/auth/register.php`
- [Header](https://github.com/jannat12-bot/leboncoin/blob/main/header.php): shared view · Common top-of-page template fragment · `header.php`
- [Footer](https://github.com/jannat12-bot/leboncoin/blob/main/footer.php): shared view · Common bottom-of-page template fragment · `footer.php`
- [Styles](https://github.com/jannat12-bot/leboncoin/blob/main/public/css/style.css): css · Static site styling · `public/css/style.css`

### Data

Database configuration and schema

- [DB config](https://github.com/jannat12-bot/leboncoin/blob/main/config/database.php): pdo config · PDO connection setup used by models · `config/database.php`
- [DB bootstrap](https://github.com/jannat12-bot/leboncoin/blob/main/database.php): pdo config · Alternate database connection bootstrap · `database.php`
- [Schema](https://github.com/jannat12-bot/leboncoin/blob/main/schema.sql): sql schema · Database structure for users, annonces, and favorites · `schema.sql`
- [Users SQL](https://github.com/jannat12-bot/leboncoin/blob/main/users.sql): sql seed · User-related SQL definition or seed data · `users.sql`
- **MySQL**: database · Persistent store for listings, users, and favorites

## Connections

- 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
