create-arktos 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +69 -0
- package/LICENSE +21 -0
- package/README.md +533 -0
- package/bin/cli.js +318 -0
- package/eslint.config.js +79 -0
- package/package.json +108 -0
- package/prisma/schema.prisma +172 -0
- package/src/app.ts +101 -0
- package/src/config/env.validation.ts +15 -0
- package/src/config/logger.ts +76 -0
- package/src/constants/errorCodes.ts +59 -0
- package/src/constants/messages.ts +190 -0
- package/src/controllers/auth.controller.ts +546 -0
- package/src/middleware/index.ts +638 -0
- package/src/routes/auth.routes.ts +29 -0
- package/src/routes/index.ts +63 -0
- package/src/schemas/index.ts +139 -0
- package/src/services/database.service.ts +120 -0
- package/src/services/email.service.ts +244 -0
- package/src/services/jwt.service.ts +227 -0
- package/src/types/express.d.ts +19 -0
- package/src/types/index.ts +156 -0
- package/src/utils/response.ts +55 -0
- package/src/views/emails/notification.html +87 -0
- package/src/views/emails/resetPassword.html +118 -0
- package/src/views/emails/verification.html +107 -0
- package/src/views/emails/welcome.html +113 -0
- package/template.package.json +82 -0
- package/tsconfig.json +35 -0
- package/vercel.json +34 -0
package/.env.example
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# =============================================================================
|
|
2
|
+
# ARKTOS BACKEND - ENVIRONMENT VARIABLES
|
|
3
|
+
# =============================================================================
|
|
4
|
+
# Copy this file to .env and fill in your actual values
|
|
5
|
+
# Never commit .env file to version control\!
|
|
6
|
+
|
|
7
|
+
# -----------------------------------------------------------------------------
|
|
8
|
+
# APPLICATION SETTINGS
|
|
9
|
+
# -----------------------------------------------------------------------------
|
|
10
|
+
NODE_ENV=development
|
|
11
|
+
PORT=3001
|
|
12
|
+
APP_NAME="Arktos"
|
|
13
|
+
|
|
14
|
+
# -----------------------------------------------------------------------------
|
|
15
|
+
# URLs
|
|
16
|
+
# -----------------------------------------------------------------------------
|
|
17
|
+
FRONTEND_URL=http://localhost:3000
|
|
18
|
+
BACKEND_URL=http://localhost:3001
|
|
19
|
+
|
|
20
|
+
# -----------------------------------------------------------------------------
|
|
21
|
+
# DATABASE CONFIGURATION (Neon PostgreSQL)
|
|
22
|
+
# -----------------------------------------------------------------------------
|
|
23
|
+
# Get these from your Neon dashboard: https://console.neon.tech/
|
|
24
|
+
DATABASE_URL="postgresql://username:password@hostname:port/database?sslmode=require"
|
|
25
|
+
DIRECT_URL="postgresql://username:password@hostname:port/database?sslmode=require"
|
|
26
|
+
|
|
27
|
+
# -----------------------------------------------------------------------------
|
|
28
|
+
# JWT CONFIGURATION
|
|
29
|
+
# -----------------------------------------------------------------------------
|
|
30
|
+
# Generate secure random strings for these keys in production
|
|
31
|
+
# You can use: openssl rand -base64 32
|
|
32
|
+
JWT_SECRET="your-super-secret-jwt-key-change-in-production-128-bits-minimum"
|
|
33
|
+
JWT_REFRESH_SECRET="your-super-secret-refresh-key-change-in-production-128-bits-minimum"
|
|
34
|
+
JWT_EXPIRES_IN="15m"
|
|
35
|
+
JWT_REFRESH_EXPIRES_IN="7d"
|
|
36
|
+
|
|
37
|
+
# -----------------------------------------------------------------------------
|
|
38
|
+
# EMAIL SERVICE (Resend)
|
|
39
|
+
# -----------------------------------------------------------------------------
|
|
40
|
+
# Get your API key from: https://resend.com/api-keys
|
|
41
|
+
RESEND_API_KEY="re_xxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
42
|
+
FROM_EMAIL="noreply@yourdomain.com"
|
|
43
|
+
FROM_NAME="Arktos"
|
|
44
|
+
|
|
45
|
+
# -----------------------------------------------------------------------------
|
|
46
|
+
# SECURITY SETTINGS
|
|
47
|
+
# -----------------------------------------------------------------------------
|
|
48
|
+
BCRYPT_SALT_ROUNDS=12
|
|
49
|
+
PASSWORD_MIN_LENGTH=8
|
|
50
|
+
MAX_LOGIN_ATTEMPTS=5
|
|
51
|
+
ACCOUNT_LOCK_TIME=900000
|
|
52
|
+
|
|
53
|
+
# -----------------------------------------------------------------------------
|
|
54
|
+
# CORS SETTINGS
|
|
55
|
+
# -----------------------------------------------------------------------------
|
|
56
|
+
CORS_ORIGIN="http://localhost:3000,https://yourdomain.com"
|
|
57
|
+
CORS_CREDENTIALS=true
|
|
58
|
+
|
|
59
|
+
# -----------------------------------------------------------------------------
|
|
60
|
+
# RATE LIMITING
|
|
61
|
+
# -----------------------------------------------------------------------------
|
|
62
|
+
RATE_LIMIT_WINDOW=900000
|
|
63
|
+
RATE_LIMIT_MAX=100
|
|
64
|
+
|
|
65
|
+
# -----------------------------------------------------------------------------
|
|
66
|
+
# LOGGING
|
|
67
|
+
# -----------------------------------------------------------------------------
|
|
68
|
+
LOG_LEVEL=info
|
|
69
|
+
LOG_FILE=logs/app.log
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Zafer Gök
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
# 🏛️ Arktos
|
|
2
|
+
|
|
3
|
+
> **A modern Node.js backend boilerplate generator with TypeScript, Express, JWT authentication, Prisma ORM, PostgreSQL, and Resend email service.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/arktos)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
|
|
9
|
+
## ⚡ Quick Start
|
|
10
|
+
|
|
11
|
+
Create a new backend project instantly:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Create a new project
|
|
15
|
+
npx create-arktos my-awesome-api
|
|
16
|
+
|
|
17
|
+
# Navigate to project
|
|
18
|
+
cd my-awesome-api
|
|
19
|
+
|
|
20
|
+
# Install dependencies
|
|
21
|
+
npm install
|
|
22
|
+
|
|
23
|
+
# Set up environment variables
|
|
24
|
+
cp .env.example .env
|
|
25
|
+
# Edit .env with your database and API keys
|
|
26
|
+
|
|
27
|
+
# Set up database
|
|
28
|
+
npx prisma migrate dev
|
|
29
|
+
|
|
30
|
+
# Start development server
|
|
31
|
+
npm run dev
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Your backend API is now running at `http://localhost:3001` 🚀
|
|
35
|
+
|
|
36
|
+
## 🌟 What's Included
|
|
37
|
+
|
|
38
|
+
### 🔐 **Complete Authentication System**
|
|
39
|
+
- JWT-based authentication with access & refresh tokens
|
|
40
|
+
- User registration with email verification
|
|
41
|
+
- Password reset functionality
|
|
42
|
+
- Profile management
|
|
43
|
+
- Login attempt logging and security monitoring
|
|
44
|
+
|
|
45
|
+
### 🛡️ **Security First**
|
|
46
|
+
- Rate limiting (general, auth, and API-specific)
|
|
47
|
+
- CORS protection with configurable origins
|
|
48
|
+
- Helmet.js security headers
|
|
49
|
+
- Input sanitization and validation with Zod
|
|
50
|
+
- Password hashing with bcrypt
|
|
51
|
+
- Request logging and monitoring
|
|
52
|
+
|
|
53
|
+
### 🗄️ **Database & ORM**
|
|
54
|
+
- Prisma ORM with PostgreSQL
|
|
55
|
+
- Pre-configured models (User, LoginLog, EmailVerification, etc.)
|
|
56
|
+
- Database health monitoring
|
|
57
|
+
- Migration system
|
|
58
|
+
- Neon serverless PostgreSQL ready
|
|
59
|
+
|
|
60
|
+
### 📧 **Email Service**
|
|
61
|
+
- Resend integration for transactional emails
|
|
62
|
+
- Pre-built email templates (welcome, verification, password reset)
|
|
63
|
+
- HTML email templates included
|
|
64
|
+
|
|
65
|
+
### 🏗️ **Modern Architecture**
|
|
66
|
+
- TypeScript with strict type checking
|
|
67
|
+
- Modular middleware system
|
|
68
|
+
- Singleton database service
|
|
69
|
+
- Centralized error handling
|
|
70
|
+
- Winston logging system
|
|
71
|
+
- Clean project structure
|
|
72
|
+
|
|
73
|
+
### 🚀 **Deployment Ready**
|
|
74
|
+
- Vercel configuration included
|
|
75
|
+
- Environment variable validation
|
|
76
|
+
- Production build scripts
|
|
77
|
+
- Health check endpoints
|
|
78
|
+
|
|
79
|
+
## 📦 Generated Project Structure
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
my-awesome-api/
|
|
83
|
+
├── src/
|
|
84
|
+
│ ├── app.ts # Express application setup
|
|
85
|
+
│ ├── config/
|
|
86
|
+
│ │ ├── env.validation.ts # Environment validation
|
|
87
|
+
│ │ └── logger.ts # Winston logger config
|
|
88
|
+
│ ├── constants/
|
|
89
|
+
│ │ ├── errorCodes.ts # Error code definitions
|
|
90
|
+
│ │ └── messages.ts # Response messages
|
|
91
|
+
│ ├── controllers/
|
|
92
|
+
│ │ └── auth.controller.ts # Authentication endpoints
|
|
93
|
+
│ ├── middleware/
|
|
94
|
+
│ │ └── index.ts # Security & validation middleware
|
|
95
|
+
│ ├── routes/
|
|
96
|
+
│ │ ├── auth.routes.ts # Auth route definitions
|
|
97
|
+
│ │ └── index.ts # Route aggregation
|
|
98
|
+
│ ├── schemas/
|
|
99
|
+
│ │ └── index.ts # Zod validation schemas
|
|
100
|
+
│ ├── services/
|
|
101
|
+
│ │ ├── database.service.ts # Singleton database service
|
|
102
|
+
│ │ ├── email.service.ts # Email service with Resend
|
|
103
|
+
│ │ └── jwt.service.ts # JWT utilities
|
|
104
|
+
│ ├── types/
|
|
105
|
+
│ │ ├── express.d.ts # Express type extensions
|
|
106
|
+
│ │ └── index.ts # Type definitions
|
|
107
|
+
│ ├── utils/
|
|
108
|
+
│ │ └── response.ts # API response utilities
|
|
109
|
+
│ └── views/
|
|
110
|
+
│ └── emails/ # HTML email templates
|
|
111
|
+
├── prisma/
|
|
112
|
+
│ └── schema.prisma # Database schema
|
|
113
|
+
├── .env.example # Environment variables template
|
|
114
|
+
├── .gitignore # Git ignore rules
|
|
115
|
+
├── .prettierrc # Prettier configuration
|
|
116
|
+
├── eslint.config.js # ESLint configuration
|
|
117
|
+
├── package.json # Dependencies and scripts
|
|
118
|
+
├── README.md # Project documentation
|
|
119
|
+
├── tsconfig.json # TypeScript configuration
|
|
120
|
+
└── vercel.json # Vercel deployment config
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 🔗 API Endpoints
|
|
124
|
+
|
|
125
|
+
### Authentication
|
|
126
|
+
| Method | Endpoint | Description |
|
|
127
|
+
|--------|----------|-------------|
|
|
128
|
+
| POST | `/api/auth/register` | Register new user |
|
|
129
|
+
| POST | `/api/auth/login` | User login |
|
|
130
|
+
| POST | `/api/auth/refresh` | Refresh access token |
|
|
131
|
+
| POST | `/api/auth/logout` | User logout |
|
|
132
|
+
| GET | `/api/auth/verify-email/:token` | Verify email address |
|
|
133
|
+
| POST | `/api/auth/resend-verification` | Resend verification email |
|
|
134
|
+
| POST | `/api/auth/forgot-password` | Request password reset |
|
|
135
|
+
| POST | `/api/auth/reset-password` | Reset password |
|
|
136
|
+
|
|
137
|
+
### User Profile
|
|
138
|
+
| Method | Endpoint | Description |
|
|
139
|
+
|--------|----------|-------------|
|
|
140
|
+
| GET | `/api/auth/profile` | Get user profile |
|
|
141
|
+
| PUT | `/api/auth/profile` | Update user profile |
|
|
142
|
+
| POST | `/api/auth/change-password` | Change password |
|
|
143
|
+
|
|
144
|
+
### Health & Status
|
|
145
|
+
| Method | Endpoint | Description |
|
|
146
|
+
|--------|----------|-------------|
|
|
147
|
+
| GET | `/health` | Basic health check |
|
|
148
|
+
| GET | `/api/health` | Detailed health with database status |
|
|
149
|
+
|
|
150
|
+
## 🛠️ Development Commands
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# Development
|
|
154
|
+
npm run dev # Start development server
|
|
155
|
+
npm run build # Build for production
|
|
156
|
+
npm start # Start production server
|
|
157
|
+
|
|
158
|
+
# Database
|
|
159
|
+
npm run db:generate # Generate Prisma client
|
|
160
|
+
npm run db:migrate # Run database migrations
|
|
161
|
+
npm run db:push # Push schema changes
|
|
162
|
+
npm run db:studio # Open Prisma Studio
|
|
163
|
+
npm run db:seed # Run database seeding
|
|
164
|
+
npm run db:reset # Reset database with seed
|
|
165
|
+
|
|
166
|
+
# Code Quality
|
|
167
|
+
npm run lint # Run ESLint
|
|
168
|
+
npm run lint:fix # Fix linting issues
|
|
169
|
+
npm run format # Format with Prettier
|
|
170
|
+
npm run type-check # TypeScript type checking
|
|
171
|
+
|
|
172
|
+
# Health Check
|
|
173
|
+
npm run health # Check API health
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## 📋 Prerequisites
|
|
177
|
+
|
|
178
|
+
- **Node.js** 18.0.0 or higher
|
|
179
|
+
- **npm** 8.0.0 or higher
|
|
180
|
+
- **PostgreSQL database** (recommend [Neon](https://neon.tech) for serverless)
|
|
181
|
+
- **Resend account** for email service (optional but recommended)
|
|
182
|
+
|
|
183
|
+
## 🔧 Environment Setup
|
|
184
|
+
|
|
185
|
+
After creating your project, you'll need to set up these services:
|
|
186
|
+
|
|
187
|
+
### 1. **Database Setup** (Neon PostgreSQL)
|
|
188
|
+
```bash
|
|
189
|
+
# 1. Sign up at neon.tech
|
|
190
|
+
# 2. Create a new database project
|
|
191
|
+
# 3. Copy connection strings from dashboard
|
|
192
|
+
# 4. Add to your .env file
|
|
193
|
+
|
|
194
|
+
DATABASE_URL="postgresql://user:password@host:port/db?sslmode=require"
|
|
195
|
+
DIRECT_URL="postgresql://user:password@host:port/db?sslmode=require"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 2. **Email Service** (Resend)
|
|
199
|
+
```bash
|
|
200
|
+
# 1. Sign up at resend.com
|
|
201
|
+
# 2. Create API key in dashboard
|
|
202
|
+
# 3. Add to your .env file
|
|
203
|
+
|
|
204
|
+
RESEND_API_KEY="re_your_api_key_here"
|
|
205
|
+
FROM_EMAIL="noreply@yourdomain.com"
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### 3. **JWT Secrets**
|
|
209
|
+
```bash
|
|
210
|
+
# Generate secure random strings
|
|
211
|
+
openssl rand -base64 32
|
|
212
|
+
|
|
213
|
+
JWT_SECRET="your-super-secure-jwt-secret"
|
|
214
|
+
JWT_REFRESH_SECRET="your-super-secure-refresh-secret"
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
### 4. **Complete .env Example**
|
|
218
|
+
Your `.env` file should look like this:
|
|
219
|
+
```bash
|
|
220
|
+
# Application
|
|
221
|
+
NODE_ENV=development
|
|
222
|
+
PORT=3001
|
|
223
|
+
FRONTEND_URL=http://localhost:3000
|
|
224
|
+
BACKEND_URL=http://localhost:3001
|
|
225
|
+
|
|
226
|
+
# Database (Neon PostgreSQL)
|
|
227
|
+
DATABASE_URL="postgresql://user:password@host:port/database?sslmode=require"
|
|
228
|
+
DIRECT_URL="postgresql://user:password@host:port/database?sslmode=require"
|
|
229
|
+
|
|
230
|
+
# JWT Configuration
|
|
231
|
+
JWT_SECRET="your-super-secure-jwt-secret-128-bits-minimum"
|
|
232
|
+
JWT_REFRESH_SECRET="your-super-secure-refresh-secret-128-bits-minimum"
|
|
233
|
+
JWT_EXPIRES_IN="15m"
|
|
234
|
+
JWT_REFRESH_EXPIRES_IN="7d"
|
|
235
|
+
|
|
236
|
+
# Email Service (Resend)
|
|
237
|
+
RESEND_API_KEY="re_xxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
238
|
+
FROM_EMAIL="noreply@yourdomain.com"
|
|
239
|
+
FROM_NAME="Your App Name"
|
|
240
|
+
|
|
241
|
+
# Security Settings
|
|
242
|
+
BCRYPT_SALT_ROUNDS=12
|
|
243
|
+
CORS_ORIGIN="http://localhost:3000,https://yourdomain.com"
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 📊 Database Models
|
|
247
|
+
|
|
248
|
+
The generated project includes these pre-configured models:
|
|
249
|
+
|
|
250
|
+
### **Core Authentication**
|
|
251
|
+
- **Users** - Complete user management with roles (USER, ADMIN, MODERATOR)
|
|
252
|
+
- **LoginLog** - Comprehensive audit trail for all authentication attempts
|
|
253
|
+
- **EmailVerification** - Secure email verification with token expiration
|
|
254
|
+
- **PasswordReset** - Secure password reset workflow
|
|
255
|
+
- **RefreshToken** - JWT refresh token management with revocation
|
|
256
|
+
|
|
257
|
+
### **Business Models** (Ready to extend)
|
|
258
|
+
- **Booking** - For appointment/reservation systems
|
|
259
|
+
- **Product** - For e-commerce applications
|
|
260
|
+
- **Blog** - For content management systems
|
|
261
|
+
- **Payment** - For payment processing integration
|
|
262
|
+
|
|
263
|
+
All models include proper relationships, indexes, and cascade deletes for data integrity.
|
|
264
|
+
|
|
265
|
+
## 🔐 Security Features
|
|
266
|
+
|
|
267
|
+
### **Authentication & Authorization**
|
|
268
|
+
- JWT-based authentication with access & refresh tokens
|
|
269
|
+
- Role-based access control (RBAC)
|
|
270
|
+
- Email verification workflow
|
|
271
|
+
- Secure password reset flow
|
|
272
|
+
- Session management with token revocation
|
|
273
|
+
|
|
274
|
+
### **Security Middleware**
|
|
275
|
+
- **Rate Limiting** - Multi-tier limits (general, auth, API)
|
|
276
|
+
- **CORS Protection** - Configurable origins and credentials
|
|
277
|
+
- **Helmet.js** - Comprehensive security headers
|
|
278
|
+
- **Input Sanitization** - XSS protection and data cleaning
|
|
279
|
+
- **Request Validation** - Zod-based schema validation
|
|
280
|
+
|
|
281
|
+
### **Monitoring & Auditing**
|
|
282
|
+
- Login attempt logging with IP and user agent tracking
|
|
283
|
+
- Failed login attempt monitoring
|
|
284
|
+
- Request logging with Winston
|
|
285
|
+
- Database connection health monitoring
|
|
286
|
+
|
|
287
|
+
### **Password Security**
|
|
288
|
+
- Bcrypt hashing with configurable salt rounds
|
|
289
|
+
- Password strength requirements
|
|
290
|
+
- Secure password reset tokens
|
|
291
|
+
- Account lockout protection
|
|
292
|
+
|
|
293
|
+
## 🚀 Deployment
|
|
294
|
+
|
|
295
|
+
### **Vercel Deployment** (Recommended)
|
|
296
|
+
|
|
297
|
+
The generated project includes Vercel configuration for seamless deployment:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
# 1. Push your code to GitHub
|
|
301
|
+
git add .
|
|
302
|
+
git commit -m "Initial commit"
|
|
303
|
+
git push origin main
|
|
304
|
+
|
|
305
|
+
# 2. Connect to Vercel
|
|
306
|
+
# - Go to vercel.com
|
|
307
|
+
# - Import your GitHub repository
|
|
308
|
+
# - Vercel will automatically detect the configuration
|
|
309
|
+
|
|
310
|
+
# 3. Set environment variables in Vercel dashboard
|
|
311
|
+
# All the variables from your .env file
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### **Production Environment Variables**
|
|
315
|
+
|
|
316
|
+
Set these in your Vercel dashboard (or hosting provider):
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
NODE_ENV=production
|
|
320
|
+
DATABASE_URL=your_neon_production_database_url
|
|
321
|
+
DIRECT_URL=your_neon_production_direct_url
|
|
322
|
+
JWT_SECRET=your_production_jwt_secret_128_bits
|
|
323
|
+
JWT_REFRESH_SECRET=your_production_refresh_secret_128_bits
|
|
324
|
+
RESEND_API_KEY=your_production_resend_api_key
|
|
325
|
+
FRONTEND_URL=https://yourdomain.com
|
|
326
|
+
BACKEND_URL=https://your-api.vercel.app
|
|
327
|
+
CORS_ORIGIN=https://yourdomain.com,https://www.yourdomain.com
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### **Other Deployment Options**
|
|
331
|
+
|
|
332
|
+
<details>
|
|
333
|
+
<summary>🐳 <strong>Docker Deployment</strong></summary>
|
|
334
|
+
|
|
335
|
+
```dockerfile
|
|
336
|
+
# Dockerfile will be generated in future versions
|
|
337
|
+
FROM node:18-alpine
|
|
338
|
+
WORKDIR /app
|
|
339
|
+
COPY package*.json ./
|
|
340
|
+
RUN npm ci --only=production
|
|
341
|
+
COPY . .
|
|
342
|
+
RUN npm run build
|
|
343
|
+
EXPOSE 3001
|
|
344
|
+
CMD ["npm", "start"]
|
|
345
|
+
```
|
|
346
|
+
</details>
|
|
347
|
+
|
|
348
|
+
<details>
|
|
349
|
+
<summary>☁️ <strong>Railway/Render Deployment</strong></summary>
|
|
350
|
+
|
|
351
|
+
1. Connect your GitHub repository
|
|
352
|
+
2. Set environment variables
|
|
353
|
+
3. Deploy automatically on push
|
|
354
|
+
</details>
|
|
355
|
+
|
|
356
|
+
## 🧪 Testing Your API
|
|
357
|
+
|
|
358
|
+
### **Health Check**
|
|
359
|
+
```bash
|
|
360
|
+
# Test basic health
|
|
361
|
+
curl http://localhost:3001/health
|
|
362
|
+
|
|
363
|
+
# Test database health
|
|
364
|
+
curl http://localhost:3001/api/health
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### **Authentication Flow**
|
|
368
|
+
```bash
|
|
369
|
+
# Register a new user
|
|
370
|
+
curl -X POST http://localhost:3001/api/auth/register \
|
|
371
|
+
-H "Content-Type: application/json" \
|
|
372
|
+
-d '{"email":"test@example.com","password":"password123","firstName":"John","lastName":"Doe"}'
|
|
373
|
+
|
|
374
|
+
# Login
|
|
375
|
+
curl -X POST http://localhost:3001/api/auth/login \
|
|
376
|
+
-H "Content-Type: application/json" \
|
|
377
|
+
-d '{"email":"test@example.com","password":"password123"}'
|
|
378
|
+
|
|
379
|
+
# Get profile (requires Bearer token)
|
|
380
|
+
curl -X GET http://localhost:3001/api/auth/profile \
|
|
381
|
+
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
## 📚 Usage Examples
|
|
385
|
+
|
|
386
|
+
### **Basic Express Server**
|
|
387
|
+
The generated `src/app.ts` provides a production-ready Express server:
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
import express from 'express';
|
|
391
|
+
import DatabaseService from './services/database.service';
|
|
392
|
+
import { middleware } from './middleware';
|
|
393
|
+
import routes from './routes';
|
|
394
|
+
|
|
395
|
+
const app = express();
|
|
396
|
+
const dbService = DatabaseService.getInstance();
|
|
397
|
+
|
|
398
|
+
// Apply security middleware
|
|
399
|
+
app.use(middleware.security);
|
|
400
|
+
app.use(middleware.cors);
|
|
401
|
+
app.use(middleware.rateLimit.general);
|
|
402
|
+
|
|
403
|
+
// API routes
|
|
404
|
+
app.use('/api', routes);
|
|
405
|
+
|
|
406
|
+
export default app;
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### **Adding Custom Routes**
|
|
410
|
+
```typescript
|
|
411
|
+
// src/routes/custom.routes.ts
|
|
412
|
+
import { Router } from 'express';
|
|
413
|
+
import { middleware } from '../middleware';
|
|
414
|
+
|
|
415
|
+
const router = Router();
|
|
416
|
+
|
|
417
|
+
// Protected route example
|
|
418
|
+
router.get('/protected',
|
|
419
|
+
middleware.auth.required,
|
|
420
|
+
(req, res) => {
|
|
421
|
+
res.json({ message: 'Hello authenticated user!' });
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
// Public route example
|
|
426
|
+
router.get('/public', (req, res) => {
|
|
427
|
+
res.json({ message: 'Hello world!' });
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
export default router;
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
### **Database Queries**
|
|
434
|
+
```typescript
|
|
435
|
+
// Using the database service
|
|
436
|
+
import DatabaseService from '../services/database.service';
|
|
437
|
+
|
|
438
|
+
const dbService = DatabaseService.getInstance();
|
|
439
|
+
const prisma = dbService.getClient();
|
|
440
|
+
|
|
441
|
+
// Example: Get all users
|
|
442
|
+
const users = await prisma.user.findMany({
|
|
443
|
+
select: {
|
|
444
|
+
id: true,
|
|
445
|
+
email: true,
|
|
446
|
+
firstName: true,
|
|
447
|
+
lastName: true,
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
// Example: Create a booking
|
|
452
|
+
const booking = await prisma.booking.create({
|
|
453
|
+
data: {
|
|
454
|
+
userId: user.id,
|
|
455
|
+
title: 'Meeting',
|
|
456
|
+
startDate: new Date(),
|
|
457
|
+
endDate: new Date(Date.now() + 3600000), // 1 hour later
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## 🤝 Contributing
|
|
463
|
+
|
|
464
|
+
We welcome contributions! Here's how you can help:
|
|
465
|
+
|
|
466
|
+
### **Reporting Issues**
|
|
467
|
+
- Use GitHub Issues for bug reports
|
|
468
|
+
- Include steps to reproduce
|
|
469
|
+
- Provide environment details
|
|
470
|
+
|
|
471
|
+
### **Feature Requests**
|
|
472
|
+
- Open a GitHub Issue with the "enhancement" label
|
|
473
|
+
- Describe the use case and expected behavior
|
|
474
|
+
|
|
475
|
+
### **Pull Requests**
|
|
476
|
+
1. Fork the repository
|
|
477
|
+
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
478
|
+
3. Make your changes
|
|
479
|
+
4. Add tests if applicable
|
|
480
|
+
5. Commit: `git commit -m 'Add amazing feature'`
|
|
481
|
+
6. Push: `git push origin feature/amazing-feature`
|
|
482
|
+
7. Open a Pull Request
|
|
483
|
+
|
|
484
|
+
## 📄 License
|
|
485
|
+
|
|
486
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
487
|
+
|
|
488
|
+
## 🙏 Acknowledgments
|
|
489
|
+
|
|
490
|
+
- **Express.js** team for the excellent web framework
|
|
491
|
+
- **Prisma** team for the amazing ORM and type safety
|
|
492
|
+
- **Resend** team for the modern email API
|
|
493
|
+
- **Neon** team for serverless PostgreSQL
|
|
494
|
+
- **Vercel** team for seamless deployment platform
|
|
495
|
+
- All the **open-source contributors** who made this possible
|
|
496
|
+
|
|
497
|
+
## ❓ FAQ
|
|
498
|
+
|
|
499
|
+
<details>
|
|
500
|
+
<summary><strong>Can I use this with a different database?</strong></summary>
|
|
501
|
+
|
|
502
|
+
Yes! While optimized for PostgreSQL, you can modify the Prisma schema to use MySQL, SQLite, or MongoDB. Update the `datasource` in `prisma/schema.prisma`.
|
|
503
|
+
</details>
|
|
504
|
+
|
|
505
|
+
<details>
|
|
506
|
+
<summary><strong>Can I use a different email provider?</strong></summary>
|
|
507
|
+
|
|
508
|
+
Absolutely! The email service is modular. You can replace Resend with SendGrid, AWS SES, or any other provider by modifying `src/services/email.service.ts`.
|
|
509
|
+
</details>
|
|
510
|
+
|
|
511
|
+
<details>
|
|
512
|
+
<summary><strong>How do I add more authentication providers?</strong></summary>
|
|
513
|
+
|
|
514
|
+
The architecture supports multiple auth providers. You can extend the `LoginType` enum in the Prisma schema and add OAuth routes in the auth controller.
|
|
515
|
+
</details>
|
|
516
|
+
|
|
517
|
+
<details>
|
|
518
|
+
<summary><strong>Is this production-ready?</strong></summary>
|
|
519
|
+
|
|
520
|
+
Yes! The boilerplate includes production-ready features like security middleware, error handling, logging, health checks, and deployment configurations.
|
|
521
|
+
</details>
|
|
522
|
+
|
|
523
|
+
---
|
|
524
|
+
|
|
525
|
+
<div align="center">
|
|
526
|
+
|
|
527
|
+
**Built with ❤️ by [Zafer Gök](https://github.com/zzafergok)**
|
|
528
|
+
|
|
529
|
+
If this project helped you, please give it a ⭐️ on GitHub!
|
|
530
|
+
|
|
531
|
+
[](https://github.com/zzafergok/arktos)
|
|
532
|
+
|
|
533
|
+
</div>
|