Skip to content

SRM-IST-KTR/gcsrm_server

Repository files navigation

OCTACORE

A robust and scalable backend server for GitHub Club SRM (GCSRM) built with Node.js, Express.js, and MongoDB. This server provides RESTful APIs for managing club activities, events, team members, sponsors, certificates, and contact submissions.

πŸ“‹ Table of Contents

✨ Features

  • RESTful API Architecture - Clean and intuitive REST API design
  • MongoDB Integration - Robust database management with Mongoose ODM
  • Event Management - Complete CRUD operations for club events
  • Team Management - Manage team members and their roles
  • Sponsor Management - Track and manage club sponsors
  • Certificate Generation - Automated certificate generation and verification system
  • Contact Form Handler - Process and store contact form submissions with email notifications
  • Interactive API Documentation - Swagger UI for easy API exploration and testing
  • Security First - Helmet.js for security headers, CORS configuration
  • Request Logging - Morgan for HTTP request logging
  • Error Handling - Centralized error handling middleware
  • Database Health Checks - Automatic connection monitoring
  • Performance Monitoring - Sentry integration for error tracking
  • Development Hot Reload - Nodemon for efficient development

πŸ› οΈ Tech Stack

Core Technologies

  • Runtime: Node.js (v16+)
  • Framework: Express.js 5.x
  • Database: MongoDB 6.x with Mongoose 8.x
  • Language: JavaScript (ES6+)

Key Dependencies

  • Security: Helmet, CORS
  • Validation: Express-validator
  • Logging: Morgan
  • Documentation: Swagger (swagger-jsdoc, swagger-ui-express)
  • Email: Nodemailer
  • Image Processing: Sharp
  • PDF Generation: PDFKit
  • Font Handling: OpenType.js
  • Monitoring: Sentry
  • Environment: dotenv

Development Tools

  • Process Manager: Nodemon
  • Version Control: Git

πŸ—οΈ Architecture

The server follows a modular MVC (Model-View-Controller) architecture:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Client    β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Express.js Server          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Middleware Layer         β”‚  β”‚
β”‚  β”‚  - CORS                   β”‚  β”‚
β”‚  β”‚  - Helmet (Security)      β”‚  β”‚
β”‚  β”‚  - Request Logging        β”‚  β”‚
β”‚  β”‚  - Error Handling         β”‚  β”‚
β”‚  β”‚  - DB Health Check        β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Routes Layer             β”‚  β”‚
β”‚  β”‚  - /api/teams             β”‚  β”‚
β”‚  β”‚  - /api/sponsors          β”‚  β”‚
β”‚  β”‚  - /api/events            β”‚  β”‚
β”‚  β”‚  - /api/certificates      β”‚  β”‚
β”‚  β”‚  - /api/contact           β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Controllers Layer        β”‚  β”‚
β”‚  β”‚  - Business Logic         β”‚  β”‚
β”‚  β”‚  - Request Handling       β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚  Models Layer             β”‚  β”‚
β”‚  β”‚  - Mongoose Schemas       β”‚  β”‚
β”‚  β”‚  - Data Validation        β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
              β”‚
              β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚   MongoDB        β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

Before you begin, ensure you have the following installed:

Installation

  1. Clone the repository

    git clone https://github.com/SRM-IST-KTR/gcsrm_server.git
    cd gcsrm_server
  2. Install dependencies

    npm install
  3. Set up environment variables

    Create a .env file in the root directory:

    cp .env.example .env

    Then edit .env with your configuration (see Configuration section below).

  4. Start MongoDB

    If using local MongoDB:

    # macOS
    brew services start mongodb-community
    
    # Linux
    sudo systemctl start mongod
    
    # Windows
    net start MongoDB
  5. Start the development server

    npm run dev
  6. Verify the installation

    • API Server: http://localhost:3000
    • API Documentation: http://localhost:3000/api-docs
    • Health Check: http://localhost:3000/health

Configuration

Create a .env file with the following variables:

# Server Configuration
PORT=3000
NODE_ENV=development

# Database Configuration
MONGODB_URI=mongodb://localhost:27017/gcsrm
DB_NAME=gcsrm

# CORS Configuration (for production)
# ALLOWED_ORIGINS=https://yourdomain.com,https://www.yourdomain.com

# Sentry Configuration (Optional - for error monitoring)
SENTRY_DSN=your_sentry_dsn_here

# Email Configuration (for contact form notifications)
ZOHO_SMTP_PASS=your_app_specific_password
ZOHO_SMTP_USER=[email protected]

# Certificate Configuration
CERTIFICATE_SECRET=YOUR_CERTIFICATE_SECRET

Environment Variable Details

Variable Description Required Default
PORT Server port No 3000
NODE_ENV Environment (development/production) No development
MONGODB_URI MongoDB connection string Yes -
DB_NAME Database name Yes -
SENTRY_DSN Sentry error tracking DSN No -
ZOHO_SMTP_USER Email account username Yes* -
ZOHO_SMTP_PASS Email account password Yes* -
CERTIFICATE_SECRET Certificate verification Yes* -

πŸ“š API Documentation

This project uses Swagger/OpenAPI for comprehensive, interactive API documentation.

Accessing Documentation

Once the server is running, access the Swagger UI at:

http://localhost:3000/api-docs

The Swagger interface provides:

  • πŸ“– Complete API reference - All endpoints with descriptions
  • πŸ§ͺ Interactive testing - Try out APIs directly from the browser
  • πŸ“‹ Request/Response schemas - Detailed data models
  • πŸ” Authentication details - Required headers and authorization
  • πŸ’‘ Example requests - Sample payloads for each endpoint

πŸ“ Project Structure

gcsrm_server/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ app.js                      # Express application setup
β”‚   β”œβ”€β”€ controller/                 # Request handlers & business logic
β”‚   β”‚   β”œβ”€β”€ certificate.controller.js
β”‚   β”‚   β”œβ”€β”€ contact.controller.js
β”‚   β”‚   β”œβ”€β”€ event.controller.js
β”‚   β”‚   β”œβ”€β”€ sponsor.controller.js
β”‚   β”‚   └── team.controller.js
β”‚   β”œβ”€β”€ middleware/                 # Custom middleware functions
β”‚   β”‚   β”œβ”€β”€ dbCheck.js             # Database health check
β”‚   β”‚   β”œβ”€β”€ errorMiddleware.js     # Centralized error handling
β”‚   β”‚   └── requestLogging.js      # Request logging middleware
β”‚   β”œβ”€β”€ models/                     # Mongoose schemas & models
β”‚   β”‚   β”œβ”€β”€ certificate.model.js
β”‚   β”‚   β”œβ”€β”€ event.model.js
β”‚   β”‚   β”œβ”€β”€ sponsor.model.js
β”‚   β”‚   └── team.model.js
β”‚   β”œβ”€β”€ routes/                     # API route definitions
β”‚   β”‚   β”œβ”€β”€ index.js               # Main router
β”‚   β”‚   β”œβ”€β”€ certificate.route.js
β”‚   β”‚   β”œβ”€β”€ contact.route.js
β”‚   β”‚   β”œβ”€β”€ event.route.js
β”‚   β”‚   β”œβ”€β”€ sponsor.route.js
β”‚   β”‚   └── team.route.js
β”‚   └── utils/                      # Helper functions & utilities
β”‚       β”œβ”€β”€ db.js                  # Database connection
β”‚       β”œβ”€β”€ instrument.js          # Sentry instrumentation
β”‚       β”œβ”€β”€ mailer.js              # Email service
β”‚       β”œβ”€β”€ swagger.js             # Swagger configuration
β”‚       └── certificates/          # Certificate generation
β”‚           └── overlay-sharp.js   # Image processing for certificates
β”œβ”€β”€ index.js                        # Application entry point
β”œβ”€β”€ package.json                    # Dependencies & scripts
β”œβ”€β”€ Dockerfile                      # Docker configuration
β”œβ”€β”€ vercel.json                     # Vercel deployment config
β”œβ”€β”€ .env                           # Environment variables (not in repo)
β”œβ”€β”€ .env.example                   # Environment template

└── README.md                       # Project documentation

Key Directories

  • controllers/ - Contains business logic and request handling
  • models/ - Database schemas and data validation rules
  • routes/ - API endpoint definitions and route handlers
  • middleware/ - Custom Express middleware for cross-cutting concerns
  • utils/ - Helper functions, database connection, and utilities

πŸ’» Development

Available Scripts

# Start development server with hot reload
npm run dev

# Start production server
npm start

πŸš€ Deployment

Vercel Deployment

This project is configured for Vercel deployment.

  1. Install Vercel CLI

    npm install -g vercel
  2. Deploy to Vercel

    vercel
  3. Production deployment

    vercel --prod

Docker Deployment

  1. Build Docker image

    docker build -t gcsrm-server .
  2. Run container

    docker run -p 3000:3000 --env-file .env gcsrm-server

Environment-Specific Configuration

Production Checklist:

  • βœ… Set NODE_ENV=production
  • βœ… Use production MongoDB URI
  • βœ… Configure proper CORS origins
  • βœ… Set up Sentry DSN for error monitoring
  • βœ… Use strong email credentials
  • βœ… Enable HTTPS
  • βœ… Set up rate limiting (if needed)
  • βœ… Configure proper logging
  • βœ… Set up monitoring and alerts

Common HTTP Status Codes:

Code Meaning Description
200 OK Request successful
201 Created Resource created successfully
400 Bad Request Invalid request data
404 Not Found Resource not found
500 Internal Server Error Server error occurred

πŸ“„ License

This project is licensed under the ISC License. See the LICENSE file for details.

ISC License

Copyright (c) 2025 GitHub Club SRM

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

πŸ“ž Support

Need help? We're here for you!

Documentation

  • πŸ“– API Documentation: Visit /api-docs when the server is running
  • πŸ“‹ Certificate System: See CERTIFICATE_SYSTEM.md

Get in Touch

Useful Resources

οΏ½ Security

Reporting Security Issues

If you discover a security vulnerability, please DO NOT open a public issue. Instead:

  1. Email us at [email protected]
  2. Include a detailed description of the vulnerability
  3. Provide steps to reproduce (if applicable)
  4. We'll respond within 48 hours

Security Best Practices

This project implements:

  • βœ… Helmet.js for security headers
  • βœ… CORS configuration
  • βœ… Input validation with express-validator
  • βœ… Environment variable protection
  • βœ… Error message sanitization
  • βœ… MongoDB injection prevention (via Mongoose)

πŸ“ˆ Performance

Optimization Techniques

  • Database Indexing - Optimized queries with proper indexes
  • Connection Pooling - Efficient database connection management
  • Error Monitoring - Sentry integration for tracking issues

Monitoring

We use Sentry for:

  • Error tracking
  • Performance monitoring
  • Release health tracking

Built with ❀️ by GitHub Community SRM

Website β€’ GitHub β€’ LinkedIn

⭐ Star us on GitHub β€” it motivates us a lot!

Contributors 5