How jesusdev1294/api_business works
Project Type and Purpose
• This is a Node.js-based backend API (“indicators-backend”) that runs as serverless functions (via Serverless Framework + AWS Lambda) or inside a Docker container on EC2.
• Its responsibilities are: expose HTTP endpoints (via Express wrapped in serverless-http), implement business logic in controllers (lof.controller, search.controller), and persist/query data via a relational database through a data service layer (src/db).
File Structure Analysis
• Top-level:
• serverless.yml – defines AWS Lambda + API Gateway resources.
• Docker-related files (Dockerfile inferred, Docker commands in README).
• src/app.js – Express application entry.
• src/controllers – HTTP request handlers.
• src/db – data-access layer (connection, init, service, models).
• src/json – sample/reference data (employees.json).
• Patterns:
• Separation of concerns: HTTP layer → Controllers → Data Service → Database.
• Use of ORM models under src/db/models.
• Configurable execution environments: serverless offline, Docker container, PM2 on EC2.
README Insights
• Commands to spin up locally with Serverless Offline or Docker.
• Indicates deployment targets: AWS Lambda (via Serverless Framework) and EC2 container (Docker + PM2).
• Dependencies: express, serverless-http, serverless-offline, pm2, plus a relational DB driver.
a. Main Components
• Client(s): UI, CLI tools, third-party services.
• API Gateway (AWS) – routes HTTP(s) to Lambda.
• Compute layer:
– AWS Lambda functions running Express (wrapped by serverless-http)
– Docker container (app-indicator) running the same Express app under PM2 on EC2
• Controllers (lof.controller.js, search.controller.js)
• Data Service (src/db/dataService.js) & Connection Manager (src/db/connection.js)
• Relational Database (e.g., AWS RDS / another SQL engine) with schema defined by ORM models
• Sample Data / JSON store (for local/testing)
b. Relationships / Interactions
1. Client issues HTTP request → API Gateway (or EC2 load balancer)
2. Gateway invokes Lambda / routes to EC2 container
3. Express app (app.js) receives request → dispatches to Controller
4. Controller calls Data Service → uses Connection → reads/writes via ORM models to the Database
5. Database returns data → flows back up through Service → Controller → HTTP response
c. Architectural Patterns
• Layered architecture: Presentation (HTTP/API) → Business Logic (controllers) → Data Access (service + models) → Persistence (DB)
• Serverless microservice for on-demand scaling, with a parallel Docker/EC2 deployment option for long-running processes or compatibility
• Configuration via serverless.yml and environment templates for dev/prod
d. Key Technologies
• Node.js + Express + serverless-http
• Serverless Framework + serverless-offline plugin
• Docker + PM2 (on EC2)
• ORM (e.g., Sequelize) under src/db/models
• JSON as mock/test data source