How iot-lab-kiit/kritique-backend works
Project Type & Purpose
• This is a backend service (written in TypeScript) that appears central to a larger application dealing with faculty (or teacher) reviews. The naming in directories such as “faculty”, “review”, and “user” suggests its role in managing data and logic for handling user reviews for faculty.
• The project acts as an API server and HTML view renderer using Express (as inferred from the presence of type definitions in src/@types/express.ts and EJS view templates). It is also containerized (Dockerfile, compose.yaml, vercel.json) and uses external modules like Firebase Admin.
Analyzing the File Structure
• Entry Point & Core Logic:
• index.ts is likely the main starting point.
• Types & Constants:
• The src/@types folder contains custom type definitions for Express as well as for domain concepts like faculty, review, and user.
• The src/constants directory holds status codes and profanity dictionary JSON files (for English and Hindi), indicating some moderation or filtering features.
• Controllers & Routes:
• The src/controllers directory manages business logic for faculty, review, and user.
• Corresponding route files (under src/routes) are separated by file extension, with JSON and HTML formats indicating that the backend serves both web pages and API responses.
• Views:
• EJS templates in src/views provide the HTML rendering for various UI components related to faculty and reviews.
• Middleware & Helpers:
• The presence of files under src/middleware (like auth.ts) implies pre-request processing such as authentication.
• The helper functions in src/helper (for anonymizing names, validating teacher data, simulating profanity) add utility functions central to the business logic.
• External Libraries:
• Under src/lib, integration with Firebase Admin and custom library functions (such as profanity filtering and random name generation) are implemented.
Main Components
a. Client / Request Entry
• Incoming HTTP requests (via REST endpoints) that hit the backend.
b. API & Routing Layer:
• Node/Express server entry point (index.ts) that routes requests based on URL paths.
c. Middleware:
• Authentication middleware and possibly other pre-processing steps that manage sessions/tokens.
d. Controllers:
• Faculty, Review, and User controllers handling request processing.
e. Service & Helper Layer:
• Helper modules (like anonName, dataFill, profanityMock) and libraries (firebase-admin integration, profanity, random-names) that encapsulate core logic.
f. Data Models:
• Under the src/model folder, structure for faculty, review, and user data is defined.
g. Views:
• EJS templates used for generating HTML responses.
h. External Services & Configurations:
• Firebase service (via src/lib/firebase-admin.ts) and environment configuration (Docker, Vercel, .env variables).
Relationships and Flow
• Controllers then use helpers, libraries, and models to process data, communicate with external services (Firebase) and then generate a response either as JSON or rendered HTML (using views).
• Dependency flow from controllers to helper functions and libraries is essential.
• Also, include the configuration and deployment aspects (Docker, compose.yaml, vercel.json) to show how the backend is packaged and deployed.
Architectural Patterns & Design Principles
• Separation of Concerns: Clear separation between routing, controllers, business logic, views, and helper utilities.
• Modular Design: Each feature (faculty, review, user) has its own controller, model, and type definitions.
• Middleware Pattern: Authentication and possibly other pre-request validations are handled through middleware.
• API/Server-Side Rendering: Dual support for JSON responses and HTML views.
• Containerization: Docker and related configuration files indicate containerized deployment.