Web Development Standards
This guide outlines our standards for web development, covering both frontend and backend practices.
Technology Stack
Frontend
Core Technologies
- Framework: Next.js
- Language: TypeScript
- Styling: Tailwind CSS
- State Management: React Query + Zustand
- Testing: Jest + React Testing Library
Backend
Core Technologies
- Framework: NestJS
- Language: TypeScript
- Database: PostgreSQL
- ORM: Prisma
- Testing: Jest
Architecture Standards
Frontend Architecture
graph TD
A[Pages] --> B[Components]
B --> C[Hooks]
C --> D[Services]
D --> E[API Client]
Project Structure
| Text Only |
|---|
| src/
├── components/ # Reusable UI components
│ ├── ui/ # Basic UI elements
│ └── features/ # Feature-specific components
├── hooks/ # Custom React hooks
├── lib/ # Utilities and helpers
├── pages/ # Next.js pages
├── services/ # API services
├── styles/ # Global styles
└── types/ # TypeScript definitions
|
Backend Architecture
graph TD
A[Controllers] --> B[Services]
B --> C[Repositories]
C --> D[Database]
Project Structure
| Text Only |
|---|
| src/
├── config/ # Configuration
├── core/ # Core modules
├── modules/ # Feature modules
├── shared/ # Shared resources
└── types/ # TypeScript definitions
|
Coding Standards
TypeScript Guidelines
| TypeScript |
|---|
| // Use interfaces for objects
interface User {
id: string;
name: string;
email: string;
role: UserRole;
}
// Use enums for fixed values
enum UserRole {
ADMIN = 'admin',
USER = 'user',
}
// Use type for unions/intersections
type UserResponse = User | Error;
|
React Guidelines
| TypeScript |
|---|
| // Functional components with TypeScript
interface Props {
user: User;
onUpdate: (user: User) => void;
}
const UserProfile: React.FC<Props> = ({ user, onUpdate }) => {
return (
<div>
<h1>{user.name}</h1>
{/* Component content */}
</div>
);
};
|
API Standards
RESTful Endpoints
| TypeScript |
|---|
| @Controller('users')
export class UsersController {
@Get()
findAll(): Promise<User[]> {
// Implementation
}
@Get(':id')
findOne(@Param('id') id: string): Promise<User> {
// Implementation
}
@Post()
create(@Body() createUserDto: CreateUserDto): Promise<User> {
// Implementation
}
}
|
| JSON |
|---|
| {
"data": {
"id": "123",
"name": "John Doe"
},
"meta": {
"timestamp": "2025-01-28T10:00:00Z"
},
"error": null
}
|
Testing Standards
Frontend Testing
| TypeScript |
|---|
| describe('UserProfile', () => {
it('renders user information', () => {
const user = {
id: '123',
name: 'John Doe',
email: 'john@example.com'
};
render(<UserProfile user={user} />);
expect(screen.getByText(user.name)).toBeInTheDocument();
});
});
|
Backend Testing
| TypeScript |
|---|
| describe('UsersService', () => {
it('should create a user', async () => {
const dto = {
name: 'John Doe',
email: 'john@example.com'
};
const user = await service.create(dto);
expect(user.name).toBe(dto.name);
});
});
|
- Lighthouse score > 90
- First Contentful Paint < 1.5s
- Time to Interactive < 3.5s
- Bundle size < 200KB (initial)
- API response time < 100ms
- Database queries < 50ms
- Memory usage < 512MB
- CPU usage < 70%
Security Standards
Frontend Security
- HTTPS only
- CSP headers
- XSS prevention
- CSRF protection
- Secure cookie handling
Backend Security
- Input validation
- Request rate limiting
- JWT authentication
- Role-based access
- Data encryption
Documentation Requirements
API Documentation
| TypeScript |
|---|
| /**
* Create a new user
* @param createUserDto - User creation data
* @returns Newly created user
* @throws ValidationError if data is invalid
*/
@Post()
@ApiOperation({ summary: 'Create user' })
@ApiResponse({ status: 201, type: User })
create(@Body() createUserDto: CreateUserDto): Promise<User> {
return this.usersService.create(createUserDto);
}
|
Component Documentation
| TypeScript |
|---|
| /**
* UserProfile component displays user information
* @param user - User object containing profile data
* @param onUpdate - Callback function when profile is updated
* @example
* <UserProfile user={userData} onUpdate={handleUpdate} />
*/
const UserProfile: React.FC<Props> = ...
|
Deployment Standards
Frontend Deployment
- Build optimization
- CDN usage
- Cache strategies
- Environment configuration
- Health monitoring
Backend Deployment
- Container orchestration
- Database migrations
- Environment secrets
- Logging setup
- Monitoring configuration
Quality Checklist
Frontend Checklist
Backend Checklist
- VS Code + Extensions
- Chrome DevTools
- Postman/Insomnia
- Docker
- Git
- Sentry
- DataDog
- Grafana
- Prometheus
- ELK Stack
Remember to follow these standards for all web development projects. Standards are regularly updated - check back for changes.