diff --git a/backend/jest.setup.js b/backend/jest.setup.js index 471ccf2..3abc1f8 100644 --- a/backend/jest.setup.js +++ b/backend/jest.setup.js @@ -12,8 +12,8 @@ global.console = { debug: jest.fn(), // Mock console.debug } -/* Mock Redis client in all unit tests */ -jest.mock('./src/redis/redisClient', () => ({ +/* Mock Redis client in all unit tests. Needed since redis is used by express-rate-limit in top level code which is imported by App.ts when the routes are loaded */ +jest.mock('./src/database/redis/redisClient', () => ({ getClient: jest.fn().mockImplementation(() => ({ sendCommand: jest.fn().mockResolvedValue('OK'), })), diff --git a/backend/src/app.ts b/backend/src/app.ts index 3a5c71a..4598b96 100644 --- a/backend/src/app.ts +++ b/backend/src/app.ts @@ -1,9 +1,9 @@ /* Application setup */ import express, { Express } from 'express'; import mongoose from 'mongoose'; -import healthCheckRouter from './healthCheck/routes/healthCheckRoutes'; -import userRouter from './user/routes/userRoutes'; -import { ApiUrlsV1 } from './constants'; +import healthCheckRouter from './features/healthCheck/routes/healthCheckRoutes'; +import userRouter from './features/user/routes/userRoutes'; +import { ApiUrlsV1 } from './features/common/constants'; import logger from './logging/logger'; import Config from 'simple-app-config'; import helmet from 'helmet'; diff --git a/backend/src/foodTracker/models/foodTracker.ts b/backend/src/database/mongodb/mongodbClient.ts similarity index 100% rename from backend/src/foodTracker/models/foodTracker.ts rename to backend/src/database/mongodb/mongodbClient.ts diff --git a/backend/src/redis/redisClient.ts b/backend/src/database/redis/redisClient.ts similarity index 97% rename from backend/src/redis/redisClient.ts rename to backend/src/database/redis/redisClient.ts index 637cea4..60273c3 100644 --- a/backend/src/redis/redisClient.ts +++ b/backend/src/database/redis/redisClient.ts @@ -1,6 +1,6 @@ import Config from 'simple-app-config'; import { createClient, RedisClientType } from 'redis'; -import logger from '../logging/logger'; +import logger from '../../logging/logger'; /** * Client class used to interact with redis diff --git a/backend/src/baseDocument.ts b/backend/src/features/common/baseDocument.ts similarity index 100% rename from backend/src/baseDocument.ts rename to backend/src/features/common/baseDocument.ts diff --git a/backend/src/constants.ts b/backend/src/features/common/constants.ts similarity index 100% rename from backend/src/constants.ts rename to backend/src/features/common/constants.ts diff --git a/backend/src/foodTracker/models/customFood.ts b/backend/src/features/foodTracker/models/customFood.ts similarity index 100% rename from backend/src/foodTracker/models/customFood.ts rename to backend/src/features/foodTracker/models/customFood.ts diff --git a/backend/src/foodTracker/models/food.ts b/backend/src/features/foodTracker/models/food.ts similarity index 86% rename from backend/src/foodTracker/models/food.ts rename to backend/src/features/foodTracker/models/food.ts index a7c0ffe..8e2a7fa 100644 --- a/backend/src/foodTracker/models/food.ts +++ b/backend/src/features/foodTracker/models/food.ts @@ -1,5 +1,5 @@ /* Interface that all official and custom food documents extend */ -import { BaseDocument } from '../../baseDocument'; +import { BaseDocument } from '../../common/baseDocument'; /** * Interface for a generic food document that is trackable diff --git a/backend/src/foodTracker/models/foodTrackerItem.ts b/backend/src/features/foodTracker/models/foodTracker.ts similarity index 100% rename from backend/src/foodTracker/models/foodTrackerItem.ts rename to backend/src/features/foodTracker/models/foodTracker.ts diff --git a/backend/src/foodTracker/models/recentFood.ts b/backend/src/features/foodTracker/models/foodTrackerItem.ts similarity index 100% rename from backend/src/foodTracker/models/recentFood.ts rename to backend/src/features/foodTracker/models/foodTrackerItem.ts diff --git a/backend/src/foodTracker/models/officialFood.ts b/backend/src/features/foodTracker/models/officialFood.ts similarity index 100% rename from backend/src/foodTracker/models/officialFood.ts rename to backend/src/features/foodTracker/models/officialFood.ts diff --git a/backend/src/features/foodTracker/models/recentFood.ts b/backend/src/features/foodTracker/models/recentFood.ts new file mode 100644 index 0000000..e69de29 diff --git a/backend/src/healthCheck/constants.ts b/backend/src/features/healthCheck/constants.ts similarity index 100% rename from backend/src/healthCheck/constants.ts rename to backend/src/features/healthCheck/constants.ts diff --git a/backend/src/healthCheck/controllers/healthCheckController.ts b/backend/src/features/healthCheck/controllers/healthCheckController.ts similarity index 96% rename from backend/src/healthCheck/controllers/healthCheckController.ts rename to backend/src/features/healthCheck/controllers/healthCheckController.ts index 1791c3b..810f0d8 100644 --- a/backend/src/healthCheck/controllers/healthCheckController.ts +++ b/backend/src/features/healthCheck/controllers/healthCheckController.ts @@ -1,8 +1,8 @@ /* Business logic for application health checks */ import { Request, Response } from 'express'; import mongoose, { STATES } from 'mongoose'; -import logger from '../../logging/logger'; import { HealthCheckResponses } from '../constants'; +import logger from '../../../logging/logger'; /** * Business logic for application health checks diff --git a/backend/src/healthCheck/routes/healthCheckRoutes.ts b/backend/src/features/healthCheck/routes/healthCheckRoutes.ts similarity index 91% rename from backend/src/healthCheck/routes/healthCheckRoutes.ts rename to backend/src/features/healthCheck/routes/healthCheckRoutes.ts index 79cfddb..9bbeb58 100644 --- a/backend/src/healthCheck/routes/healthCheckRoutes.ts +++ b/backend/src/features/healthCheck/routes/healthCheckRoutes.ts @@ -1,13 +1,13 @@ /* Routes for application health checks */ import express from 'express'; import rateLimit, { MemoryStore } from 'express-rate-limit'; -import logger from '../../logging/logger'; import Config from 'simple-app-config'; import HealthCheckController from '../controllers/healthCheckController'; -import { API_URLS_V1_PREFIX, Environments, GenericResponses } from '../../constants'; +import { API_URLS_V1_PREFIX, Environments, GenericResponses } from '../../common/constants'; import RedisStore from 'rate-limit-redis'; -import RedisClient from '../../redis/redisClient'; import _ from 'lodash'; +import logger from '../../../logging/logger'; +import RedisClient from '../../../database/redis/redisClient'; const healthCheckRouter = express.Router(); diff --git a/backend/src/user/constants.ts b/backend/src/features/user/constants.ts similarity index 100% rename from backend/src/user/constants.ts rename to backend/src/features/user/constants.ts diff --git a/backend/src/user/controllers/userController.ts b/backend/src/features/user/controllers/userController.ts similarity index 94% rename from backend/src/user/controllers/userController.ts rename to backend/src/features/user/controllers/userController.ts index 05ade5e..8d8cf84 100644 --- a/backend/src/user/controllers/userController.ts +++ b/backend/src/features/user/controllers/userController.ts @@ -2,8 +2,8 @@ import { Request, Response } from 'express'; import { User } from '../models/user'; import { UserResponses } from '../constants'; -import { GenericResponses } from '../../constants'; -import logger from '../../logging/logger'; +import { GenericResponses } from '../../common/constants'; +import logger from '../../../logging/logger'; /** * Business logic for user related APIs diff --git a/backend/src/user/models/user.ts b/backend/src/features/user/models/user.ts similarity index 95% rename from backend/src/user/models/user.ts rename to backend/src/features/user/models/user.ts index 50eefda..fbc8435 100644 --- a/backend/src/user/models/user.ts +++ b/backend/src/features/user/models/user.ts @@ -1,6 +1,6 @@ /* Schema definition for a user */ import mongoose, { Schema } from 'mongoose'; -import { BaseDocument } from '../../baseDocument'; +import { BaseDocument } from '../../common/baseDocument'; /** * Interface for user document diff --git a/backend/src/user/routes/userRoutes.ts b/backend/src/features/user/routes/userRoutes.ts similarity index 90% rename from backend/src/user/routes/userRoutes.ts rename to backend/src/features/user/routes/userRoutes.ts index d69d2d3..2c9a03d 100644 --- a/backend/src/user/routes/userRoutes.ts +++ b/backend/src/features/user/routes/userRoutes.ts @@ -1,13 +1,13 @@ /* Routes for user authentication */ import express from 'express'; import rateLimit, { MemoryStore } from 'express-rate-limit'; -import logger from '../../logging/logger'; +import logger from '../../../logging/logger'; import Config from 'simple-app-config'; -import { API_URLS_V1_PREFIX, Environments, GenericResponses } from '../../constants'; +import { API_URLS_V1_PREFIX, Environments, GenericResponses } from '../../common/constants'; import UserController from '../controllers/userController'; import RedisStore from 'rate-limit-redis'; -import RedisClient from '../../redis/redisClient'; import _ from 'lodash'; +import RedisClient from '../../../database/redis/redisClient'; export const userRouter = express.Router(); diff --git a/backend/src/index.ts b/backend/src/index.ts index 8b3656e..e8c4a09 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -2,7 +2,7 @@ * Import DB clients and logger before all else */ import logger from './logging/logger'; -import RedisClient from './redis/redisClient'; +import RedisClient from './database/redis/redisClient'; /** * IIFE to ensure database connections are established synchronously before anything else uses the DBs diff --git a/backend/src/logging/logger.ts b/backend/src/logging/logger.ts index 7ef76d0..e88e563 100644 --- a/backend/src/logging/logger.ts +++ b/backend/src/logging/logger.ts @@ -1,7 +1,7 @@ /* Setup for logger */ import DailyRotateFile from 'winston-daily-rotate-file'; import winston from 'winston'; -import { Environments } from '../constants'; +import { Environments } from '../features/common/constants'; /* Set up file transport and rotation */ const fileTransport = new DailyRotateFile({ diff --git a/backend/tests/app.test.ts b/backend/tests/app.test.ts index 903812b..1e9fd96 100644 --- a/backend/tests/app.test.ts +++ b/backend/tests/app.test.ts @@ -1,7 +1,7 @@ /* Unit tests for the backend application server class */ import mongoose from 'mongoose'; import App from '../src/app'; -import { Environments } from '../src/constants'; +import { Environments } from '../src/features/common/constants'; import logger from '../src/logging/logger'; import Config, { EnvParser } from 'simple-app-config'; import http from 'http'; diff --git a/backend/tests/healthCheck/controllers/healthCheckController.test.ts b/backend/tests/healthCheck/controllers/healthCheckController.test.ts index e52ae88..b71790a 100644 --- a/backend/tests/healthCheck/controllers/healthCheckController.test.ts +++ b/backend/tests/healthCheck/controllers/healthCheckController.test.ts @@ -1,7 +1,7 @@ import { Request, Response } from 'express'; import { MockRequest, MockResponse, createRequest, createResponse } from 'node-mocks-http'; -import HealthCheckController from '../../../src/healthCheck/controllers/healthCheckController'; -import { HealthCheckResponses } from '../../../src/healthCheck/constants'; +import HealthCheckController from '../../../src/features/healthCheck/controllers/healthCheckController'; +import { HealthCheckResponses } from '../../../src/features/healthCheck/constants'; import mongoose from 'mongoose'; describe('Health Check Controller Tests', () => { diff --git a/backend/tests/healthCheck/routes/healthCheckRoutes.test.ts b/backend/tests/healthCheck/routes/healthCheckRoutes.test.ts index 9cbbd58..23fba6b 100644 --- a/backend/tests/healthCheck/routes/healthCheckRoutes.test.ts +++ b/backend/tests/healthCheck/routes/healthCheckRoutes.test.ts @@ -1,12 +1,12 @@ /* Unit tests for the health check routes */ import request from 'supertest'; -import { ApiUrlsV1, GenericResponses } from '../../../src/constants'; +import { ApiUrlsV1, GenericResponses } from '../../../src/features/common/constants'; import App from '../../../src/app'; import Config from 'simple-app-config'; -import HealthCheckController from '../../../src/healthCheck/controllers/healthCheckController'; +import HealthCheckController from '../../../src/features/healthCheck/controllers/healthCheckController'; /* Mock the controller functions */ -jest.mock('../../../src/healthCheck/controllers/healthCheckController', () => ({ +jest.mock('../../../src/features/healthCheck/controllers/healthCheckController', () => ({ checkHealth: jest.fn().mockImplementation((req, res) => { res.sendStatus(200); })