A progressive Node.js framework for building efficient and scalable server-side applications.
A robust NestJS backend API for managing a construction company's admin dashboard. Built with TypeScript, featuring secure authentication, contact management, and project portfolio management.
- π Secure Authentication: JWT-based authentication with bcrypt password hashing
- π Contact Management: Store and manage customer inquiries and contact information
- π’ Project Portfolio: Upload and manage construction projects with images and descriptions
- π Dashboard Analytics: Get overview statistics and recent activities
- π‘οΈ Protected Routes: All admin endpoints require authentication
- β Input Validation: Comprehensive validation using Zod schemas
- ποΈ Database: MySQL with Drizzle ORM for type-safe database operations
- Node.js (v18 or higher)
- MySQL database
- npm or yarn
-
Clone the repository
git clone <your-repo-url> cd pues-api-node
-
Install dependencies
npm install
-
Set up environment variables Create a
.env
file in the root directory:DATABASE_URL=mysql://username:password@localhost:3306/pues_api JWT_SECRET=your_super_secret_jwt_key_here_make_it_long_and_random PORT=3000 NODE_ENV=development
-
Set up the database
# Generate migrations npm run db:generate # Run migrations npm run db:migrate
-
Start the development server
npm run start:dev
The API will be available at http://localhost:3000
POST /auth/signup
Content-Type: application/json
{
"email": "admin@construction.com",
"password": "securepassword123",
"name": "Admin User"
}
POST /auth/signin
Content-Type: application/json
{
"email": "admin@construction.com",
"password": "securepassword123"
}
All admin endpoints require a JWT token in the Authorization header:
Authorization: Bearer <your_jwt_token>
GET /admin/profile
GET /admin/contacts # List all contacts
GET /admin/contacts/:id # Get specific contact
DELETE /admin/contacts/:id # Delete contact
GET /admin/projects # List all projects
GET /admin/projects/:id # Get specific project
POST /admin/projects # Create new project
PUT /admin/projects/:id # Update project
DELETE /admin/projects/:id # Delete project
GET /admin/dashboard/stats # Get dashboard statistics
POST /admin/projects
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Modern Office Building",
"description": "A state-of-the-art office complex with sustainable design",
"imageUrl": "https://example.com/project-image.jpg",
"completedAt": "2024-01-15T00:00:00.000Z"
}
# Development
npm run start:dev # Start in watch mode
npm run start:debug # Start with debug
# Production
npm run build # Build the application
npm run start:prod # Start production server
# Database
npm run db:generate # Generate database migrations
npm run db:migrate # Run database migrations
npm run db:studio # Open Drizzle Studio
# Testing
npm run test # Run unit tests
npm run test:e2e # Run end-to-end tests
npm run test:cov # Run tests with coverage
# Code Quality
npm run lint # Run ESLint
npm run format # Format code with Prettier
src/
βββ auth/ # Authentication module
β βββ auth.controller.ts # Auth endpoints
β βββ auth.service.ts # Auth business logic
β βββ jwt.strategy.ts # JWT authentication
β βββ auth.module.ts # Auth module config
βββ admin/ # Admin dashboard module
β βββ admin.controller.ts # Admin endpoints
β βββ admin.service.ts # Admin business logic
β βββ admin.module.ts # Admin module config
βββ db/ # Database configuration
β βββ index.ts # Database connection
β βββ schema.ts # Database schema
β βββ database.module.ts # Database module
βββ utils/ # Utility functions
βββ zod-validation.pipe.ts
βββ zod-exception.filters.ts
- Password Hashing: bcrypt with 12 salt rounds
- JWT Tokens: 24-hour expiration for admin sessions
- Input Validation: Zod schemas for all inputs
- Protected Routes: Authentication required for admin endpoints
- Soft Deletes: Safe deletion (marked as deleted, not removed)
- Error Handling: Proper error responses for invalid requests
id
: Primary keyemail
: Unique email addresspasswordHash
: Hashed passwordname
: Admin user namecreatedAt
,updatedAt
: Timestampsdeleted
,deletedAt
: Soft delete fields
id
: Primary keytitle
: Project titledescription
: Project descriptionimageUrl
: Project image URLcompletedAt
: Completion dateupdatedAt
: Last update timestampdeleted
,deletedAt
: Soft delete fields
id
: Primary keyname
: Contact nameemail
: Contact emailphone
: Contact phone (optional)message
: Contact messagecreatedAt
: Contact creation timestampupdatedAt
: Last update timestampdeleted
,deletedAt
: Soft delete fields
DATABASE_URL=mysql://user:password@host:port/database
JWT_SECRET=your_production_jwt_secret
NODE_ENV=production
PORT=3000
npm run db:migrate
- 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
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository.
- Check the AUTH_SETUP.md for detailed setup instructions.