Skip to content

RedaAz07/forum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

161 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forum Application

A modern web-based forum application built with Go, featuring user authentication, post management, comments, and a like/reaction system.

Features

  • 🔐 User Authentication - Secure login and registration system
  • 📝 Create Posts - Users can create forum posts with categories
  • 💬 Comments - Add and manage comments on posts
  • 👍 Likes & Reactions - React to posts and comments
  • 🏷️ Categories - Organize posts by categories
  • 👤 User Profiles - View posts created by specific users
  • 🎨 Responsive UI - Clean and intuitive user interface with CSS styling
  • 🐳 Docker Support - Easy deployment with Docker

Prerequisites

Before you begin, ensure you have the following installed:

  • Go 1.23.0 or higher (Download Go)
  • SQLite3 (usually comes with most systems)
  • Git (optional, for cloning the repository)

Optional

  • Docker - If you want to run the application in a container

Installation

1. Clone or Download the Project

git clone <repository-url>
cd forum

2. Install Dependencies

go mod download

This will download all required Go modules:

  • google/uuid - For generating unique identifiers
  • mattn/go-sqlite3 - SQLite database driver
  • golang.org/x/crypto - For password hashing

Usage

Running Locally

  1. Start the application:
go run ./cmd/main.go
  1. Access the application:

Open your browser and navigate to:

http://localhost:8080/
  1. Create an account:

    • Click on "Register"
    • Fill in your username and password
    • Submit the form
  2. Start using the forum:

    • Create new posts
    • Add comments to existing posts
    • Like posts and comments
    • Filter posts by categories or your own posts

Building the Application

To build a standalone executable:

go build -o main ./cmd/main.go
./main

Running with Docker

  1. Build the Docker image:
docker build -t forum:latest .
  1. Run the container:
docker run -p 8080:8080 forum:latest
  1. Access the application:

Open your browser and navigate to:

http://localhost:8080/

Project Structure

forum/
├── cmd/
│   └── main.go                 # Application entry point
├── handlers/                   # HTTP request handlers
│   ├── HomeHandler.go          # Home page handler
│   ├── LoginHandler.go         # Login logic
│   ├── LoginShowHandler.go     # Login page display
│   ├── RegisterHandler.go      # Registration logic
│   ├── RegisterShowHandler.go  # Registration page display
│   ├── CreatePost.go           # Create post handler
│   ├── DeletePost.go           # Delete post handler
│   ├── Comment.go              # Comment handler
│   ├── CommentsLikeHandler.go  # Like comments handler
│   ├── Reaction.go             # Post reaction handler
│   ├── Filter_By_Categorie.go  # Filter by category
│   ├── Filter_By_My_Posts.go   # Filter user's posts
│   ├── Filter_by_Liked_Posts.go # Filter liked posts
│   ├── UploadHandler.go        # File upload handler
│   ├── LogOutHandler.go        # Logout handler
│   ├── StyleHandler.go         # CSS/static file handler
│   └── Reaction.go             # Post reactions
├── middleware/                 # Middleware functions
│   ├── Auth.go                 # Authentication middleware
│   ├── login.go                # Login middleware
│   ├── Posts.go                # Posts middleware
│   ├── Likes.go                # Likes middleware
│   ├── comments.go             # Comments middleware
│   └── structures.go           # Data structures
├── helpers/                    # Helper functions
│   ├── db.go                   # Database connection
│   ├── AllCategories.go        # Fetch all categories
│   ├── fetchCategoy.go         # Fetch category info
│   ├── fetchComments.go        # Fetch comments
│   ├── GetUsernameFromSession.go # Session management
│   ├── RanderTemplate.go       # Template rendering
│   ├── Sessionchecked.go       # Session validation
│   ├── formatDuration.go       # Date/time formatting
│   └── PageDeleted.go          # Deleted page handler
├── routes/
│   └── route.go                # Route definitions
├── utils/
│   └── Utils.go                # Utility functions
├── template/                   # HTML templates
│   ├── home.html               # Home page template
│   ├── login.html              # Login page template
│   ├── register.html           # Registration template
│   └── statusPage.html         # Status page template
├── static/                     # Static assets
│   ├── home.css                # Home page styling
│   ├── login.css               # Login page styling
│   ├── navbar.css              # Navigation styling
│   ├── register.css            # Registration styling
│   ├── status_Page.css         # Status page styling
│   └── images/                 # Image assets
├── db/
│   └── query.sql               # Database schema and queries
├── Dockerfile                  # Docker configuration
├── go.mod                      # Go module definition
└── README.md                   # This file

Technologies Used

  • Backend: Go 1.23.0
  • Database: SQLite3
  • Frontend: HTML5, CSS3
  • Authentication: Session-based with bcrypt password hashing
  • Containerization: Docker
  • Utilities: UUID for unique identifiers

API Routes

The forum provides the following main routes:

Route Method Description
/ GET Home page
/register GET/POST User registration
/login GET/POST User login
/logout GET User logout
/create-post GET/POST Create new post
/delete-post POST Delete post
/comment POST Add comment
/like POST Like/unlike post
/reaction POST React to post
/filter GET Filter posts by category
/my-posts GET View user's posts
/liked-posts GET View liked posts

Database

The application uses SQLite3 as its database. The database schema is defined in db/query.sql.

Database Features

  • User accounts with password hashing
  • Posts with categories and timestamps
  • Comments with author tracking
  • Like/reaction tracking
  • Session management

Session Management

  • User sessions are tracked after successful login
  • Sessions are validated on each request requiring authentication
  • Logout clears the user session

Troubleshooting

Port Already in Use

If port 8080 is already in use, modify the port in cmd/main.go:

err = http.ListenAndServe(":YOUR_PORT", nil)

Database Issues

If you encounter database errors:

  1. Ensure SQLite3 is installed
  2. Delete the existing database file and restart the application
  3. Check db/query.sql for schema requirements

Template Loading Error

Ensure all HTML template files are in the template/ directory:

  • home.html
  • login.html
  • register.html
  • statusPage.html

Development

Building for Production

go build -o forum ./cmd/main.go

Running Tests

Currently, no test suite is configured. Consider adding tests in the future.

Contributing

To contribute to this project:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test your changes thoroughly
  5. Submit a pull request

License

This project is open source and available under the MIT License.

Authors

  • mennaas
  • abalouri
  • abaid
  • ranniz
  • ychatoua

Support

For issues or questions, please create an issue in the repository or contact the maintainers.


Happy Forumming! 🎉

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors