How 14fabyzz/inventorymaster works
Project Type and Purpose
• This is a Node.js/TypeScript REST‑API backend for an online tech store.
• It exposes endpoints for authentication, user management, product management, and profile operations.
• Uses Express (via app.ts), environment‑configurable database connectivity, JWT for auth, and a layered code structure (routes → controllers → services → repositories).
File Structure
• Top‑level entry: app.ts initializes Express, loads middleware, mounts routes.
• config/config‑db.ts handles DB connection parameters (driven by .env).
• routes/*.ts define HTTP endpoints grouped by resource (auth, users, products, profile, register).
• controllers/*Controller.ts contain request handlers and validation.
• services/*Services.ts implement business logic.
• repositories/*Repository.ts perform CRUD against the database.
• Helpers/ generateHash and generateToken encapsulate password hashing and JWT creation.
• middleware/VerifyToken.ts secures protected routes.
README for Additional Insights
• Requires Node.js v20+, environment variables for DB credentials.
• Build step (tsc -w) + runtime command (node ./dist/app).
• No front‑end delivered here—this service will be consumed by a separate UI or API client.
Main Components & Their Interactions
a. API Client (e.g., Web UI or Postman)
↘ sends HTTP requests to →
b. Express Server (app.ts)
– Global middleware (VerifyToken, JSON parser)
– Mounted Routers (routes/auth, users, products, register, profile)
↘ route match →
c. Controller Layer
– Accepts req/res, calls into →
d. Service Layer
– Implements business rules, calls →
e. Repository (Data Access)
– Executes SQL/ORM calls against the Database
f. Database (MySQL/Postgres, as configured in config‑db.ts)
g. Helpers & Shared Utilities
– generateHash (password security)
– generateToken (JWT signing)
h. External Dependencies
– Environment (ENV) for credentials
– npm packages (Express, JWT, bcrypt, ORM)
Architectural Patterns & Design Principles
• Layered (Onion) Architecture: keeps controllers thin, services focused, repositories isolated.
• Dependency Injection (manual wiring in app.ts) to decouple modules.
• Middleware pattern for cross‑cutting concerns (authentication).
• Clear separation of concerns: routing vs. control vs. business vs. data.
Final Checklist
[ ] Clear component labels matching folder names
[ ] Call out environment (.env) and external libraries (JWT, bcrypt)
[ ] Note any asynchronous flows or error handlers if relevant