How tanvir-mahamood/resourcehub works
1. This repository is a monolithic PHP 8.x web application that sits between users and a private Google Drive. Its core architectural goal is to expose an authenticated, searchable resource catalog without ever exposing raw Drive URLs.
2. The application has three primary external dependencies: Google OAuth 2.0 for user sign-in, Google Drive API v3 via a service account for file and folder access, and MySQL for persistence. Everything else in the repo is application logic, UI rendering, or admin tooling.
3. index.php is the main user-facing entry point. It likely handles the landing page, login state, and rendering of the cached folder tree as a browsable resource hierarchy. index.css provides the custom UI layer, while Bootstrap and front-end libraries are used for layout, icons, and charts.
4. Authentication is handled by auth.php. The flow is OAuth-based rather than password-based: a Google login returns user identity data, which is then stored or updated in the users table. The app uses PHP sessions to maintain login state and role checks.
5. Authorization is simple and centralized: regular authenticated users can browse and interact with resources, while admins have access to maintenance and analytics screens. The admin boundary is implemented in admin/index.php and reinforced by server-side checks, not just UI hiding.
6. File access is mediated by proxy.php, which is the key security boundary in the system. Instead of linking directly to Drive, the app streams file content through the server after checking session/auth context and then retrieves the content from Google Drive using the service account. This keeps Drive links hidden and allows download/view events to be logged.
7. The resource hierarchy is not fetched live on every page request. refresh_cache.php crawls the Drive folder tree and stores a JSON representation in drive_cache. This cached tree is what makes recursive, nested browsing fast and reduces repeated Drive API calls.
8. User engagement actions are separated into lightweight AJAX-style endpoints. star.php toggles star/unstar state and updates counts, while download/view events are recorded in user_activity_log and aggregated into resource_metrics. The data model supports both per-file metrics and per-user behavior tracking.
9. The database is the app’s state boundary. db.php provides the PDO connection used across the app, and database_schema.sql defines the persistent entities: users, resource metrics, user stars, activity logs, and the cached Drive tree. setup_db.php is a one-time bootstrap path for initializing that schema.
10. The admin dashboard acts as an operational control plane rather than a separate application. It combines database-backed KPIs like total users, downloads over time, top resources, and active users, plus a manual cache refresh control that synchronizes the app with the underlying Drive structure.
11. From a data-flow perspective, the main loop is: Google login creates a session and user row, the cached Drive tree is read from MySQL for browsing, user interactions generate metric writes, and file requests are proxied to Google Drive through the server. The app never gives the browser direct access to the storage backend.
12. Deployment is classic PHP/MySQL hosting with Composer-managed dependencies and environment-specific secrets kept out of version control. config.php and the service account JSON are local-only configuration artifacts, which is important because the application depends on both OAuth credentials and Drive access permissions to function securely.
Main entry points: database_schema.sql Schema · auth.php Sign-in · refresh_cache.php Cache refresh · db.php PDO access
Components 19
Core app
User-facing browsing, auth, and interaction flow.
- Catalog UI · Main user-facing page for browsing the cached resource hierarchy and rendering the landing/auth state.
index.php - Sign-in · Google OAuth login flow; creates or updates user records and establishes the session.
auth.php - File proxy · Server-side download/view boundary that checks session context and streams Drive content without exposing raw URLs.
proxy.php - Star action · Lightweight endpoint for starring and unstarring resources and updating engagement state.
star.php - Cache refresh · Crawls Google Drive folder structure and rebuilds the cached JSON tree in the database.
refresh_cache.php - Composer deps · Managed PHP dependencies used by the application runtime.
composer.json - Local config · Example configuration for secrets and environment-specific settings.
config.example.php - UI styles · Custom front-end styling for the catalog interface.
index.css
Data layer
Database schema, connection, and cache persistence.
- PDO access · Shared database connection used by the application.
db.php - Schema · Persistent model for users, cached Drive tree, metrics, stars, and activity logs.
database_schema.sql - Bootstrap DB · One-time initialization path for creating and seeding the database schema.
setup_db.php - Users · Authenticated identities and role state stored after Google sign-in.
database_schema.sql - Drive cache · Cached folder/file tree used for fast recursive browsing.
database_schema.sql - Metrics · Aggregated resource counts and usage statistics for the dashboard.
database_schema.sql - Activity log · Per-user view/download/star events for auditing and aggregation.
database_schema.sql - Stars · Per-user favorite state for resources.
database_schema.sql
External services
Google OAuth and Drive integrations.
- Google OAuth · Identity provider used for user sign-in.
- Google Drive · Private document store accessed through a service account and proxied by the app.
Admin control
Operational dashboard and maintenance actions.
- Admin dashboard · Operational screen for KPIs, active users, top resources, and manual maintenance controls.
admin/index.php
Connections 29
- Catalog UI → PDO access: reads cache · Loads the cached resource tree and related state from MySQL.
- Catalog UI → Sign-in: login flow · Routes unauthenticated users into Google sign-in.
- Sign-in → Google OAuth: authenticate · Delegates identity verification to Google OAuth.
- Sign-in → Users: upsert user · Creates or updates the logged-in user record.
- Sign-in → PDO access: persist session user · Writes user state through the shared database connection.
- File proxy → Google Drive: stream file · Fetches protected file content from Google Drive via service account.
- File proxy → PDO access: log access · Records downloads or views through persistent storage.
- File proxy → Activity log: append event · Creates user activity entries for proxied file requests.
- Star action → Stars: toggle star · Updates per-user star state for a resource.
- Star action → Metrics: update counts · Adjusts aggregated engagement metrics.
- Star action → Activity log: log action · Records star/unstar interactions.
- Cache refresh → Google Drive: crawl tree · Traverses folders and files from Google Drive.
- Cache refresh → Drive cache: write cache · Stores the computed hierarchy as a cached tree.
- Cache refresh → PDO access: persist tree · Writes refreshed cache data through MySQL.
- Admin dashboard → Metrics: read KPIs · Displays dashboard metrics such as downloads and active users.
- Admin dashboard → Activity log: read activity · Uses activity history for operational reporting.
- Admin dashboard → Cache refresh: refresh cache · Triggers manual synchronization of the Drive tree.
- Schema → Users: defines · Declares the users table.
- Schema → Drive cache: defines · Declares the cached Drive tree table.
- Schema → Metrics: defines · Declares the metrics table.
- Schema → Activity log: defines · Declares the user activity log table.
- Schema → Stars: defines · Declares the stars table.
- Bootstrap DB → Schema: initializes · Bootstraps the database schema.
- Catalog UI → UI styles: styles with · Uses the custom CSS layer for the catalog UI.
- Catalog UI → Composer deps: loads deps · Runs with Composer-managed PHP dependencies.
- Sign-in → Local config: reads secrets · Uses local configuration for OAuth and service account settings.
- File proxy → Local config: reads secrets · Uses local configuration for Drive access credentials.
- Cache refresh → Local config: reads secrets · Uses local configuration for Drive crawling credentials.
- Admin dashboard → PDO access: reads data · Fetches dashboard data through the shared database connection.