This is the backend repository for the ACM Officer Database
- Node.js (v18 or higher)
- npm or yarn
- Firebase Admin SDK credentials
- Google Cloud SDK (for deployment)
-
Clone the repository
git clone https://github.com/acmutd/officer-database-backend.git cd officer-database-backend -
Install dependencies
npm install
-
Configure Firebase credentials
Caution
Never commit firebase-creds.json to version control!
- Go to Firebase Console
- Select your project
- Navigate to Project Settings → Service Accounts
- Click Generate New Private Key
- Save the downloaded file as
firebase-creds.jsonin the project root
-
Build the TypeScript code
npm run build
-
Start the development server
npm run devThis starts a local Express server on http://localhost:8080 that runs all endpoints simultaneously. No need to select or run individual functions—just start the server and call any endpoint.
Available endpoints:
GET /getOfficers- Retrieve all officersGET /getOfficer?id={id}- Get a single officer by IDPOST /createOfficer- Create a new officerPATCH /updateOfficer?id={id}- Update an officerDELETE /deleteOfficer?id={id}- Delete an officerPOST /archiveOfficer?id={id}- Archive an officer (setsisActiveto false)POST /unarchiveOfficer?id={id}- Unarchive an officer (setsisActiveto true)POST /uploadOfficerPhoto- Upload officer photo (multipart/form-data)POST /uploadOfficerResume- Upload officer resume (multipart/form-data)GET /getOfficerResume?id={id}- Get signed URL for officer resume
officer-database-backend/
├── src/
│ ├── functions/ # Cloud Functions (CRUD operations)
│ │ ├── archiveOfficer.ts
│ │ ├── createOfficer.ts
│ │ ├── deleteOfficer.ts
│ │ ├── getOfficer.ts
│ │ ├── getOfficerResume.ts
│ │ ├── getOfficers.ts
│ │ ├── index.ts
│ │ ├── unarchiveOfficer.ts
│ │ ├── updateOfficer.ts
│ │ ├── uploadOfficerPhoto.ts
│ │ └── uploadOfficerResume.ts
│ ├── helpers/ # Validation utilities
│ │ └── validators.ts
│ ├── types/ # TypeScript types and Zod schemas
│ │ └── officer.ts
│ ├── middleware.ts # Request validation middleware
│ ├── firebase.ts # Firebase Admin SDK initialization
│ └── index.ts # Function exports
├── tests/ # Test scripts
│ └── deploy.ts
├── dist/ # Compiled JavaScript (generated)
├── firebase-creds.json # Firebase credentials (not in git)
├── cloudbuild.yaml
├── package.json
├── tsconfig.json
├── API_DOCUMENTATION.md
└── README.md
- Local: Uses an Express server to run all functions simultaneously on a single port (8080 by default). Start the server with
npm run devto access all endpoints. - Production: Serverless Cloud Functions deployed on Google Cloud Platform (GCP). Each function has its own endpoint URL.
- Database: Firestore database on Firebase with two collections:
officer(current officers) andarchived(archived officers)
| Environment | Server | URL Structure |
|---|---|---|
| Local | Express server running all functions | http://localhost:8080/ENDPOINT_NAME |
| Production | Serverless Cloud Functions on GCP | https://REGION-PROJECT.cloudfunctions.net/FUNCTION_NAME |
"Cannot find module" errors:
- Run
npm run buildto compile TypeScript
Firebase authentication errors:
- Verify
firebase-creds.jsonexists in project root - Check that the service account has Firestore permissions
Port already in use:
- Change the port in
package.jsondev script or kill the process using port 8080
Type errors:
- Run
npm installto ensure all@types/*packages are installed