# matteo-grellier/projet_forum architecture

> Architecture diagram of the GitHub repository matteo-grellier/projet_forum, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/matteo-grellier/projet_forum
- Repository: https://github.com/matteo-grellier/projet_forum

## Overview

##### Project Type and Purpose
- This is a monolithic full-stack web application (“Projet_Forum”) written in Go.
- Purpose: provide a classic online forum where users can register/login, create topics and posts, like/dislike content, comment, and filter by category or personal activity.

##### File Structure Analysis
- server.go: entry point that starts the HTTP server and routes requests.
- handlers/: Go packages that implement HTTP handlers (controllers), session management (cookies, uuid), input validation, error pages, and page rendering.
- BDD/: data-access layer (models) providing all database operations (user creation, post insertion, filtering, likes, comments), against a SQLite file.
- static/: client-side assets (CSS, JavaScript, images).
- .github/workflows/: CI for Go build/tests and Jekyll docs.
- README.md: project description, tech stack, architecture overview.

##### Core Architecture
- Pattern: a simple MVC-style structure
- Model = BDD layer
- View = templates + static assets
- Controller = handlers + router in server.go
- Single HTTP web server (8080) that:
- Serves HTML pages by executing templates with data from BDD functions.
- Serves static assets directly (CSS/JS/images).
- Manages user sessions with secure cookies (uuid), hashing passwords with bcrypt.
- Data store: embedded SQLite database.

