How matteo-grellier/projet_forum works
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