How yogeshkathayat/bike-stolen-app-nodejs-typescript works
Project Type & Purpose
• Type: A Node.js-based RESTful backend microservice (no bundled frontend).
• Purpose: Expose HTTP endpoints for owners to report stolen bikes and for police officers to search, assign, and resolve cases. Uses Express, Sequelize (PostgreSQL), hosted on Heroku.
High-Level Component Breakdown
a. Clients & External Users
– Bike owners (reporting cases via HTTP requests or Postman)
– Police officers (search/report/update cases via HTTP)
– API docs consumer (browser hitting Swagger/UI).
b. API Gateway Layer
– Express app (server.ts + app.ts)
– Middlewares (error handling, validation)
c. Application Layer (MVC + Service)
– Routes (src/api/routes)
– Controllers (src/api/controllers)
– Validation middleware (src/api/validations)
– Business Services (src/api/services)
d. Data Access Layer
– Models (src/api/models) with Sequelize ORM
– Database connection/config (src/config/sequelize.ts)
e. Supporting Modules
– Configuration (env vars, constants, logger) in src/config
– Utility helpers (src/util/response.ts)
f. Persistence
– PostgreSQL (Heroku-hosted)
g. Documentation & Tests
– Static API docs (docs/ folder; served at /api/v1/docs/)
– Unit tests (Jest + Supertest under test/)
Relationships & Data Flow
1. Client → HTTP request → Express Router
2. Router → (Validation Middleware) → Controller
3. Controller → Service Layer (business rules, automatic assignment logic)
4. Service → Model → PostgreSQL
5. DB → Service → Controller → HTTP response → Client
6. Errors bubble up to centralized error middleware → formatted error response
7. API docs (static files) served alongside Express endpoints
Architectural Patterns & Design Principles
• Layered architecture (Router → Controller → Service → Data Access)
• Separation of concerns: validation, logging, error handling extracted to middlewares/utilities
• ORM abstraction (Sequelize) encapsulates SQL queries behind model definitions
• Auto-assignment logic embedded in service layer to ensure one-case-per-officer constraint
Final Checklist
[ ] All major components (Clients, Express App, Middlewares, Controllers, Services, Models, DB)
[ ] Annotations for key libraries/frameworks (Express, Sequelize, Jest)
[ ] Deployment target (Heroku) and environment (Node.js, Postgres)