A comprehensive, production-ready security platform built with TypeScript, featuring advanced access control mechanisms, multi-factor authentication, audit logging, and automated backups. This system demonstrates enterprise-grade security practices with Mandatory Access Control (MAC), Discretionary Access Control (DAC), Role-Based Access Control (RBAC), Rule-Based Access Control (RuBAC), and Attribute-Based Access Control (ABAC).
The fastest way to get started is using Docker Compose:
# Clone the repository
git clone <repository-url>
cd security-project
# Start all services
docker compose up --build
# Access the application at http://localhostThat's it! The application will be running with all dependencies automatically configured.
- Prerequisites
- Installation & Setup
- Environment Configuration
- Running the Application
- Architecture Overview
- Security Features
- API Documentation
- Development
- Troubleshooting
- Deployment
- Docker: Version 20.10 or later
- Docker Compose: Version 2.0 or later
- Git: For cloning the repository
- At least 4GB RAM for Docker containers
- 2GB free disk space for containers and data
- Node.js: Version 18 or later
- npm: Version 8 or later
- PostgreSQL client (for local database access)
-
Clone the repository
git clone <repository-url> cd security-project
-
Start the application
# Build and start all services docker compose up --build # Or run in background docker compose up -d --build
-
Access the application
- Frontend: http://localhost
- Backend API: http://localhost/api
- Admin Panel: http://localhost/admin
-
Default admin account
- Email:
admin@security.local - Password:
admin123(change this immediately!)
- Email:
-
Install dependencies
npm install
-
Set up environment
cp .env.example .env # Edit .env with your configuration -
Start PostgreSQL (using Docker)
docker run --name postgres-dev -e POSTGRES_PASSWORD=mypassword -e POSTGRES_DB=security_db -p 5432:5432 -d postgres:15-alpine
-
Run database migrations
npm run db:setup
-
Start development server
npm run dev
Create a .env file in the root directory with the following variables:
# PostgreSQL Database
DB_HOST=localhost
DB_PORT=5432
DB_NAME=security_db
DB_USER=admin
DB_PASSWORD=secure_password_here
# For Docker Compose (internal networking)
# DB_HOST=db
# DB_USER=admin
# DB_PASSWORD=security123# JWT Configuration
JWT_SECRET=your-super-secure-jwt-secret-here-minimum-32-chars
REFRESH_TOKEN_SECRET=your-super-secure-refresh-token-secret-here-minimum-32-chars
# Session Configuration
SESSION_TIMEOUT_MINUTES=60
MAX_FAILED_ATTEMPTS=5
LOCKOUT_DURATION_MINUTES=30
# Password Policy
MIN_PASSWORD_LENGTH=8
PASSWORD_HISTORY_COUNT=5# EmailJS Configuration (for email verification)
EMAILJS_SERVICE_ID=your_emailjs_service_id
EMAILJS_TEMPLATE_ID=your_emailjs_template_id
EMAILJS_PUBLIC_KEY=your_emailjs_public_key
APP_URL=http://localhost
# reCAPTCHA Configuration (for bot protection)
RECAPTCHA_SITE_KEY=your_recaptcha_site_key
RECAPTCHA_SECRET_KEY=your_recaptcha_secret_key# Backup Settings
BACKUP_SCHEDULE=0 2 * * * # Daily at 2 AM
BACKUP_RETENTION_DAYS=30
BACKUP_DIR=./backupsNODE_ENV=development # or 'production'
LOG_LEVEL=info # or 'debug', 'warn', 'error'# Start all services
docker compose up -d
# View logs
docker compose logs -f
# Stop all services
docker compose down
# Rebuild after code changes
docker compose up --build -d
# Clean restart (removes volumes)
docker compose down -v
docker compose up --build -dβββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Nginx Proxy β β React App β β Node.js API β
β (Port 80) βββββΊβ (Port 80) βββββΊβ (Port 3000) β
β β β β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βββββββββββββββββββββββββΌββββββββββββββββββββββββ
βΌ
βββββββββββββββββββ
β PostgreSQL DB β
β (Port 5432) β
βββββββββββββββββββ
- Main Application: http://localhost
- API Documentation: http://localhost/api/docs (if Swagger enabled)
- Database: localhost:5432 (from host machine)
- Logs: Available in
./logs/directory - Backups: Available in
./backups/directory
src/
βββ models/ # Database models and queries
βββ routes/ # API route handlers
βββ services/ # Business logic and external services
βββ middleware/ # Authentication, authorization, validation
βββ utils/ # Helper functions and utilities
βββ types/ # TypeScript type definitions
- Authentication Service: JWT tokens, MFA, password hashing
- Access Control Service: MAC, DAC, RBAC, RuBAC, ABAC enforcement
- Audit Service: Comprehensive logging and monitoring
- Backup Service: Automated database backups
- Email Service: Verification emails and notifications
users # User accounts and authentication
roles # Role definitions and permissions
user_roles # User-role assignments
documents # Secure documents with classification
document_permissions # DAC permissions for documents
policies # RuBAC and ABAC policy definitions
audit_logs # Security event logging
employees # Extended user profile information- JWT-based authentication with automatic token refresh
- Multi-Factor Authentication (MFA) with TOTP
- Password hashing with bcrypt and salt rounds
- Account lockout after failed attempts
- Session management with configurable timeouts
- Security levels: PUBLIC, INTERNAL, CONFIDENTIAL
- No read-up, no write-down enforcement
- Clearance-based access decisions
- Owner-based permissions on documents
- Explicit sharing with read/write/full access
- Admin override capabilities
- Hierarchical roles with inheritance
- Permission-based access to features
- Dynamic role assignment and revocation
- Time-based restrictions (working hours, weekends)
- Location-based rules (IP restrictions)
- Contextual access policies
- Department-based access control
- User attribute evaluation
- Dynamic policy enforcement
- Comprehensive logging of all security events
- Real-time monitoring with alerting
- Immutable audit trail in database
- Automated backups with retention policies
- Rate limiting to prevent abuse
# User registration
POST /api/auth/register
{
"username": "john_doe",
"email": "john@example.com",
"password": "SecurePass123!",
"phone_number": "+1234567890"
}
# User login
POST /api/auth/login
{
"email": "john@example.com",
"password": "SecurePass123!",
"otp": "123456" // If MFA enabled
}
# Password reset
POST /api/auth/forgot-password
{
"email": "john@example.com"
}
POST /api/auth/reset-password
{
"token": "reset_token_here",
"newPassword": "NewSecurePass123!"
}# List accessible documents
GET /api/documents
# Create new document
POST /api/documents
{
"name": "Confidential Report",
"classification": "CONFIDENTIAL",
"content": "Document content here..."
}
# Share document
POST /api/documents/{id}/share
{
"userId": 123,
"permission": "read"
}# User management (Admin only)
GET /api/users
POST /api/users/{id}/roles
DELETE /api/users/{id}/roles/{roleId}
# Access policies (Admin only)
GET /api/rules
POST /api/rules
PUT /api/rules/{id}
DELETE /api/rules/{id}
# Audit logs (Admin only)
GET /api/audit
GET /api/audit/export- Install dependencies
npm install-
Set up local database
# Using Docker docker run --name postgres-dev \ -e POSTGRES_PASSWORD=mypassword \ -e POSTGRES_DB=security_db \ -p 5432:5432 \ -d postgres:15-alpine -
Run database migrations
npm run db:setup
-
Start development servers
# Backend (with hot reload) npm run dev # Frontend (separate terminal) cd client && npm run dev
# Backend scripts
npm run build # Build TypeScript
npm run dev # Development server with hot reload
npm run start # Production server
npm run test # Run tests
npm run lint # Code linting
# Database scripts
npm run db:setup # Initialize database
npm run db:migrate # Run migrations
npm run db:seed # Seed with sample data
# Docker scripts
docker compose up -d # Start all services
docker compose logs -f # View logs
docker compose down # Stop services
docker compose restart app # Restart backend# Run backend tests
npm test
# Run with coverage
npm run test:coverage
# Integration tests
npm run test:integration# Check if PostgreSQL is running
docker ps | grep postgres
# View database logs
docker logs security_db
# Reset database
docker compose down -v
docker compose up --build db# Check environment variables
cat .env
# View application logs
docker compose logs app
# Check if ports are available
netstat -tulpn | grep :3000# Check EmailJS configuration
echo $EMAILJS_SERVICE_ID
# Verify APP_URL setting
echo $APP_URL
# Check server logs for email errors
docker compose logs app | grep -i email# Check user roles
docker exec security_app psql -U admin -d security_db -c "SELECT u.username, r.name FROM users u JOIN user_roles ur ON u.id = ur.user_id JOIN roles r ON ur.role_id = r.id;"
# Verify JWT token
# Check browser developer tools β Network tab β Request headers# Check backup directory permissions
ls -la backups/
# View backup logs
docker compose logs app | grep -i backup
# Manual backup test
docker exec security_app pg_dump -U admin security_db > backup.sql# Monitor container resources
docker stats
# Check Node.js memory usage
docker exec security_app ps aux | grep node
# Adjust Node.js memory limits
export NODE_OPTIONS="--max-old-space-size=1024"# Enable query logging
docker exec security_app psql -U admin -d security_db -c "ALTER DATABASE security_db SET log_statement = 'all';"
# View slow queries
docker compose logs db | grep -i duration- Change default admin password
- Set strong JWT secrets (minimum 32 characters)
- Configure HTTPS/TLS certificates
- Set up firewall rules
- Enable database SSL connections
- Configure log rotation and monitoring
- Set up automated security updates
- Enable rate limiting and DDoS protection
-
Set up production environment
export NODE_ENV=production export APP_URL=https://yourdomain.com
-
Configure reverse proxy (nginx example)
server { listen 443 ssl; server_name yourdomain.com; ssl_certificate /path/to/cert.pem; ssl_certificate_key /path/to/key.pem; location / { proxy_pass http://localhost:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /api { proxy_pass http://localhost:3000/api; # Same headers as above } }
-
Set up SSL certificates
# Using Let's Encrypt certbot --nginx -d yourdomain.com -
Configure systemd service
# Create service file: /etc/systemd/system/security-app.service [Unit] Description=Security Management System After=network.target [Service] Type=simple User=appuser WorkingDirectory=/opt/security-app ExecStart=/usr/bin/npm start Restart=always Environment=NODE_ENV=production [Install] WantedBy=multi-user.target
# Application health
curl http://localhost/api/health
# Database connectivity
docker exec security_app pg_isready -U admin -d security_db# List recent backups
ls -la backups/ | head -10
# Verify backup integrity
docker exec security_app pg_restore --list backup.sql# View recent errors
tail -f logs/app.log | grep -i error
# Count failed login attempts
docker exec security_app psql -U admin -d security_db -c "SELECT COUNT(*) FROM audit_logs WHERE action = 'LOGIN_FAILED' AND created_at > NOW() - INTERVAL '1 hour';"- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- TypeScript: Strict type checking enabled
- ESLint: Code linting and formatting
- Pre-commit hooks: Automated testing and linting
- Security: Regular dependency updates and security scans
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Documentation: Check this README first
- Issues: Use GitHub Issues for bugs and feature requests
- Discussions: Use GitHub Discussions for questions
- Security: Report security vulnerabilities privately
- β Core Security Features: MAC, DAC, RBAC, RuBAC, ABAC
- β Authentication: JWT, MFA, Email verification
- β Audit & Compliance: Comprehensive logging
- β Automated Backups: Scheduled database backups
- β Docker Support: Production-ready containerization
- β API Documentation: RESTful API with proper responses
Built with security-first principles and enterprise-grade architecture. πβ¨