SensitiveMinds Backend is a dedicated API server created for the needs of a research project conducted by psychology students. Its purpose is to provide a secure and efficient backend infrastructure for the SensitiveMinds mobile application, enabling streamlined data collection about patients and conducted visits.
The backend was designed as a secure API for internal use among project participants. It provides comprehensive authentication, patient management, visit tracking, and data export capabilities while ensuring complete security and confidentiality of collected data.
- Modern Architecture: Built with NestJS 11.0.1 and TypeScript
- Secure Authentication: JWT-based authentication with role-based access control
- Database Management: PostgreSQL with TypeORM for efficient data handling
- API Documentation: Comprehensive Swagger/OpenAPI documentation
- Patient Management: Complete patient tracking and management system
- Visit Management: Therapeutic visit management with exercise tracking
- Role-Based Access: Manager and Researcher role system
- Data Export: Secure data export functionality
- Center Grouping: Organization of patients by therapeutic centers
- Framework: NestJS 11.0.1
- Language: TypeScript 5.7.3
- Database: PostgreSQL 8.13.3 with TypeORM 0.3.21
- Authentication: JWT 9.0.2, Passport, bcrypt 5.1.1
- API Documentation: Swagger/OpenAPI 11.0.6
- Validation: class-validator 0.14.1
- Testing: Jest 29.7.0, Supertest 7.0.0
- Linting: ESLint 9.18.0 with TypeScript support
- Formatting: Prettier 3.4.2
- Development: NestJS CLI 11.0.0
βββ src/ # Source code
β βββ auth/ # Authentication module
β β βββ auth.controller.ts # Auth endpoints
β β βββ auth.service.ts # Auth business logic
β β βββ auth.module.ts # Auth module configuration
β β βββ jwt-auth.guard.ts # JWT authentication guard
β β βββ dto/ # Auth data transfer objects
β βββ users/ # User management module
β β βββ users.controller.ts # User endpoints
β β βββ users.service.ts # User business logic
β β βββ users.entity.ts # User database entity
β β βββ users.module.ts # User module configuration
β β βββ roles.guard.ts # Role-based access guard
β βββ patients/ # Patient management module
β β βββ patients.controller.ts # Patient endpoints
β β βββ patients.service.ts # Patient business logic
β β βββ patients.entity.ts # Patient database entity
β β βββ center.entity.ts # Center database entity
β β βββ patients.module.ts # Patient module configuration
β β βββ dto/ # Patient data transfer objects
β βββ visits/ # Visit management module
β β βββ visit.controller.ts # Visit endpoints
β β βββ visit.service.ts # Visit business logic
β β βββ visits.entity.ts # Visit database entity
β β βββ visit.module.ts # Visit module configuration
β β βββ dto/ # Visit data transfer objects
β βββ center/ # Center management module
β β βββ center.controller.ts # Center endpoints
β β βββ center.service.ts # Center business logic
β β βββ center.module.ts # Center module configuration
β βββ export/ # Data export functionality
β βββ app.module.ts # Main application module
β βββ main.ts # Application entry point
β βββ app.controller.ts # Main application controller
β βββ app.service.ts # Main application service
βββ test/ # Test files
βββ dist/ # Compiled JavaScript output
βββ package.json # Dependencies and scripts
βββ tsconfig.json # TypeScript configuration
βββ nest-cli.json # NestJS CLI configuration
βββ .env # Environment variables (not in repo)
- Node.js >= 18
- PostgreSQL >= 12
- npm or yarn package manager
-
Clone the repository
git clone <repository-url> cd sensitive-minds-backend
-
Install dependencies
npm install
-
Set up environment variables
Create a
.envfile in the root directory with the following variables:# JWT Configuration JWT_SECRET=your-super-secret-jwt-key-here # Database Configuration PGHOST=localhost PGPORT=5432 PGUSER=your-database-user PGPASSWORD=your-database-password PGDATABASE=sensitive_minds # Application Configuration PORT=3000 EXPORT_ALL_PASSWORD=your-export-password
β οΈ IMPORTANT: Never commit the.envfile to the repository - it contains sensitive data! -
Set up the database
Create a PostgreSQL database and update the connection details in your
.envfile.
The application uses the following environment variables:
JWT_SECRET: Secret key for JWT token signingPGHOST: PostgreSQL host addressPGPORT: PostgreSQL port (default: 5432)PGUSER: PostgreSQL usernamePGPASSWORD: PostgreSQL passwordPGDATABASE: PostgreSQL database namePORT: Application port (default: 3000)EXPORT_ALL_PASSWORD: Password for data export functionality
The application uses TypeORM with PostgreSQL. The database connection is configured in src/app.module.ts:
TypeOrmModule.forRoot({
type: 'postgres',
host: process.env.PGHOST,
port: parseInt(process.env.PGPORT, 10) || 5432,
username: process.env.PGUSER,
password: process.env.PGPASSWORD,
database: process.env.PGDATABASE,
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true, // Use migrations in production
});npm run start- Start the application in production modenpm run start:dev- Start the application in development mode with hot reloadnpm run start:debug- Start the application in debug modenpm run build- Build the application for productionnpm run test- Run unit testsnpm run test:e2e- Run end-to-end testsnpm run test:cov- Run tests with coverage reportnpm run lint- Run ESLint for code qualitynpm run format- Format code with Prettier
The API provides the following main endpoints:
POST /auth/login- User loginPOST /auth/register- User registration (admin only)
GET /users- Get all users (admin only)GET /users/:id- Get user by IDPUT /users/:id- Update userDELETE /users/:id- Delete user
GET /patients- Get all patientsGET /patients/:id- Get patient by IDPOST /patients- Create new patientPUT /patients/:id- Update patientDELETE /patients/:id- Delete patient
GET /visits- Get all visitsGET /visits/:id- Get visit by IDPOST /visits- Create new visitPUT /visits/:id- Update visitDELETE /visits/:id- Delete visit
GET /centers- Get all centers
id: Unique identifierfullName: User's full nameusername: Unique usernamepassword: Hashed passwordrole: User role (MANAGER or RESEARCHER)patients: Associated patientsresearchers: Associated researchers (for managers)manager: Associated manager (for researchers)
id: Unique identifiername: Patient nameage: Patient agebedNumber: Bed numbergender: Patient gendercenter: Associated therapeutic centerroomNumber: Room numberuser: Associated researchervisits: Patient's visits
id: Unique identifierdate: Visit dateconsentGiven: Consent statusexercises: Exercise completion datapastMemory: Memory exercise completionarithmetic: Arithmetic exercise datareading: Reading exercise completionstroopTest: Stroop test data
notes: Visit notespatient: Associated patientcreatedBy: User who created the visit
- JWT Authentication: Secure token-based authentication
- Password Hashing: bcrypt for password security
- Role-Based Access Control: Manager and Researcher roles
- Input Validation: Comprehensive data validation
- SQL Injection Protection: TypeORM parameterized queries
- Environment Variable Protection: Sensitive data isolation
The API documentation is automatically generated using Swagger/OpenAPI and is available at:
http://localhost:3000/api
The documentation includes:
- All available endpoints
- Request/response schemas
- Authentication requirements
- Interactive testing interface
The project includes comprehensive testing setup:
# Run unit tests
npm run test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:cov
# Run end-to-end tests
npm run test:e2e-
Build the application
npm run build
-
Set up production environment variables
-
Configure database migrations (recommended for production)
-
Deploy using your preferred method:
- Docker containers
- Cloud platforms (AWS, Google Cloud, Azure)
- Traditional servers
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist ./dist
EXPOSE 3000
CMD ["node", "dist/main"]The project uses ESLint and Prettier for code quality and formatting:
# Check for linting errors
npm run lint
# Format code
npm run formatFor production environments, it's recommended to use TypeORM migrations instead of synchronize: true:
# Generate migration
npm run typeorm migration:generate -- -n MigrationName
# Run migrations
npm run typeorm migration:runThis project is private and proprietary. All rights reserved.
SensitiveMinds Backend
- Author: Daniel ΕledΕΊ
- Frontend Repository: SensitiveMinds
- Backend Repository: SensitiveMinds Backend
Built with β€οΈ for efficient therapy management
Secure backend solutions for modern healthcare