How adrirepa23/backend-rally works
Project type and purpose
• This is a RESTful backend service (“Backend Rally Fotográfico”) built with Node.js and Express. It exposes CRUD endpoints for users, rallies, publications, votes, comments and statistics.
• Although the README mentions MongoDB/Mongoose, your custom instruction specifies “Using MySQL,” so the system will use a MySQL database (initialized via basededatos.sql) accessed by an ORM.
• It also integrates with Cloudinary (image storage) and SendGrid (email notifications).
File structure
• Top-level files:
• basededatos.sql → MySQL schema & seed script.
• package.json, nodemon.json → build/run scripts & dependencies.
• src/config → configuration modules for DB, Cloudinary, SendGrid.
• src/routes → route definitions (one file per resource).
• src/controllers → handlers implementing business logic.
• src/models → data models (replace Mongoose models with ORM entities for MySQL).
• src/middlewares → shared middleware (auth, optional-auth, error handling).
• src/server.js → main entry point that wires everything together.
README for additional insights
• Security layers: Helmet, rate limiting, CORS, input validation.
• JWT-based authentication.
• Clear separation of config, models, controllers, routes and middleware, following an MVC-style layering.
a. Main components
• Client(s): Web or mobile frontend(s) consuming the API.
• API Gateway / Express Server:
– Routes layer (src/routes)
– Middleware layer (auth, CORS, rate limiter, error handler)
– Controller layer (src/controllers)
– ORM / Data access layer (src/models)
• MySQL Database cluster (based on schema in basededatos.sql)
• External Services: Cloudinary (image storage) and SendGrid (email service)
b. Relationships & data flow
1. Client → HTTP request → Express Server
2. Server → CORS → Rate Limiter → Auth Middleware → Route resolution
3. Route handler calls Controller → Controller uses ORM to query/update MySQL
4. Controller may call Cloudinary SDK to upload/fetch images
5. Controller may call SendGrid SDK to send emails
6. Controller returns data → Middleware error handling → Response → Client
c. Architectural patterns & design principles
• Layered (MVC) architecture with clear separation of concerns
• Stateless REST endpoints secured with JWT
• Centralized error handling and input validation
• Externalizing configuration via environment variables
d. Key technologies/frameworks
• Node.js, Express.js
• MySQL (with an ORM such as Sequelize or TypeORM)
• Cloudinary API
• SendGrid API
• Security: Helmet, express-rate-limit, CORS
• JWT for auth