How ashutosh-live/charaka-be2 works
Project Type and Purpose
• This is a TypeScript-based, Node.js/Express monolithic REST API server.
• It exposes endpoints for managing users, authentication, chat, products/additives, plants, suppliers, support tickets, and project settings.
• It persists data in a relational database (SQL scripts under db/), uses Redis for caching or session storage, and integrates with AWS S3 for file storage and an SMTP/mail service.
Main Components
a. Clients – e.g., web or mobile front ends calling the HTTP API.
b. API Server – the Node.js/Express application (src/server.ts & src/app.ts)
• Middlewares (jwt auth, logging)
• Routes (src/routes/*.ts) → Controllers (src/controllers/*.ts) → Validation layer (src/controllers/validation)
• Business logic & helpers (src/helpers/*.ts) for common tasks: S3, mailer, Redis, cron scheduling
• Data access (src/models/*.ts + models/index.js) via an ORM or query layer
• Swagger docs (src/docTemplate/swagger.ts)
• Cron jobs (src/controllers/cronController.ts + src/helpers/cron.ts)
c. Relational Database – schema managed by SQL scripts in db/
d. Redis – caching, session or token store
e. AWS S3 – storage for uploads
f. SMTP/Mailer – email notifications
g. Logging service – custom logger (src/lib/logger.ts) writing to files or external system
Component Interactions
1) Client → HTTP(S) request → Express Server
2) JWT middleware authenticates → route dispatch
3) Controller validates input → calls helper or service functions
4) Helpers call model methods → ORM issues SQL queries → Database
5) Helpers may also read/write Redis or upload/read from S3
6) Controller returns JSON response → client
7) Cron module triggers scheduled jobs → same controllers/helpers path
8) Logging captured at each step by logger module
Architectural Patterns & Principles
• Layered architecture: Presentation (routes/controllers) → Business (helpers/services) → Data (models/DB).
• Separation of concerns: Validation separated, helpers abstract external integrations (S3, Redis, mail).
• Single monolith service; if scaling, could split into microservices by domain (e.g., auth, chat).
• Cron-based scheduling for periodic tasks.
• External dependencies abstracted behind interfaces (src/interface/*.ts).
Technologies & Frameworks
• Node.js + Express + TypeScript
• PostgreSQL/MySQL (SQL scripts) via Sequelize or similar
• Redis (caching/session)
• AWS S3 SDK (src/helpers/S3.ts)
• JSON Web Tokens (src/middlewares/jwt.ts)
• Swagger/OpenAPI (src/docTemplate/swagger.ts)
• Mailer (nodemailer or similar in src/helpers/mailer.ts)
• Custom logger (src/lib/logger.ts)
• Cron scheduling (src/helpers/cron.ts)
• Testing with Jest/Mocha (src/test/*.js)