How jabesinhoo/asesores_tecnonacho works
This repository is a small Node.js application for managing “cards de asesores” with a public-facing site and an authenticated admin area.
1. Overall shape
- The app is split into three request domains: public, auth, and admin.
- Server-side code lives in server.js, app.js, routes/, controllers/, middlewares/, utils/, and db.js.
- Client-side assets are prebuilt and served from public/, with simple HTML entry pages in views/.
2. Runtime and framework boundary
- The architecture is typical of an Express-style Node.js backend: routes dispatch to controllers, controllers use shared database and utility modules, and middleware handles cross-cutting concerns.
- server.js is the runtime entrypoint, while app.js likely wires middleware, static assets, and route mounts.
3. Public-facing surface
- routes/public.routes.js serves the public experience, backed by controllers/advisors.controller.js.
- The public UI is mostly static assets under public/, including public/index.html, public/js/public.js, and public/styles.css.
- This side of the app is likely used to list or display advisor cards without authentication.
4. Admin surface
- routes/admin.routes.js and views/admin.html define the protected management area.
- public/js/admin.js is the browser-side code for admin interactions.
- The admin area is the place where advisor records are created, updated, or deleted, and where uploads are probably handled.
5. Authentication flow
- routes/auth.routes.js and controllers/auth.controller.js implement login/logout or session establishment for admins.
- views/login.html and public/js/login.js provide the login UI.
- middlewares/loginLimiter.js adds brute-force protection around the login path.
- middlewares/requireAdmin.js protects admin endpoints after authentication.
6. Data layer
- db.js centralizes database access.
- The presence of SQL migrations in migrations/001_init.sql and migrations/002_whatsapp_unique.sql indicates a relational database schema managed via migration files rather than ORM-first modeling.
- scripts/migrate.js applies schema changes, and scripts/seed.js populates initial data.
7. Advisor domain logic
- controllers/advisors.controller.js is the main domain controller for advisor records.
- utils/normalizeWhatsapp.js and utils/validateEmail.js show that advisor contact fields are normalized and validated at the application layer before persistence.
- This suggests the app treats contact data as important domain input, not just raw form submission.
8. File upload path
- middlewares/upload.js indicates the admin workflow supports file uploads, most likely advisor images or avatars.
- Upload handling is separated as middleware, so the controller can assume files are already parsed and stored.
9. Frontend asset pipeline
- The repo uses Tailwind CSS with tailwind.config.js, postcss.config.js, public/tailwind-input.css, and generated output in public/tailwind.css.
- Browser logic is split by page role: public/js/public.js, public/js/admin.js, and public/js/login.js.
- This is a server-rendered/static hybrid rather than a full SPA.
10. Persistence and schema concerns
- 002_whatsapp_unique.sql implies the advisor phone/WhatsApp field must be unique at the database level.
- That means there is both application-side normalization and database-side enforcement for integrity.
11. Deployment and automation
- .github/workflows/deploy-asesores.yml provides CI/CD automation for deployment.
- The repo also includes .env.example, so configuration is environment-driven and not hardcoded.
12. Likely request/data flow
- Public user visits public/index.html or a public route → browser JS calls public endpoints → controller reads advisor data from the DB → response is rendered or returned to the page.
- Admin user visits views/login.html → auth controller validates credentials with limiter protection → admin session/authorization is established → protected admin routes allow CRUD and uploads → controller writes to DB and possibly filesystem/object storage via upload middleware.
13. Key architectural boundaries to show in a diagram
- Browser/UI boundary: static HTML/CSS/JS under public/ and views/.
- API/controller boundary: route modules dispatching to controllers.
- Security boundary: auth limiter + admin authorization middleware around admin endpoints.
- Persistence boundary: controller/database access through db.js, controlled by migrations.
- Build/deploy boundary: Tailwind/PostCSS build and GitHub Actions deployment pipeline.
14. Repo purpose in one sentence
- This is a small Node/Express-style CRUD application for managing advisor listings, with public display, protected admin editing, login throttling, validation, uploads, and SQL-based persistence.
Main entry points: app.js app.js · admin.routes.js Admin routes · advisors.controller.js Advisors controller · auth.routes.js Auth routes
Components 27
Runtime
Express app startup and request routing
Public site
Unauthenticated advisor browsing surface
- Public routes · Routes for public advisor browsing
routes/public.routes.js - Advisors controller · Reads and manages advisor records
controllers/advisors.controller.js - Public page · Public-facing HTML shell
public/index.html - Public JS · Client logic for public advisor pages
public/js/public.js - Styles · Shared visual styling for the public site
public/styles.css
Admin area
Authenticated management surface
- Auth routes · Login and logout endpoints
routes/auth.routes.js - Auth controller · Validates credentials and establishes admin access
controllers/auth.controller.js - Login page · Admin login screen
views/login.html - Login JS · Client logic for login interactions
public/js/login.js - Admin routes · Protected advisor management endpoints
routes/admin.routes.js - Admin page · Authenticated management interface
views/admin.html - Admin JS · Client logic for admin CRUD actions
public/js/admin.js - Login limiter · Rate limits login attempts
middlewares/loginLimiter.js - Admin guard · Protects admin endpoints after authentication
middlewares/requireAdmin.js - Upload middleware · Parses and stores uploaded files
middlewares/upload.js
Data layer
Database access, schema, and migrations
- db.js · Shared database connection and query access
db.js - Migrate · Applies SQL schema changes
scripts/migrate.js - Seed · Loads initial database data
scripts/seed.js - Init schema · Initial relational schema
migrations/001_init.sql - WhatsApp unique · Adds uniqueness enforcement for WhatsApp/contact field
migrations/002_whatsapp_unique.sql
Build & deploy
Frontend asset build and deployment automation
- Tailwind config · Tailwind CSS build configuration
tailwind.config.js - PostCSS config · PostCSS pipeline configuration
postcss.config.js - Tailwind input · Source stylesheet consumed by the build
public/tailwind-input.css - Tailwind output · Generated CSS bundle served by the app
public/tailwind.css - Deploy workflow · GitHub Actions deployment automation
.github/workflows/deploy-asesores.yml
Connections 24
- server.js → app.js: starts · Server boots the Express app
- app.js → Public routes: mounts · Public routes are attached to the app
- app.js → Auth routes: mounts · Auth routes are attached to the app
- app.js → Admin routes: mounts · Admin routes are attached to the app
- Public routes → Advisors controller: dispatches · Public endpoints delegate to advisor logic
- Advisors controller → db.js: queries · Advisor data is read from and written to the database
- Auth routes → Login limiter: guards · Login path is rate-limited
- Auth routes → Auth controller: dispatches · Auth routes invoke authentication logic
- Auth controller → db.js: queries · Authentication reads user/admin data
- Admin routes → Admin guard: guards · Protected admin routes require authorization
- Admin routes → Upload middleware: uses · Admin workflow accepts file uploads
- Admin routes → Advisors controller: dispatches · Admin CRUD reuses advisor domain logic
- Advisors controller → Upload middleware: depends on · Uploaded assets are part of advisor management flow
- Public page → Public JS: loads · Public page loads browser logic
- Public page → Styles: styles · Public page uses shared styles
- Login page → Login JS: loads · Login page loads client-side behavior
- Admin page → Admin JS: loads · Admin page loads client-side behavior
- Migrate → Init schema: applies · Migration runner applies schema files
- Migrate → WhatsApp unique: applies · Migration runner applies schema files
- Seed → db.js: writes · Seeding uses the shared database layer
- Tailwind config → PostCSS config: pairs with · Tailwind and PostCSS define the CSS build pipeline
- Tailwind input → Tailwind output: builds into · Source CSS is compiled to the generated bundle
- Deploy workflow → server.js: deploys · CI/CD ships the application runtime
- Deploy workflow → Tailwind output: includes · Deployment includes built assets