🔐 Fullstack Security Implementation
A comprehensive authentication and authorization dashboard featuring React.js frontend, Node.js backend, PostgreSQL database, JWT/OAuth2.0 authentication, and mTLS security.
🔒 Authentication & Authorization
JWT Authentication - Access & Refresh tokens with HTTP-only cookies
OAuth2.0 Integration - Google OAuth, Github OAuth and Keycloak support
Role-Based Access Control (RBAC) - Admin, Manager, and User roles
Mutual TLS (mTLS) - Certificate-based authentication for enhanced security
User registration with email/password validation
Password hashing with bcrypt
Profile management
Session management with device tracking
Login activity logging
Rate limiting for brute force protection
Input validation and sanitization
Security headers with Helmet
CORS configuration
Suspicious activity detection
Failed login attempt monitoring
User management with advanced filtering
Bulk operations (status toggle, role assignment)
Analytics and charts
Audit log viewer
System health monitoring
User data export (JSON/CSV)
Layer
Technology
Frontend
React 19, React Router 7, Tailwind CSS 4, Vite 7
Backend
Node.js, Express.js, TypeScript
Database
PostgreSQL 15, Prisma ORM
Authentication
JWT, Passport.js, OAuth2.0
OAuth Server
Keycloak 25
Security
mTLS, bcrypt, Helmet
Containerization
Docker, Docker Compose
fullstack-security-implementation/
├── backend/
│ ├── certs/ # TLS certificates for mTLS
│ ├── prisma/
│ │ ├── migrations/ # Database migrations
│ │ ├── schema.prisma # Database schema
│ │ └── seed.ts # Database seeder
│ └── src/
│ ├── controllers/ # Route controllers
│ ├── middleware/ # Auth, RBAC, mTLS middleware
│ ├── routes/ # API routes
│ ├── types/ # TypeScript types
│ ├── utils/ # Utility functions
│ └── server.ts # Express server
├── frontend/
│ └── src/
│ ├── components/ # React components
│ ├── context/ # Auth context provider
│ ├── pages/ # Page components
│ │ └── Dashboard/ # Dashboard pages
│ └── services/ # API service layer
├── docker/
│ ├── docker-compose.yml # Docker services configuration
│ └── keycloak-init.sh # Keycloak initialization script
└── implementation-plan.md # Detailed implementation plan
Node.js 18+
Yarn or npm
Docker & Docker Compose
PostgreSQL (or use Docker)
git clone < repository-url>
cd fullstack-security-implementation
2. Start Database Services
cd docker
docker-compose up -d postgres keycloak
cd backend
# Install dependencies
yarn install
# Create environment file
cp .env.example .env
# Generate Prisma client
yarn prisma:generate
# Run database migrations
yarn prisma:migrate
# Seed the database (creates demo users)
yarn prisma:seed
# Start development server
yarn dev
cd frontend
# Install dependencies
yarn install
# Start development server
yarn dev
5. Access the Application
Method
Endpoint
Description
POST
/api/auth/register
Register new user
POST
/api/auth/login
Login with email/password
POST
/api/auth/logout
Logout user
POST
/api/auth/refresh
Refresh access token
GET
/api/auth/me
Get current user
GET
/api/auth/google
Google OAuth login
GET
/api/auth/keycloak
Keycloak OAuth login
Method
Endpoint
Description
GET
/api/activity/my/history
User's login history
GET
/api/activity/my/sessions
User's active sessions
DELETE
/api/activity/my/sessions/:id
Revoke specific session
POST
/api/activity/my/sessions/revoke-all
Revoke all other sessions
GET
/api/activity/my/security
User's security summary
Method
Endpoint
Description
GET
/api/admin/users
List all users with filtering
GET
/api/admin/dashboard
Dashboard statistics
PUT
/api/admin/users/:id/role
Update user role
PUT
/api/admin/users/:id/status
Toggle user status
POST
/api/admin/users/bulk-status
Bulk status update
POST
/api/admin/users/bulk-role
Bulk role assignment
GET
/api/admin/audit-logs
Security audit logs
GET
/api/admin/system-health
System health overview
GET
/api/admin/export
Export user data
mTLS (Certificate Required)
Method
Endpoint
Description
GET
/api/mtls/verify
Verify client certificate
GET
/api/mtls/info
Get certificate info
cd backend/certs
./generate-certs.sh
This generates:
ca.crt / ca.key - Certificate Authority
server.crt / server.key - Server certificate
client.crt / client.key - Client certificate
client.p12 - PKCS12 bundle for browser import
Set in .env:
MTLS_ENABLED = true
HTTPS_PORT = 5443
cd docker
docker-compose --profile full up -d
Services Only (Database + Keycloak)
cd docker
docker-compose up -d
Variable
Description
Default
PORT
HTTP port
5000
HTTPS_PORT
HTTPS port (mTLS)
5443
DATABASE_URL
PostgreSQL connection string
-
JWT_ACCESS_SECRET
JWT access token secret
-
JWT_REFRESH_SECRET
JWT refresh token secret
-
GOOGLE_CLIENT_ID
Google OAuth client ID
-
GOOGLE_CLIENT_SECRET
Google OAuth client secret
-
KEYCLOAK_URL
Keycloak server URL
http://localhost:8080
KEYCLOAK_REALM
Keycloak realm name
security-app
KEYCLOAK_CLIENT_ID
Keycloak client ID
security-app-client
MTLS_ENABLED
Enable mTLS
false
Profile settings
Active sessions management
Security overview
Personal data
User list view
Team statistics
Reports
Full user management
Analytics and charts
Audit logs
System health monitoring
Role assignment
Bulk operations
yarn dev # Start development server
yarn build # Build for production
yarn start # Start production server
yarn prisma:studio # Open Prisma Studio
yarn prisma:migrate # Run migrations
yarn prisma:seed # Seed database
yarn dev # Start development server
yarn build # Build for production
yarn preview # Preview production build
yarn lint # Run ESLint
📝 Security Best Practices Implemented
✅ Password hashing with bcrypt (cost factor 12)
✅ JWT tokens with short expiry (15 min access, 7 day refresh)
✅ HTTP-only cookies for token storage
✅ CSRF protection
✅ Rate limiting (100 requests/15 min)
✅ Input validation and sanitization
✅ Security headers (Helmet)
✅ CORS configuration
✅ mTLS for certificate-based auth
✅ Audit logging
✅ Suspicious activity detection
✅ Brute force protection
MIT License - see LICENSE for details.
Fork the repository
Create your 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
For support, please open an issue in the repository.
Built with ❤️ for secure applications