Files
SkyArtShop/backend/readme.md

110 lines
2.4 KiB
Markdown
Raw Normal View History

2026-01-01 22:24:30 -06:00
# SkyArtShop Backend
Production-ready Node.js + Express + TypeScript backend for Sky Art Shop.
## 🚀 Quick Start
```bash
# Install dependencies
npm install
# Set up database
npx prisma generate
npx prisma migrate dev
# Run development server
npm run dev
# Build for production
npm run build
# Run production server
npm start
```
## 📁 Project Structure
```
backend/
├── prisma/
│ └── schema.prisma # Database schema
├── src/
│ ├── @types/ # TypeScript definitions
│ ├── config/ # Configuration files
│ ├── controllers/ # Request handlers
│ ├── services/ # Business logic
│ ├── models/ # Data access layer
│ ├── routes/ # API route definitions
│ ├── middlewares/ # Express middleware
│ ├── validators/ # Request validation
│ ├── helpers/ # Utility functions
│ └── server.ts # Entry point
├── .env
├── tsconfig.json
└── package.json
```
## 🛠️ Tech Stack
- **Node.js** - Runtime
- **Express** - Web framework
- **TypeScript** - Type safety
- **Prisma** - ORM
- **PostgreSQL** - Database
- **JWT** - Authentication
- **Zod** - Validation
## 🔑 Environment Variables
Create a `.env` file:
```
PORT=3000
NODE_ENV=development
DATABASE_URL="postgresql://user:password@localhost:5432/skyartshop"
JWT_SECRET=your-secret-key
CORS_ORIGIN=http://localhost:5173
```
## 📝 Development Guidelines
### Folder Responsibilities
- **controllers/**: Handle HTTP requests and responses
- **services/**: Business logic and orchestration
- **models/**: Database queries (Prisma models)
- **routes/**: Define endpoints and apply middleware
- **middlewares/**: Authentication, validation, logging
- **validators/**: Zod schemas for request validation
- **helpers/**: Pure utility functions
### Adding a New Feature
1. Create model in `prisma/schema.prisma`
2. Run `npx prisma migrate dev`
3. Create service in `src/services/`
4. Create controller in `src/controllers/`
5. Add routes in `src/routes/`
6. Add validators in `src/validators/`
## 🔒 Security
- JWT authentication on protected routes
- Input validation with Zod
- Helmet for security headers
- CORS configured
- Rate limiting ready
## 📊 Database
```bash
# Generate Prisma Client
npx prisma generate
# Create migration
npx prisma migrate dev --name description
# Open Prisma Studio
npx prisma studio
```