Welcome to the PUNTOSPOINT backend project, an e-commerce platform built with Ruby on Rails 3 and Ruby 1.9.3. This application provides robust APIs for managing products, categories, purchases, and audit logging while supporting detailed analytics and reporting.
The project was developed to fulfill the following objectives:
- Core Requirements:
- CRUD operations for Products, Categories, Customers, and Purchases.
- Associating Products with multiple Categories and adding Product Images.
- Audit logging for tracking Administrator actions (creation, updates, deletions).
- Sending emails for first product purchases and daily sales reports.
- JWT-based authentication for Administrators to access APIs securely.
- Technical Requirements:
- Fully optimized PostgreSQL database with associations.
- Redis caching for high-performance API responses.
- Sidekiq for background jobs (daily sales reporting and email notifications).
- JSON APIs documented with Swagger.
- Additional Features: • API response caching using Redis. • Comprehensive RSpec tests for API endpoints. • Modular and scalable code adhering to Rails best practices. • Entity-Relationship Diagram (ERD) for database structure.
- Language: Ruby 1.9.3
- Framework: Rails 3
- Database: PostgreSQL
- Caching: Redis
- Background Jobs: Sidekiq
- Testing: RSpec
- Containerization: Docker and Docker Compose
Pre-requisites
- Install Docker & Docker Compose
• Install Docker • Install Docker Compose
- Environment Variables
The project relies on environment variables defined in a
.env
file. Ensure you create this file at the root of the project with the following content:
DATABASE_HOST=db
DATABASE_USER=appuser
DATABASE_PASSWORD=password
DATABASE_NAME=appdb
REDIS_URL=redis://redis:6379/0
SMTP_ADDRESS=smtp.gmail.com
SMTP_PORT=587
SMTP_DOMAIN=gmail.com
[email protected]
SMTP_PASSWORD=dbrmzzrvfbmowmby
SMTP_AUTHENTICATION=plain
SMTP_ENABLE_STARTTLS_AUTO=true
JWT_SECRET=Llave&D1f1c1l_^D3_1div1n4r$
Steps to Run the Server / Services (Redis + Sidekiq + PostgreSQL)
- Clone the Repository
git clone <repository_url>
cd <repository_directory>
- Build and Start the Services
docker-compose build
docker-compose up
- [OPTIONAL] Run Database Migrations (just in case, migration are not applied automatically after the previous commands) Inside the running container, run:
docker-compose exec app rake db:create db:migrate
- Access the Application
The API server will be running at http://localhost:3000.
- Run the seeds
docker-compose exec app rake db:seed
- Run the Rspec test
docker-compose exec app rspec
- Login (JWT Token Generation):
POST /api/sessions
Request Body:
{
"email": "[email protected]",
"password": "password"
}
Response:
{
"token": "your_jwt_token_sha256"
}
Consider check the POSTMAN file to see the exported version of API calls for the 5 endpoints.
- Most Purchased Products by Category:
GET /api/products/most_purchased_by_category
Response: List of top products per category.
- Top Earning Products by Category:
GET /api/products/top_earning_by_category
Response: List of top 3 earning products per category.
• List Purchases:
• GET /api/purchases
• Filters:
• from (date)
• to (date)
• category_id (single or multiple)
• customer_id (single or multiple)
• admin_id (single or multiple)
• Purchase Count by Granularity:
• GET /api/purchases/count_by_granularity
• Parameters:
• granularity (hour, day, week, year)
Sales Report:
- Sends a daily report of purchases to administrators using Sidekiq with Excel file attached.
First Purchase Email:
- Sends an email to administrators when a product is purchased for the first time.
- Fully functional CRUD for Products, Categories, Purchases, and Customers from console.
- JWT-based authentication for secure access.
- Sidekiq for background jobs (email and reports).
- Redis for caching high-demand endpoints.
- Caching: Implemented with Redis for API optimization.
- Audit Logs: Tracks all actions (create, update, delete) performed by Administrators.
- API Documentation: Created with SwaggerDoc Gem.
- Test Coverage: Comprehensive RSpec tests.