Skip to content

Implemented real-time online debate platform with structured phases and AI judgment using WebSocket and WebRTC #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9826e9b
Initial commit
ceilican Dec 3, 2024
463d7a2
Update README.md
keshav-nischal Dec 7, 2024
fb25239
basic and incomplete signup
keshav-nischal Dec 7, 2024
9894752
Merge pull request #1 from keshav-nischal/main
keshav-nischal Dec 7, 2024
835e63e
Authentication, Forgot Password, Integration with FE
sakshi-in-loops Dec 21, 2024
e53a827
Framework for POC & Auth update
sakshi-in-loops Jan 1, 2025
c5732c6
Bug Fixes & Transcript Addition
sakshi-in-loops Jan 21, 2025
0edf5fe
Frontend Refactoring
sakshi-in-loops Feb 2, 2025
c6e8b82
Merge pull request #31 from sakshi-in-loops/FERefactoring
keshav-nischal Feb 3, 2025
db76e22
refactored backend
Rishab87 Feb 9, 2025
1b3697b
git ignore in main folder
optmyzrKeshav Feb 26, 2025
db1408e
Merge pull request #1 from AOSSIE-Org/main
keshav-nischal Feb 26, 2025
fd95fd5
Merge pull request #42 from keshav-nischal/main
keshav-nischal Feb 26, 2025
22ff4cc
Merge pull request #35 from Rishab87/backend-refactor
keshav-nischal Feb 26, 2025
4676f2b
docs: new setup process
Naman-B-Parlecha Mar 2, 2025
416d1d6
Merge pull request #45 from Naman-B-Parlecha/doc/naman
keshav-nischal Mar 2, 2025
fb2c4ef
password hide-visible feature added
221fa04732 Mar 3, 2025
de5cf0d
Merge pull request #48 from 221fa04732/Feature-Request-Show-Hide-Pass…
keshav-nischal Mar 3, 2025
5a973b9
feat: enhance post-sign-in flow with profile and leaderboard UIs for …
rixitgithub Mar 27, 2025
5938dcb
chore: update config.prod.yml with descriptive placeholders
rixitgithub Mar 27, 2025
c0e167b
Merge remote-tracking branch 'origin/main'
rixitgithub Mar 31, 2025
61a7056
Enhance debate with diverse AI bot personalities, speech features, an…
rixitgithub Apr 1, 2025
a2c5927
feat: Implement real-time online debate platform with structured phas…
rixitgithub Apr 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions backend/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,91 @@ package main

import (
"log"
"os"
"strconv"

"arguehub/config"
"arguehub/db"
"arguehub/middlewares"
"arguehub/routes"
"arguehub/services"
"arguehub/utils"
"arguehub/websocket"

"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)

func main() {
// Load the configuration from the specified YAML file
cfg, err := config.LoadConfig("./config/config.prod.yml")
if err != nil {
log.Fatalf("Failed to load config: %v", err)
}

router := setupRouter(cfg)
services.InitDebateVsBotService(cfg)
// Connect to MongoDB using the URI from the configuration
if err := db.ConnectMongoDB(cfg.Database.URI); err != nil {
log.Fatalf("Failed to connect to MongoDB: %v", err)
}
log.Println("Connected to MongoDB")

// Seed initial debate-related data
utils.SeedDebateData()
utils.PopulateTestUsers()

// Create uploads directory
os.MkdirAll("uploads", os.ModePerm)

// Set up the Gin router and configure routes
router := setupRouter(cfg)
port := strconv.Itoa(cfg.Server.Port)
log.Printf("Server starting on port %s", port)

if err := router.Run(":" + port); err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}

func setupRouter(cfg *config.Config) *gin.Engine {
// gin.SetMode(gin.ReleaseMode) // Uncomment this line for production

router := gin.Default()

// Set trusted proxies (adjust as needed)
router.SetTrustedProxies([]string{"127.0.0.1", "localhost"})

// Configure CORS for your frontend (e.g., localhost:5173 for Vite)
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:5173"},
AllowMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
router.OPTIONS("/*path", func(c *gin.Context) { c.Status(204) })

router.OPTIONS("/*path", func(c *gin.Context) {
c.Status(204)
})

// Public routes for authentication
router.POST("/signup", routes.SignUpRouteHandler)
router.POST("/verifyEmail", routes.VerifyEmailRouteHandler)
router.POST("/login", routes.LoginRouteHandler)
router.POST("/forgotPassword", routes.ForgotPasswordRouteHandler)
router.POST("/confirmForgotPassword", routes.VerifyForgotPasswordRouteHandler)
router.POST("/verifyToken", routes.VerifyTokenRouteHandler)

router.GET("/ws", websocket.WebsocketHandler)

// Protected routes (JWT auth)
auth := router.Group("/")
auth.Use(middlewares.AuthMiddleware("./config/config.prod.yml"))
{
auth.GET("/user/fetchprofile", routes.GetProfileRouteHandler)
auth.PUT("/user/updateprofile", routes.UpdateProfileRouteHandler)
auth.GET("/leaderboard", routes.GetLeaderboardRouteHandler)
auth.POST("/debate/result", routes.UpdateEloAfterDebateRouteHandler)
routes.SetupDebateVsBotRoutes(auth)

// WebSocket signaling endpoint
auth.GET("/ws", websocket.WebsocketHandler)

routes.SetupTranscriptRoutes(auth)
}

return router
}
}
60 changes: 35 additions & 25 deletions backend/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,47 @@ package config

import (
"fmt"
"io/ioutil"
"io/ioutil"

"gopkg.in/yaml.v3"
"gopkg.in/yaml.v3"
)

type Config struct {
Server struct {
Port int `yaml:"port"`
} `yaml:"server"`

Cognito struct {
AppClientId string `yaml:"appClientId"`
AppClientSecret string `yaml:"appClientSecret"`
UserPoolId string `yaml:"userPoolId"`
Region string `yaml:"region"`
} `yaml:"cognito"`

Openai struct {
GptApiKey string `yaml:"gptApiKey"`
} `yaml:"openai`
Server struct {
Port int `yaml:"port"`
} `yaml:"server"`

Cognito struct {
AppClientId string `yaml:"appClientId"`
AppClientSecret string `yaml:"appClientSecret"`
UserPoolId string `yaml:"userPoolId"`
Region string `yaml:"region"`
} `yaml:"cognito"`

Openai struct {
GptApiKey string `yaml:"gptApiKey"`
} `yaml:"openai"`

Gemini struct {
ApiKey string `yaml:"apiKey"`
} `yaml:"gemini"`

Database struct {
URI string `yaml:"uri"`
} `yaml:"database"`
}

// LoadConfig reads the configuration file
func LoadConfig(path string) (*Config, error) {
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}
data, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read config file: %w", err)
}

var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("failed to unmarshal yaml: %w", err)
}
var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, fmt.Errorf("failed to unmarshal yaml: %w", err)
}

return &cfg, nil
return &cfg, nil
}
19 changes: 12 additions & 7 deletions backend/config/config.prod.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
server:
port: 1313
port: 1313

cognito:
appClientId:
appClientSecret:
userPoolId:
region:
appClientId: <your-cognito-app-client-id>
appClientSecret: <your-cognito-app-client-secret>
userPoolId: <your-cognito-user-pool-id>
region: eu-north-1

openai:
gptApiKey:

gptApiKey: <your-openai-gpt-api-key>

database:
uri: "<your-mongodb-connection-string>"

gemini:
apiKey: "<your-gemini-api-key>"
Loading