Skip to content

Commit a08433b

Browse files
committed
chore: add warp.md file
1 parent 39400b4 commit a08433b

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

WARP.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# WARP.md
2+
3+
This file provides guidance to WARP (warp.dev) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
**Pizza Stars API Backend** - A TypeScript/Node.js backend for a pizza restaurant management system (TCC project) built with Fastify, Prisma ORM, and PostgreSQL. Features JWT authentication, role-based access control, and comprehensive CRUD operations for users, addresses, and future product/order management.
8+
9+
## Development Commands
10+
11+
### Core Development
12+
```bash
13+
# Development server with hot reload
14+
npm run dev
15+
16+
# Build for production
17+
npm run build
18+
19+
# Start production server
20+
npm start
21+
```
22+
23+
### Database Operations
24+
```bash
25+
# Start PostgreSQL container
26+
docker-compose up -d
27+
28+
# Run database migrations
29+
npx prisma migrate dev
30+
31+
# Seed database with sample data
32+
npx prisma db seed
33+
34+
# Open Prisma Studio (database GUI)
35+
npx prisma studio
36+
37+
# Reset database (drops all data)
38+
npx prisma migrate reset
39+
```
40+
41+
### Code Quality
42+
```bash
43+
# Run Biome linter
44+
npm run lint
45+
46+
# Fix linting issues automatically
47+
npx biome check --write
48+
49+
# Structured commit (uses commitlint)
50+
npm run commit
51+
```
52+
53+
## Architecture Overview
54+
55+
### High-Level Structure
56+
57+
The application follows a **layered architecture** with clear separation of concerns:
58+
59+
**Controllers****Services****Repositories****Database**
60+
61+
- **Controllers** (`src/http/controllers/`): Handle HTTP requests/responses, validation, error handling
62+
- **Services** (`src/services/`): Business logic, coordinating between repositories
63+
- **Repositories** (`src/repositories/`): Data access layer, abstracted database operations
64+
- **Factories** (`src/services/factories/`): Dependency injection pattern for service instantiation
65+
66+
### Key Architectural Patterns
67+
68+
1. **Repository Pattern**: Abstract database operations through interfaces (`UsersRepository`, `AddressRepository`)
69+
2. **Factory Pattern**: Service instantiation with proper dependency injection
70+
3. **Service Layer**: Encapsulate business logic separate from HTTP concerns
71+
4. **Middleware Chain**: JWT verification and role-based access control
72+
73+
### Authentication Flow
74+
75+
The app uses **JWT-based authentication** with refresh tokens:
76+
77+
- Access tokens expire in 10 minutes
78+
- Refresh tokens stored in HTTP-only cookies
79+
- Role-based access control (CUSTOMER, EMPLOYEE, ADMIN)
80+
- Custom middlewares: `verifyJWT`, `verifyUserRole`
81+
82+
### Database Schema Architecture
83+
84+
**Core Entities**:
85+
- **Users**: Authentication, profile data, roles
86+
- **Addresses**: User delivery addresses (1:1 with User)
87+
- **Products**: Pizzas, Drinks, Desserts with enum-based categorization
88+
- **Orders/Cart**: Many-to-many relationships with products
89+
90+
**Key Relationships**:
91+
- User ↔ Address (1:1)
92+
- User ↔ Cart (1:1)
93+
- User ↔ Orders (1:N)
94+
- Orders/Cart ↔ Products (N:N via implicit join tables)
95+
96+
## Development Notes
97+
98+
### Environment Setup
99+
100+
Required environment variables in `.env`:
101+
```env
102+
DATABASE_URL="postgresql://lucas:lucas123@localhost:5432/pizza-stars"
103+
PORT=3333
104+
NODE_ENV="dev"
105+
JWT_SECRET="your-secure-secret-key"
106+
GMAIL_USER="[email protected]"
107+
GMAIL_PASS="your-app-password"
108+
```
109+
110+
### Code Style Guidelines
111+
112+
- **Biome** enforces code style (no default exports, semicolon preferences, etc.)
113+
- **TypeScript strict mode** enabled
114+
- **Path aliases**: Use `@/*` for `src/*` imports
115+
- **Conventional commits** required via commitlint
116+
117+
### Error Handling Strategy
118+
119+
- **Custom Error Classes**: `UserAlreadyExistsError`, `InvalidCredentialsError`, etc.
120+
- **Global Error Handler**: Catches and formats errors appropriately
121+
- **Zod Validation**: Automatic request validation with detailed error responses
122+
- **Database Error Detection**: Handles connection issues gracefully
123+
124+
### Testing Considerations
125+
126+
- Services are designed for easy unit testing with dependency injection
127+
- Repository interfaces allow for easy mocking
128+
- Factory pattern enables swapping implementations for testing
129+
130+
### Deployment Configuration
131+
132+
- **Docker**: PostgreSQL container via docker-compose
133+
- **Build Tool**: tsup for fast TypeScript compilation
134+
- **Module System**: ESM modules (`"type": "module"`)
135+
- **Node.js Version**: Locked to Node.js 20 via Volta
136+
137+
## API Structure
138+
139+
Base URL: `http://localhost:3333/api`
140+
141+
### Authentication Endpoints
142+
- `POST /auth/login` - User authentication
143+
- `PATCH /auth/refresh` - Token refresh
144+
- `DELETE /auth/logout` - User logout (requires JWT)
145+
146+
### User Management
147+
- `POST /users` - User registration
148+
- `GET /user` - Get current user profile (requires JWT)
149+
- `PATCH /user` - Update user profile (requires JWT)
150+
- `DELETE /user` - Delete user account (requires JWT)
151+
- `GET /users` - List all users (requires ADMIN role)
152+
153+
### Address Management
154+
- Full CRUD operations for user addresses (all require JWT)
155+
156+
*Note: Product and order management APIs are planned but not yet implemented.*

0 commit comments

Comments
 (0)