-
Notifications
You must be signed in to change notification settings - Fork 0
Development Guide
Thant Htoo Aung edited this page Feb 23, 2026
·
1 revision
Guidelines for developing and contributing to the DevCom Social Media API.
- Node.js 20.x
- MongoDB 7.0
- Git
- VS Code (recommended) or your preferred IDE
# Clone repository
git clone https://github.com/your-username/DevCom_Node.git
cd DevCom_Node
# Install dependencies
npm install
# Copy environment file
cp .env.example .env
# Start MongoDB (using Docker)
docker-compose up -d mongodb
# Start development server
npm run dev- Create Module Structure
src/modules/new-feature/
├── new-feature.controller.ts
├── new-feature.service.ts
├── new-feature.repository.ts
├── new-feature.dto.ts
└── new-feature.routes.ts
- Create Model (if needed)
src/database/models/NewFeature.model.ts
- Add Routes
Update src/routes/index.ts:
import newFeatureRoutes from "../modules/new-feature/new-feature.routes";
router.use("/new-feature", newFeatureRoutes);- Use TypeScript for all new code
- Avoid
anytypes - use proper types orunknown - Use interfaces for object shapes
- Prefer
constoverlet
-
Files:
kebab-case.ts(e.g.,user-profile.controller.ts) -
Classes:
PascalCase(e.g.,UserController) -
Functions/Methods:
camelCase(e.g.,getUserProfile) -
Constants:
UPPER_SNAKE_CASE(e.g.,MAX_RETRY_COUNT) -
Interfaces:
Iprefix (e.g.,IUser)
// 1. Imports (external first, then internal)
import express from "express";
import { AppError } from "../../common/exceptions/AppError";
// 2. Interfaces/Types
interface MyInterface {
// ...
}
// 3. Constants
const CONSTANT = "value";
// 4. Class/Function
export class MyClass {
// ...
}Always use asyncHandler for async route handlers:
import { asyncHandler } from "../../common/utils/asyncHandler";
export class MyController {
myMethod = asyncHandler(async (req: Request, res: Response) => {
// Your code here
});
}Use Zod schemas for validation:
import { z } from "zod";
export const createSchema = z.object({
name: z.string().min(1, "Name is required"),
email: z.string().email("Invalid email"),
});
export type CreateDTO = z.infer<typeof createSchema>;npm test- Unit tests for services
- Integration tests for API endpoints
- Test coverage should be > 80%
-
feature/feature-name- New features -
bugfix/bug-name- Bug fixes -
hotfix/issue-name- Critical fixes -
refactor/refactor-name- Code refactoring
Follow conventional commits:
feat: add user profile update endpoint
fix: resolve authentication token expiration issue
docs: update API documentation
refactor: improve error handling in services
test: add unit tests for user service
- Create a feature branch
- Make your changes
- Write/update tests
- Update documentation
- Create pull request
- Address review comments
- Merge after approval
- Code follows style guidelines
- All tests pass
- No TypeScript errors
- Documentation updated
- Error handling implemented
- Security considerations addressed
- Performance optimized (if applicable)
Set in .env:
NODE_ENV=developmentLogs are written to:
-
logs/error.log- Error logs -
logs/combined.log- All logs - Console output (development mode)
MongoDB Connection:
# Check MongoDB status
mongosh --eval "db.adminCommand('ping')"Port Already in Use:
# Find process using port 3000
lsof -i :3000
# Kill process
kill -9 <PID>- Database Indexes - Add indexes for frequently queried fields
- Pagination - Always paginate large datasets
- Caching - Consider Redis for frequently accessed data
-
Query Optimization - Use
select()to limit fields - Connection Pooling - MongoDB handles this automatically
-
Never commit secrets - Use
.envfile - Validate all inputs - Use Zod schemas
- Sanitize user input - Prevent injection attacks
- Use HTTPS - In production
- Rate limiting - Already implemented
- Password hashing - bcrypt with salt rounds
- Use JSDoc for public methods
- Explain "why" not "what"
- Keep comments up to date
- Update wiki when adding endpoints
- Include request/response examples
- Document error cases
Questions? Open an issue or contact the maintainers.