Skip to content

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

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages