Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Building a Scalable Auth Service Using Node.js, Express, PostgreSQL, and Prisma (Microservices Architecture)

Below is a production-style Auth Service for your Local Marketplace Microservices Platform using: Node.js Express PostgreSQL Prisma ORM JWT Authentication Docker-ready structure Layered architecture (Controller → Service → Rep…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Below is a production-style Auth Service for your Local Marketplace Microservices Platform using:




  • Node.js

  • Express

  • PostgreSQL

  • Prisma ORM

  • JWT Authentication

  • Docker-ready structure

  • Layered architecture (Controller → Service → Repository)



This structure is similar to what engineers use in production systems at companies like Stripe and Shopify.

📁 Auth Service Folder Structure

auth-service

│

├── src

│ ├── config

│ │ └── db.js

│ │

│ ├── controllers

│ │ └── auth.controller.js

│ │

│ ├── services

│ │ └── auth.service.js

│ │

│ ├── repositories

│ │ └── user.repository.js

│ │

│ ├── routes

│ │ └── auth.routes.js

│ │

│ ├── middlewares

│ │ └── auth.middleware.js

│ │

│ ├── utils

│ │ ├── hash.js

│ │ └── jwt.js

│ │

│ ├── app.js

│ └── server.js

│

├── prisma

│ ├── schema.prisma

│ └── seed.js

│

├── .env

├── package.json

└── Dockerfile


1️⃣ package.json




{
"name": "auth-service",
"version": "1.0.0",
"main": "src/server.js",
"scripts": {
"dev": "nodemon src/server.js",
"start": "node src/server.js",
"prisma": "prisma migrate dev"
},
"dependencies": {
"@prisma/client": "^5.0.0",
"bcryptjs": "^2.4.3",
"dotenv": "^16.0.0",
"express": "^4.18.2",
"jsonwebtoken": "^9.0.0"
},
"devDependencies": {
"nodemon": "^3.0.0",
"prisma": "^5.0.0"
}
}






2️⃣ .env




PORT=4000

DATABASE_URL="postgresql://postgres:password@localhost:5432/auth_db"

JWT_SECRET=supersecret






3️⃣ Prisma Schema

📁 prisma/schema.prisma




generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model User {
id String @id @default(uuid())
name String
email String @unique
password String
role String @default("CUSTOMER")
createdAt DateTime @default(now())
}






Run:




npx prisma generate
npx prisma migrate dev --name init






4️⃣ DB Config



📁 src/config/db.js




const { PrismaClient } = require('@prisma/client')

const prisma = new PrismaClient()

module.exports = prisma






5️⃣ Hash Utility



📁 src/utils/hash.js




const bcrypt = require('bcryptjs')

exports.hashPassword = async (password) => {
return bcrypt.hash(password, 10)
}

exports.comparePassword = async (password, hash) => {
return bcrypt.compare(password, hash)
}






6️⃣ JWT Utility



📁 src/utils/jwt.js




const jwt = require('jsonwebtoken')

exports.generateToken = (payload) => {
return jwt.sign(payload, process.env.JWT_SECRET, {
expiresIn: "1d"
})
}






7️⃣ Repository Layer



📁 src/repositories/user.repository.js




const prisma = require('../config/db')

exports.createUser = (data) => {
return prisma.user.create({ data })
}

exports.findUserByEmail = (email) => {
return prisma.user.findUnique({
where: { email }
})
}






8️⃣ Service Layer



📁 src/services/auth.service.js




const userRepo = require('../repositories/user.repository')
const { hashPassword, comparePassword } = require('../utils/hash')
const { generateToken } = require('../utils/jwt')

exports.register = async (data) => {

const existingUser = await userRepo.findUserByEmail(data.email)

if (existingUser) {
throw new Error("User already exists")
}

const hashedPassword = await hashPassword(data.password)

const user = await userRepo.createUser({
...data,
password: hashedPassword
})

return user
}

exports.login = async ({ email, password }) => {

const user = await userRepo.findUserByEmail(email)

if (!user) {
throw new Error("Invalid credentials")
}

const valid = await comparePassword(password, user.password)

if (!valid) {
throw new Error("Invalid credentials")
}

const token = generateToken({
id: user.id,
email: user.email
})

return { token }
}






9️⃣ Controller



📁 src/controllers/auth.controller.js




const authService = require('../services/auth.service')

exports.register = async (req, res) => {
try {

const user = await authService.register(req.body)

res.status(201).json(user)

} catch (error) {

res.status(400).json({
message: error.message
})

}
}

exports.login = async (req, res) => {

try {

const result = await authService.login(req.body)

res.json(result)

} catch (error) {

res.status(401).json({
message: error.message
})

}
}






🔟 Routes



📁 src/routes/auth.routes.js




const express = require('express')
const router = express.Router()

const authController = require('../controllers/auth.controller')

router.post('/register', authController.register)

router.post('/login', authController.login)

module.exports = router






1️⃣1️⃣ Express App



📁 src/app.js




const express = require('express')
const authRoutes = require('./routes/auth.routes')

const app = express()

app.use(express.json())

app.use('/auth', authRoutes)

module.exports = app






1️⃣2️⃣ Server



📁 src/server.js




require('dotenv').config()

const app = require('./app')

const PORT = process.env.PORT || 4000

app.listen(PORT, () => {
console.log(`Auth service running on port ${PORT}`)
})






1️⃣3️⃣ Dockerfile




FROM node:20

WORKDIR /app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 4000

CMD ["npm","start"]






🚀 API Endpoints

Register User




POST /auth/register






Body




{
"name": "John",
"email": "[email protected]",
"password": "123456"
}






Login




POST /auth/login






Body




{
"email": "[email protected]",
"password": "123456"
}






⭐ What Makes This Production-Ready



✔ Layered architecture

✔ Repository pattern

✔ Prisma ORM

✔ JWT authentication

✔ Microservice-ready

✔ Docker-ready

✔ Scalable structure

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - Building a Scalable Auth Service Using Node.js, Express, PostgreSQL, and Prisma (Microservices Architecture)
id: 13463263-eada-45bd-b182-76f77b157c0e
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-27
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-27"
        description = "YARA Signature for "
    strings:
        $str = "Building a Scalable Auth Servi" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Building a Scalable Auth Service Using N")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Building a Scalable Auth Service Using N*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Building a Scalable Auth Service Using N"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Building a Scalable Auth Service Using N.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Building a Scalable Auth Service Using Node.js, Express, PostgreSQL, and Prisma (Microservices Architecture)

Thematisch verwandte Begriffe: Building, Scalable, Auth, Service · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100620 | Capgo CLI (npm package @capgo/cli) through 7.98.2 is affected by an ove…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag