How gid3onjura/shorai-do-api works
• API Server: The central entry point is app.js, which initializes the server and ties everything together.
• Database Layer: Represented by the “db” folder. Within this folder, you have:
• Controllers (db/controller): Handling business logic for specific domain areas (e.g., dojo, event, exam, users, refreshtoken).
• Models (db/models): Defining the data structures and schemas for MySQL interaction.
• Database initialization (db/index.js) and SQL scripts (db/data/shorai-do.sql) for setting up the MySQL database.
• Routes: The “routes” folder contains Express route definitions (auth, events, exam, test, users, utils), mapping HTTP endpoints to controllers.
• Middleware: In the “middleware” folder you find tokens and API key handlers that govern authentication and authorization.
• Validation: The “validation” folder provides request schema and validation logic ensuring correct data formats coming into the API.
• Security & Certificates: The “security” folder holds SSL certificate (cert.pem, key.pem) and configuration files to secure connections.
• Documentation: The “doc” directory and README point to API documentation, including a Postman collection and a Doku YAML file.
• Libraries & Helpers: The “lib” directory likely contains utility functions or modules that support other components.
• Mock Data: The “mock” folder provides sample JSON data useful for testing and development.
Relationships and Interactions
• Clients (or Postman during testing) send HTTP requests to various endpoints defined in the Routes.
• Each route forwards the request to its corresponding controller (located in db/controller) after passing through Middleware (authentication, API-key resolution, and validation).
• Controllers communicate with the Model layer for database interactions. This is where the business logic is applied.
• The Models interface with the MySQL database (established through db/index.js and configured using credentials provided in an .env file).
• External security layers indicating that HTTPS might be used, employing certificates stored in the “security” folder.
• Optionally, indicate a documentation or utility reference showing how the API is documented (via the “doc” folder and Postman-Collection).
Architectural Patterns
• The structure suggests an MVC-like separation:
• Models: Define database entities.
• Controllers: Handle request logic and data processing before interacting with models.
• Routes: Expose endpoints.
• Incorporate Middleware as cross-cutting concerns for authentication and validation.
• The layered approach (Routes → Controllers → Models → Database) should be clearly indicated.
Specific Technologies and Tools
• Node.js/Express: The main framework driving the API,
• MySQL: The relational database system (setup via the provided SQL script and config via .env),
• Middleware for Token Authentication and API Key resolution,
• SSL/TLS: For security, using certificates from the “security” folder.
• Documentation Tools: Doku YAML and Postman collection indicate emphasis on well-documented API endpoints.