How adimyy/google_script works
Project type and purpose
• This is a single-service Node.js API (no separate frontend) designed to manage medication data and orders via Google Sheets and Google Drive.
• It exposes OAuth2 endpoints and a REST-style /api endpoint that accepts actions like “createsheet,” “storemedication,” and “storeorder.”
File structure
• Top-level files
• app.js → the entire Express-style HTTP server
• package.json / package-lock.json → defines Node.js dependencies (express, googleapis, dotenv, etc.)
• vercel.json → deployment configuration for Vercel serverless
• .gitignore, README.md → ancillary
• No “src/,” “services/,” or “controllers/” directories; everything lives in app.js, making this effectively a small monolith.
Key insights from the README
• Uses Google OAuth2 for authentication.
• Integrates two Google Services: Sheets API and Drive API.
• Manages a folder structure:
NAQQAS/
├── SHEETS_FOLDER/
│ └── [user_email]/
└── ORDER_FOLDER/
└── [user_email]/
• Hosted locally (node app.js) or on Vercel (serverless functions).
Main components
a. Client (web browser or other HTTP client)
b. API Server (Node.js/Express in app.js)
• OAuth2 module
• Sheets-management module
• Drive-management module
c. Google OAuth2 Authorization Server
d. Google Sheets API
e. Google Drive API
g. Environment Config (CLIENT_ID, etc.) shown as a secure vault
Relationships and interactions
• Client → GET /auth → API Server → Google OAuth2 → redirects back to /oauth2callback
• Client → GET/POST /api?action=… → API Server → calls Google Sheets API or Google Drive API
• API Server reads credentials from environment vault, refreshes tokens with OAuth2 server
• Google Drive API persists folder structure (NAQQAS/SHEETS_FOLDER & ORDER_FOLDER)
• Google Sheets API reads/writes rows for medication and order data
Architectural patterns and principles
• Monolithic service (single codebase) but functionally decomposed into:
• Authentication flow
• Resource management (Sheets vs. Drive)
• External service integration pattern
• Configuration-driven (dotenv + Vercel env vars)
• Stateless, REST-style HTTP API
Relevant technologies and libraries
• Express (HTTP routing)
• googleapis (Sheets & Drive clients + OAuth2 client)
• dotenv (local config)
• Vercel (serverless hosting)
• Node.js v14+