How rteixe0/apae-backend works
Project type and purpose
• This is a full-stack back-end API (Node.js + Express) for managing events and tickets for APAE.
• It exposes REST endpoints for events, tickets, and validation, uses Firebase for auth, Firestore for data persistence, Storage for QR codes, and Node libraries for email and QR generation.
File structure
• Top-level:
• index.js – application entrypoint
• controllers/ – request handlers (eventsController, ticketsController, validationController)
• routes/ – route definitions mapping URLs to controllers
• middlewares/ – authMiddleware for JWT validation via Firebase
• services/ – low-level business logic (emailService, qrService)
• config/ – Firebase, email (SMTP) and storage configuration
• scripts/ – admin scripts for Firestore setup, token retrieval, custom claims
• webhook.js – standalone integration endpoint
• .github/workflows/deploy.yml – CI/CD pipeline
• Key patterns:
• Layered MVC-style (Routes → Controllers → Services → Data layer)
• BaaS integration via Firebase Admin SDK
Additional insights from README
• Uses environment variables for Firebase credentials and SMTP.
• Deploys to a Google Cloud VM via GitHub Actions.
• QR Codes are generated at runtime and stored in Firebase Storage.
a. Main components
1. Client(s)
– Frontend app, Postman, mobile apps generating HTTP requests
2. API Layer (Express)
– Routes
– Authentication Middleware (verifies JWT against Firebase Auth)
– Controllers (orchestrate use cases)
– Services (emailService, qrService)
3. Firebase BaaS
– Auth (JWT validation & custom claims)
– Firestore (Events, Tickets, Validations collections)
– Storage (QR code images)
4. External SMTP server (Gmail SMTP)
5. CI/CD Pipeline (GitHub Actions → Google Cloud VM)
b. Relationships & interactions
1. Client makes HTTP request → Express Routes
2. Route calls Auth Middleware → verifies JWT with Firebase Auth
3. Controller executes business logic → may invoke:
• qrService to generate QR code
• emailService to send ticket via SMTP
• Firestore via Firebase Admin to read/write data
• Firebase Storage to upload QR image
4. Response flows back to client
5. CI/CD: on merge to main → GitHub Actions runs deploy.yml → SSH/git pull on GCE VM → restarts Node service
c. Architectural patterns & principles
• Layered architecture: clear separation of routing, business logic, data access
• Dependency inversion: controllers depend on abstracted services (email, qr, database via Firebase Admin)
• Externalized configuration: all credentials in env
• Serverless-style backend: relies on third-party BaaS rather than custom DB servers
d. Key technologies/frameworks
• Node.js, Express
• Firebase Admin SDK (Auth, Firestore, Storage)
• Nodemailer (SMTP)
• QRCode library
• dotenv, cors, body-parser
• GitHub Actions for CI/CD