- API Documentation: http://localhost:3000/api-docs
- Welcome Page: http://localhost:3000/
- Health Check: http://localhost:3000/api/v1/health
- Overview
- Key Features
- Tech Stack
- Architecture
- Quick Start
- API Endpoints
- Testing
- Deployment
- Project Structure
This project demonstrates a production-ready REST API for a farming marketplace platform. It showcases modern software development practices including:
- Microservices Architecture with clean separation of concerns
- TypeScript for type safety and better developer experience
- PostgreSQL with Sequelize ORM for robust data management
- JWT Authentication with secure token-based sessions
- File Upload with Cloudinary integration
- Real-time Notifications using Expo Push Notifications
- Payment Processing with Adwa payment gateway
- Comprehensive Testing with 80%+ code coverage
- Docker Containerization for consistent deployment
- CI/CD Pipeline with automated testing and deployment
- JWT-based authentication with refresh tokens
- Role-based access control (Farmers, Buyers, Admins)
- Input validation with Zod schemas
- Rate limiting and security middleware
- Password hashing with bcrypt
- Product catalog with search and filtering
- Order management system
- Secure payment processing
- User reviews and ratings
- Real-time order tracking
- Responsive web interface
- Push notifications for order updates
- File upload for product images
- User profile management
- Custom 404 error pages
- Comprehensive API documentation (Swagger/OpenAPI)
- Automated testing with Vitest
- Code quality tools (ESLint, Prettier)
- Hot reloading for development
- Detailed error logging
- Runtime: Node.js 20
- Language: TypeScript 5.0
- Framework: Express.js
- Database: PostgreSQL 15
- ORM: Sequelize with TypeScript
- Authentication: JWT + bcrypt
- Validation: Zod schemas
- File Upload: Multer + Cloudinary
- Testing Framework: Vitest
- HTTP Testing: Supertest
- Code Coverage: V8 Coverage
- Linting: ESLint
- Formatting: Prettier
- Containerization: Docker + Docker Compose
- CI/CD: GitHub Actions
- Database Migrations: Sequelize CLI
- Environment Management: dotenv
- Cloud Storage: Cloudinary
- Push Notifications: Expo
- Payment Gateway: Adwa
- Email Service: Nodemailer
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Client Apps β β Web Browser β β Mobile Apps β
βββββββββββ¬ββββββββ βββββββββββ¬ββββββββ βββββββββββ¬ββββββββ
β β β
ββββββββββββββββββββββββΌβββββββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β Express.js Server β
β (TypeScript + Node.js) β
βββββββββββββββ¬ββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β Business Logic Layer β
β (Controllers + Services) β
βββββββββββββββ¬ββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β Data Access Layer β
β (Sequelize + Models) β
βββββββββββββββ¬ββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β PostgreSQL DB β
βββββββββββββββββββββββββββββ
- Node.js 20+
- Docker & Docker Compose
- PostgreSQL (or use Docker)
git clone <repository-url>
cd farming-product-REST-api
yarn install
cp .env.example .env
# Edit .env with your configuration
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f app
# Stop services
docker-compose down
# Start database
docker-compose up db -d
# Run migrations
npx sequelize-cli db:migrate
# Start development server
yarn dev
POST /api/v1/auth/signup # User registration
POST /api/v1/auth/login # User login
POST /api/v1/auth/verifyOTP # OTP verification
GET /api/v1/products # Get all products
POST /api/v1/products # Create product (Farmers only)
GET /api/v1/products/:id # Get product by ID
PUT /api/v1/products/:id # Update product
DELETE /api/v1/products/:id # Delete product
POST /api/v1/orders # Create order
GET /api/v1/orders # Get user orders
POST /api/v1/payments # Process payment
GET /api/v1/users/profile # Get user profile
PUT /api/v1/users/profile # Update profile
POST /api/v1/users/upload-avatar # Upload profile picture
GET /api/v1/health # Health check with DB status
GET /api-docs # API documentation (Swagger)
yarn test # Run tests
yarn coverage # Generate coverage report
yarn vitest --ui # Interactive test UI
- Unit Tests: 80%+ coverage
- Integration Tests: API endpoints
- Mocking: External services (email, payments)
- Database: Test database with migrations
describe('Auth Controller', () => {
it('should create user and send OTP on successful signup', async () => {
const response = await request(app)
.post('/api/v1/auth/signup')
.send({
email: 'test@example.com',
password: 'password123',
role: 'farmer'
});
expect(response.status).toBe(201);
expect(response.body).toHaveProperty('message', 'User created successfully');
});
});
# Build and run
docker-compose up --build -d
# Production build
docker build -t farming-api .
docker run -p 3000:3000 farming-api
# Database
DATABASE_URL=postgresql://user:pass@host:5432/dbname
# JWT
JWT_SECRET=your_jwt_secret
JWT_SECRET_REFRESH=your_refresh_secret
# External Services
CLOUDINARY_CLOUD_NAME=your_cloud_name
ADWA_MERCHANT_KEY=your_merchant_key
farming-product-REST-api/
βββ src/
β βββ controllers/ # API controllers
β β βββ auth.controller.ts
β β βββ product.controller.ts
β β βββ user.controller.ts
β βββ middleware/ # Express middleware
β β βββ auth-check.ts
β β βββ errorHandler.ts
β β βββ rateLimiter.ts
β βββ models/ # Database models
β β βββ user.ts
β β βββ product.ts
β β βββ order.ts
β βββ routes/ # API routes
β β βββ auth.routes.ts
β β βββ product.routes.ts
β β βββ user.routes.ts
β βββ config/ # Configuration
β β βββ config.ts
β βββ utils/ # Utility functions
β βββ runMigrations.ts
βββ public/ # Static files
β βββ index.html # Welcome page
β βββ 404.html # Custom 404 page
β βββ assets/ # Static assets
β βββ styles.css
β βββ script.js
β βββ images/
βββ tests/ # Test files
β βββ controllers/
β βββ mocks/
β βββ setup.ts
βββ migrations/ # Database migrations
βββ docker-compose.yml # Docker services
βββ Dockerfile # Docker configuration
βββ README.md # This file
- Scalable Architecture: Designed for high-traffic e-commerce operations
- Security First: Implemented comprehensive security measures
- Developer Experience: Full CI/CD pipeline with automated testing
- Production Ready: Dockerized deployment with health monitoring
- Documentation: Complete API documentation with Swagger
- Code Quality: 80%+ test coverage with TypeScript
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Developed by Avom Brice
Full-Stack Developer | TypeScript | Node.js | React | DevOps
Ready to scale your e-commerce platform? This API demonstrates enterprise-level development practices with modern technologies and best practices.