# ashutosh-live/charaka-be2 architecture

> Architecture diagram of the GitHub repository ashutosh-live/charaka-be2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ashutosh-live/charaka-be2
- Repository: https://github.com/ashutosh-live/charaka-be2

## Overview

##### 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)

## Diagram (Mermaid)

```mermaid
flowchart TB
    Client["Client"]:::external

    subgraph "API Server"
        Server["src/server.ts"]:::internal
        App["src/app.ts"]:::internal
        JWT["JWT Middleware"]:::internal
        Logger["Logger Service"]:::internal
        Routes["Routes"]:::internal
        Controllers["Controllers"]:::internal
        Validation["Validation Layer"]:::internal
        Helpers["Helpers/Services"]:::internal
        Models["Data Models"]:::internal
        Swagger["Swagger Docs"]:::internal
    end

    subgraph "External Services"
        DB["Relational Database"]:::datastore
        Redis["Redis Cache"]:::datastore
        S3["AWS S3"]:::externalService
        SMTP["SMTP/Mailer"]:::externalService
    end

    Client -->|"HTTP Request"| Server
    Client -->|"HTTP Request"| App
    Server --> JWT
    App --> JWT
    JWT --> Routes
    Routes --> Controllers
    Controllers --> Validation
    Controllers --> Helpers
    Controllers --> Logger
    Helpers --> Logger
    Helpers --> Models
    Swagger -.-> Routes

    Models -->|"SQL Query"| DB
    Helpers -->|"Cache R/W"| Redis
    Helpers -->|"File Upload"| S3
    Helpers -->|"Send Email"| SMTP

    classDef internal fill:#cce5ff,stroke:#004085,color:#004085
    classDef datastore fill:#d4edda,stroke:#155724,color:#155724
    classDef externalService fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#f8d7da,stroke:#721c24,color:#721c24

    click Server "https://github.com/ashutosh-live/charaka-be2/blob/TLGC-19/src/server.ts"
    click App "https://github.com/ashutosh-live/charaka-be2/blob/TLGC-19/src/app.ts"
    click JWT "https://github.com/ashutosh-live/charaka-be2/blob/TLGC-19/src/middlewares/jwt.ts"
    click Logger "https://github.com/ashutosh-live/charaka-be2/blob/TLGC-19/src/lib/logger.ts"
    click Routes "https://github.com/ashutosh-live/charaka-be2/tree/TLGC-19/src/routes/"
    click Controllers "https://github.com/ashutosh-live/charaka-be2/tree/TLGC-19/src/controllers/"
    click Validation "https://github.com/ashutosh-live/charaka-be2/tree/TLGC-19/src/controllers/validation/"
    click Helpers "https://github.com/ashutosh-live/charaka-be2/tree/TLGC-19/src/helpers/"
    click Models "https://github.com/ashutosh-live/charaka-be2/tree/TLGC-19/src/models/"
    click Swagger "https://github.com/ashutosh-live/charaka-be2/blob/TLGC-19/src/docTemplate/swagger.ts"
    click DB "https://github.com/ashutosh-live/charaka-be2/tree/TLGC-19/db/"
    click Redis "https://github.com/ashutosh-live/charaka-be2/blob/TLGC-19/src/helpers/redis.ts"
    click S3 "https://github.com/ashutosh-live/charaka-be2/blob/TLGC-19/src/helpers/S3.ts"
    click SMTP "https://github.com/ashutosh-live/charaka-be2/blob/TLGC-19/src/helpers/mailer.ts"
```
