Skip to content

This project is a NestJS backend API designed for managing developer projects, resources, secrets, and API keys, with robust authentication and authorization using Keycloak.

License

Notifications You must be signed in to change notification settings

JawherKl/nestjs-stack

Repository files navigation

NestJS Stack Backend API

Repository Size Last Commit Issues Forks Stars

nestapi

Enterprise-grade NestJS backend for managing developer projects, resources, secrets, and API keys with Keycloak authentication.

πŸ› οΈ Tech Stack

  • Framework: NestJS + Fastify
  • Database: PostgreSQL with Prisma ORM
  • Auth: Keycloak Integration
  • Docs: OpenAPI/Swagger
  • Testing: Jest + Supertest

πŸš€ Features

Authentication & Authorization

  • Keycloak integration
  • JWT token validation
  • Role-based access control
  • User registration & login
  • Token refresh support

Project Management

  • CRUD operations
  • Ownership validation
  • Soft delete functionality
  • Pagination & filtering
  • Search capabilities

Resource Management

  • Secure secrets storage
  • API keys management
  • Project-based organization
  • Resource type validation
  • Archive/restore support

Audit Logging

  • Track all critical actions (create/update/delete) for projects and resources
  • Store logs in a dedicated table
  • Expose an endpoint for admins to review logs

Resource Sharing & Permissions

  • Allow project/resource sharing with other users
  • Implement granular permissions (read/write/admin) per resource/project

πŸ—οΈ Installation

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env

# Create database
psql -U postgres -c "CREATE DATABASE neststack_db;"

# Run database migrations
npx prisma migrate dev

πŸš€ Running the App

# Development
npm run start:dev

# Production
npm run start:prod

πŸ§ͺ Testing

# Unit tests
npm run test

# E2E tests
npm run test:e2e

# Test coverage
npm run test:cov

πŸ“š API Documentation

Once the application is running, access the Swagger documentation at:

http://localhost:3000/api/docs

πŸ”§ Environment Variables

# Database
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/neststack"

# Keycloak
KEYCLOAK_AUTH_SERVER_URL="http://localhost:8080/auth"
KEYCLOAK_REALM="realm-name"
KEYCLOAK_CLIENT_ID="client-name"
KEYCLOAK_CLIENT_SECRET="your-client-secret"

# App
PORT=3000
NODE_ENV=development

πŸ“ Project Structure

src/
β”œβ”€β”€ audit-log/              # Audit Logging
β”œβ”€β”€ auth/                   # Authentication & authorization
β”œβ”€β”€ dto/                    # Data transfer objects
β”œβ”€β”€ keycloak/               # Keycloak implementation
β”œβ”€β”€ prisma/                 # Database schema & migrations
β”œβ”€β”€ project/                # Project management
β”œβ”€β”€ project-permission/     # Project permission management
β”œβ”€β”€ resource/               # Resource management
β”œβ”€β”€ resource-permission/    # Resource premission management
└── user/                   # User informations management

πŸ§ͺ Test Environment

# Create test database
psql -U postgres -c "CREATE DATABASE neststack_test;"

# Run tests with test environment
NODE_ENV=test npm run test

πŸ“ API Endpoints

Auth Routes

  • POST /api/auth/register - Register new user
  • POST /api/auth/login - User login
  • POST /api/auth/logout - User logout

Project Routes

  • GET /api/projects - List all projects
  • POST /api/projects - Create project
  • GET /api/projects/:id - Get project
  • PUT /api/projects/:id - Update project
  • DELETE /api/projects/:id - Delete project

Resource Routes

  • GET /api/resources - List all resources
  • POST /api/resources - Create resource
  • GET /api/resources/:id - Get resource
  • DELETE /api/resources/:id - Delete resource

Audit Logging

  • GET /api/resources - List all audit log

Resource Sharing & Permissions

  • GET /projects/{projectId}/permissions - List permissions releated to project
  • POST /projects/{projectId}/permissions - Create permissions for project
  • GET /resources/{resourceId}/permissions - List permissions releated to resource
  • POST /resources/{resourceId}/permissions - Create permissions for resource

πŸ‘€ Author

Jawher Kallel

πŸ“„ License

This project is MIT licensed.

About

This project is a NestJS backend API designed for managing developer projects, resources, secrets, and API keys, with robust authentication and authorization using Keycloak.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published