How vietrux/habacteam-api works
Project type and purpose
• This is a backend‐only RESTful API built with Node.js and Express.
• It exposes HTTP endpoints (see routes/index.js and routes/api.js) and relies on Firebase for data storage/logic (config/firebase.js).
• It also requires a Facebook Page access token (HMC_ACCESS_TOKEN), so it may call the Facebook Graph API as an external service.
File structure
• app.js
– Bootstraps Express, applies middleware (dotenv, body-parser, CORS, etc.), mounts routes.
• bin/www
– Standard Express startup script that reads the PORT and launches the HTTP server.
• config/firebase.js
– Initializes the Firebase Admin SDK with the service account JSON.
• routes/index.js
– May serve a health‐check or homepage.
• routes/api.js
– Defines the core REST endpoints for the API.
• package.json / package-lock.json
– Lists dependencies (express, firebase-admin, dotenv, etc.) and scripts (npm run dev).
• .gitignore & README.MD
– Git exclusions and basic setup docs.
README for additional insights
• Setup instructions confirm it’s a dev server listening on port 5500.
• Environment variables:
• HMC_ACCESS_TOKEN: used for calls to Facebook’s API
• FIREBASE_SERVICE_ACCOUNT: JSON string to initialize Firebase Admin
Main components
a. External Clients (Web front‐end, Mobile apps, Chatbot UI, or any HTTP consumer)
b. Load Balancer or Reverse Proxy (optional, e.g., Nginx)
c. Node.js / Express API Server
– Entry point: bin/www → app.js
– Middleware layer: dotenv, body parsing, CORS, logging
– Routing layer: routes/index.js, routes/api.js
– Config layer: config/firebase.js (Firebase Admin)
– Service/Controller logic (inside route handlers)
d. Firebase (Cloud Firestore or Realtime Database)
e. External Facebook Graph API
f. Environment & Secrets Store (dotenv or a secrets manager)
Relationships and data flows
• Within API Server, flow: HTTP Server → Middleware → Router → Controller →
• Either Firebase Admin SDK → Firebase
• Or HTTP client → Facebook Graph API
• Environment variables feeding into the server startup.
Architectural patterns & design principles
• Layered architecture: transport layer (HTTP), middleware, routing, service logic, external integrations.
• Single responsibility: each file/directory handles a clear concern (startup, routing, config).
• Externalize configuration via dotenv.
• Use of managed services (Firebase, Facebook API) to offload state and auth.