##### Main Components
a. Client (Web Browser)
b. Web Server (Golang process)
- HTTP Router (net/http + handler.go)
- Controller Layer (handlers/*.go)
- Session Manager (cookies + uuid)
- Auth Utilities (bcrypt hashing)
c. Data-Access Layer (BDD/*.go)
d. Database (SQLite file)
e. Static File Server (serving /static)
f. Template Engine (Go html/template reading templates/)

##### Relationships and Data Flows
- User → HTTP Request → Router → appropriate Handler
- Handler ↔ Model (calls BDD functions → SQL statements → SQLite)
- Handler → Template Engine → Render HTML → Response to Client
- Static asset requests bypass controllers and map → Static File Server
- Login/Logout: Handler ↔ Session Manager ↔ Cookies in Client
- Password storage: Handler ↔ bcrypt library ↔ BDD writes hashed password

##### Important Patterns and Design Principles
- Single responsibility per package: BDD only does data logic, handlers only HTTP logic.
- Layered architecture: Presentation (templates/static), Application (handlers), Data (BDD).
- Secure practices: hashed passwords, cookie expiration.
- Separation of concerns: templates decouple HTML structure from data logic.

##### Relevant Technologies
- Language: Go (net/http, html/template)
- Database: SQLite via mattn/go-sqlite3
- Security: golang.org/x/crypto/bcrypt
- Sessions: github.com/google/uuid
- Frontend: HTML5, CSS3, vanilla JavaScript

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Client Side"
        classDef frontend fill:#AED6F1,stroke:#3498DB,color:#1B4F72
        Browser["Web Browser"]:::frontend
        Static["Static File Server"]:::frontend
        PageTemplates["Page Templates (HTML)"]:::frontend
        Layouts["Layout Templates"]:::frontend
    end

    subgraph "Server Side"
        classDef server fill:#ABEBC6,stroke:#27AE60,color:#145A32
        Server["Web Server (Golang)"]:::server
        Router["HTTP Router"]:::server
        subgraph "Controller Layer"
            Connexion["handlers/connexion.go"]:::server
            Inscription["handlers/inscription.go"]:::server
            Cookies["handlers/cookies.go"]:::server
            Color["handlers/color.go"]:::server
            Errors["handlers/errors.go"]:::server
            CommonHandler["handlers/common.go"]:::server
        end
        Session["Session Manager"]:::server
        Auth["Auth Utilities (bcrypt)"]:::server
        subgraph "Data-Access Layer (BDD)"
            addBDD["BDD/addBDD.go"]:::server
            displayBDD["BDD/displayBDD.go"]:::server
            verifyBDD["BDD/verifyBDD.go"]:::server
            commonBDD["BDD/common.go"]:::server
            schemaSQL["BDD/bdd.sql"]:::server
        end
    end

    subgraph "Data Store"
        classDef db fill:#F9E79F,stroke:#D68910,color:#7E5109
        SQLite["SQLite Database File"]:::db
    end

    %% Data Flows
    Browser -->|HTTP Request| Router
    Browser -->|Static Asset Request| Static
    Router -->|routes to| Connexion
    Router -->|routes to| Inscription
    Router -->|routes to| Cookies
    Router -->|routes to| Color
    Router -->|routes to| Errors
    Router -->|routes to| CommonHandler

    Connexion -->|calls| Auth
    Inscription -->|calls| Auth
    Connexion -->|uses| Session
    Cookies -->|manages| Session
    CommonHandler -->|helps| Session

    Connexion -->|calls| addBDD
    Inscription -->|calls| addBDD
    Connexion -->|calls| verifyBDD
    Color -->|calls| displayBDD
    Errors -->|renders| PageTemplates

    Connexion -->|render HTML| PageTemplates
    Inscription -->|render HTML| PageTemplates
    Color -->|render HTML| PageTemplates
    Errors -->|render HTML| PageTemplates
    CommonHandler -->|render HTML| PageTemplates

    PageTemplates -->|includes| Layouts

    Connexion -->|queries| commonBDD
    Inscription -->|queries| commonBDD
    addBDD -->|executes SQL| SQLite
    displayBDD -->|executes SQL| SQLite
    verifyBDD -->|executes SQL| SQLite
    commonBDD -->|executes SQL| SQLite

    %% Click events
    click Static "https://github.com/matteo-grellier/projet_forum/tree/main/static/"
    click PageTemplates "https://github.com/matteo-grellier/projet_forum/tree/main/templates/"
    click Layouts "https://github.com/matteo-grellier/projet_forum/tree/main/templates/layouts/"
    click Server "https://github.com/matteo-grellier/projet_forum/blob/main/server.go"
    click Router "https://github.com/matteo-grellier/projet_forum/blob/main/handlers/handler.go"
    click Connexion "https://github.com/matteo-grellier/projet_forum/blob/main/handlers/connexion.go"
    click Inscription "https://github.com/matteo-grellier/projet_forum/blob/main/handlers/inscription.go"
    click Cookies "https://github.com/matteo-grellier/projet_forum/blob/main/handlers/cookies.go"
    click Color "https://github.com/matteo-grellier/projet_forum/blob/main/handlers/color.go"
    click Errors "https://github.com/matteo-grellier/projet_forum/blob/main/handlers/errors.go"
    click CommonHandler "https://github.com/matteo-grellier/projet_forum/blob/main/handlers/common.go"
    click addBDD "https://github.com/matteo-grellier/projet_forum/blob/main/BDD/addBDD.go"
    click displayBDD "https://github.com/matteo-grellier/projet_forum/blob/main/BDD/displayBDD.go"
    click verifyBDD "https://github.com/matteo-grellier/projet_forum/blob/main/BDD/verifyBDD.go"
    click commonBDD "https://github.com/matteo-grellier/projet_forum/blob/main/BDD/common.go"
    click schemaSQL "https://github.com/matteo-grellier/projet_forum/blob/main/BDD/bdd.sql"
    click SQLite "https://github.com/matteo-grellier/projet_forum/blob/main/BDD/BDDForum1.db"
    
    %% Styles
    class Browser,Static,PageTemplates,Layouts frontend
    class Server,Router,Connexion,Inscription,Cookies,Color,Errors,CommonHandler,Session,Auth,addBDD,displayBDD,verifyBDD,commonBDD,schemaSQL server
    class SQLite db
```
