How markkhramko/nodejs-express-jwt works
Main Components
• Server Entry Point: Indicate app/app.js as the central bootstrapping file.
• Controllers: Illustrate two sets – API controllers (in app/controllers/api) responsible for REST endpoints and Web controllers (in app/controllers/web) for HTTP request handling and view rendering.
• Routes: Show how the routes (located in app/routes, with separate directories for API and web) are mapped to the respective controllers.
• Models: Represent the database models (in app/models), which are defined with Sequelize. Connect these to the corresponding services and the database.
• db.service.js for database interactions,
• bcrypt.service.js for password hashing,
• jwt.service.js for token management.
• Facades & Factories: Indicate the error handling (under app/factories/errors) and response factories (app/factories/responses) which help standardize responses.
• Policies: Include the policies (in app/policies) that serve as middleware enforcing authentication and authorization rules.
• Configurations: Represent the configs directory (with separate files for API, database, environments, JWT, and server settings) alongside .env for environment values.
• Migrations and Seeders: Highlight the migrator folder for database schema migrations and seed data processes.
• Public & Views: Show the public directory for static assets and app/views for Pug templates used in web responses.
• Utilities: Optionally, mark additional helper modules such as those under app/utils.
Relationships and Interactions
• From controllers, indicate interconnections with models (database queries via Sequelize) and services (e.g., calling JWT or bcrypt functions).
• Link policies as middleware between the request routing and controller actions.
• That the configurations are loaded first and influence all components (server, JWT, DB, etc.).
• Database (MySQL/PostgreSQL) being accessed by models through the db.service.
• Optionally, indicate the role played by factories and facades in error and response management.
Architectural Patterns
• Separation of concerns: distinct modules for request routing, business logic (controllers), data models, and service utilities.
• Use of the factory pattern (seen in controllers and response/error factories) to create consistent layers of abstraction.
• Middleware (via policies) as a decoupled layer to handle cross-cutting concerns like authentication.
• Layered architecture: configurations at the base, followed by controllers → services → models → database.
Incorporate Relevant Technologies
• Node.js and Express for the server and routing.
• Babel for ES6+ code compilation.
• Sequelize as the ORM, supporting MySQL (or PostgreSQL).
• JWT authentication mechanism.
• Pug for web (template/view) rendering.
• Tools like nodemon for development and environmental configuration through .env and config files.