Skip to main content

Tech Stack

Complete reference of technologies powering AsaHome Cloud.

Backend Stack

Runtime & Framework

TechnologyVersionPurpose
Node.js20+JavaScript runtime
NestJS10.xProgressive Node.js framework
TypeScript5.xType-safe JavaScript

Why NestJS?

NestJS was chosen for its:

  • Modular Architecture: Clean separation of concerns
  • TypeScript First: Full type safety out of the box
  • Dependency Injection: Testable, maintainable code
  • Decorators: Express-like but with structure
  • Built-in WebSocket Support: Socket.IO integration
  • OpenAPI/Swagger: Automatic API documentation

Database

TechnologyVersionPurpose
PostgreSQL16Primary relational database
TypeORM0.3.xObject-Relational Mapping

TypeORM features used:

// Entity example with TypeORM decorators
@Entity('devices')
export class Device {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ unique: true })
uuid: string;

@Column({ default: false })
isOnline: boolean;

@Column({ type: 'jsonb', nullable: true })
metadata: Record<string, any>;

@CreateDateColumn()
createdAt: Date;
}

Authentication & Security

TechnologyPurpose
Passport.jsAuthentication middleware
@nestjs/jwtJWT token generation/validation
bcryptPassword hashing (12 rounds)
Helmet.jsSecurity headers
@nestjs/throttlerRate limiting

JWT Configuration

JwtModule.register({
secret: process.env.JWT_SECRET,
signOptions: {
expiresIn: '15m', // Access token
},
})

Password Security

// bcrypt with 12 salt rounds
const hashedPassword = await bcrypt.hash(password, 12);

Real-time Communication

TechnologyVersionPurpose
Socket.IO4.xWebSocket library
@nestjs/websockets-NestJS WebSocket integration

WebSocket Gateway

@WebSocketGateway({
namespace: '/tunnel',
cors: {
origin: process.env.CORS_ORIGINS?.split(','),
credentials: true,
},
})
export class TunnelGateway {
@WebSocketServer()
server: Server;

@SubscribeMessage('tunnel:message')
handleMessage(@MessageBody() data: TunnelMessage) {
// Route message to device
}
}

Infrastructure

Containerization

TechnologyPurpose
DockerContainer runtime
Docker ComposeMulti-container orchestration
Alpine LinuxMinimal base images

Dockerfile

# Multi-stage build for production
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine AS production
WORKDIR /app
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/node_modules ./node_modules
EXPOSE 3000
CMD ["node", "dist/main.js"]

Reverse Proxy

TechnologyVersionPurpose
NginxAlpineReverse proxy, TLS termination

API Documentation

TechnologyPurpose
@nestjs/swaggerOpenAPI spec generation

OpenAPI Setup

The API uses NestJS Swagger module to generate OpenAPI specifications:

const config = new DocumentBuilder()
.setTitle('AsaHome Cloud API')
.setDescription('API for remote AsaHome OS access')
.setVersion('1.0')
.addBearerAuth()
.build();

const document = SwaggerModule.createDocument(app, config);

Test the API using Postman or any HTTP client at https://cloud.asahome.io/api/v1

Development Tools

Testing

ToolPurpose
JestUnit and integration testing
SupertestHTTP assertion library
@nestjs/testingNestJS testing utilities

Code Quality

ToolPurpose
ESLintCode linting
PrettierCode formatting
HuskyGit hooks
lint-stagedRun linters on staged files

CI/CD

ToolPurpose
GitHub ActionsCI/CD pipelines
Docker HubContainer registry

Package Dependencies

Production Dependencies

{
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/jwt": "^10.0.0",
"@nestjs/passport": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-socket.io": "^10.0.0",
"@nestjs/swagger": "^7.0.0",
"@nestjs/throttler": "^5.0.0",
"@nestjs/typeorm": "^10.0.0",
"@nestjs/websockets": "^10.0.0",
"bcrypt": "^5.1.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"helmet": "^7.0.0",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pg": "^8.11.0",
"socket.io": "^4.7.0",
"typeorm": "^0.3.17"
}

Development Dependencies

{
"@nestjs/cli": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/bcrypt": "^5.0.0",
"@types/jest": "^29.5.0",
"@types/node": "^20.0.0",
"@types/passport-jwt": "^3.0.0",
"eslint": "^8.0.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"supertest": "^6.3.0",
"ts-jest": "^29.1.0",
"typescript": "^5.0.0"
}

Version Requirements

RequirementMinimum Version
Node.js20.0.0
npm9.0.0
Docker24.0.0
Docker Compose2.20.0
PostgreSQL16.0

Next Steps