Overview
SGD-MCS backend runs on Google Apps Script (GAS), a serverless JavaScript platform that provides direct integration with Google Workspace services including Sheets and Drive.The backend uses Apps Script V8 runtime for modern JavaScript support including ES6+ features.
Prerequisites
Google Account
A Google Workspace or Gmail account with access to Google Drive and Sheets
Node.js & clasp
Optional: Install clasp CLI for command-line deployment
Source Code
Clone the repository and navigate to the Backend directory
Google Sheets Database
A properly configured Google Sheets database (see Database Structure)
Apps Script Manifest
Theappsscript.json file configures the Apps Script project:
Configuration Options
Sets the default timezone for date/time operations. Uses IANA timezone identifiers.
JavaScript runtime version.
V8 enables modern ES6+ syntax, arrow functions, and more.Error logging destination.
STACKDRIVER logs to Google Cloud Logging for better debugging.OAuth 2.0 scopes required by the application:
spreadsheets- Read/write Google Sheets datadrive- Create and manage Drive folders/filesscript.external_request- Make external HTTP requests (if needed)
Execution context.
USER_DEPLOYING runs code with deployer’s permissions.Access control.
ANYONE_ANONYMOUS allows public access without authentication.Deployment Methods
Method 1: Using clasp (Recommended)
Create New Project
Navigate to the Backend directory and create a new Apps Script project:This generates a
.clasp.json file with your script ID.Push Code
Deploy all files to Google Apps Script:Use
clasp push --watch to enable auto-deployment on file changes.Method 2: Manual Upload
Create New Project
- Go to script.google.com
- Click “New Project”
- Rename to “SGD-MCS Backend”
Configure Manifest
- Click the gear icon (Project Settings)
- Check “Show appsscript.json manifest file”
- Edit
appsscript.jsonwith the configuration above
Create Files
Create each file from the
Backend/ directory structure:config.jscore/Main.jscore/EntityManager.jscore/controller.jsservices/DataService.jsservices/DriveManager.jsservices/DriveFileManager.jsservices/SearchService.jsutils/Utils.jsutils/DataUtils.js
File Structure
The backend follows a modular architecture:Key Functions
Entry Point: doGet()
Serves the web application:API Proxies
Apps Script requires global function declarations for client-side calls viagoogle.script.run. The Main.js file provides these proxies:
OAuth Scopes Explained
spreadsheets - Full Sheets Access
spreadsheets - Full Sheets Access
Scope:
https://www.googleapis.com/auth/spreadsheetsRequired for:- Reading student, faculty, thesis, and event data
- Writing new records and updates
- Auto-incrementing ID counters in Config sheet
- Audit logging to Historial_Documentos
drive - Drive File Management
drive - Drive File Management
Scope:
https://www.googleapis.com/auth/driveRequired for:- Creating entity folders (Students, Thesis, etc.)
- Uploading documents and certificates
- Organizing files into structured directories
- Moving files to trash on deletion
script.external_request - HTTP Requests
script.external_request - HTTP Requests
Scope:
https://www.googleapis.com/auth/script.external_requestRequired for:- Making external API calls (if needed)
- Webhook integrations
- Future extensibility
Testing Deployment
Updating the Script
Using clasp
Manual Update
- Open the script at script.google.com
- Edit the relevant files
- Save changes (Ctrl+S)
- Create new deployment or update existing one
Permissions and Security
Service Account
The script runs with the permissions of the deploying user. Ensure this account has:
- Owner or Editor access to the Google Sheets database
- Access to the Drive folder specified in
ROOT_FOLDER_ID - Appropriate organizational permissions
Public Access Warning
The default configuration allows anonymous public access. For production:
- Change
webapp.accessto"DOMAIN"(organization only) - Or change to
"ANYONE"(requires Google login) - Implement additional authentication in
doGet()if needed
Monitoring and Logs
View Execution Logs
- Open your Apps Script project
- Click “Executions” in the left sidebar
- View recent runs, errors, and execution times
Cloud Logging
WithexceptionLogging: "STACKDRIVER", errors are logged to Google Cloud:
- Go to console.cloud.google.com
- Select your Apps Script project
- Navigate to “Logging” → “Logs Explorer”
- Filter by severity and timestamp
Troubleshooting
Script Authorization Required
Script Authorization Required
Deployment Failed
Deployment Failed
Error: “Unable to deploy”Solution: Check that all file syntax is valid. Run “Debug” → “Check for errors” in the editor.
Scope Mismatch
Scope Mismatch
Error: “Access not granted”Solution: Verify all required scopes are in
appsscript.json. Re-authorize the script.Functions Not Found
Functions Not Found
Error: “Function not found” when calling from frontendSolution: Ensure functions are declared in global scope (Main.js proxies).
Next Steps
Configuration
Configure database connection and settings
Database Structure
Understand the Google Sheets schema
Permissions
Set up user roles and access control