Skip to content

Latest commit

Β 

History

62 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌱 Solidify Backend - SME Carbon Management Platform

A comprehensive Node.js/Express/MongoDB backend for helping Small and Medium Enterprises (SMEs) in Ghana achieve Net Zero Carbon Emissions.

πŸ“‹ Table of Contents

✨ Features

Core Features

  • πŸ” Authentication & Authorization - JWT-based auth with role-based access control
  • πŸ’¬ Real-time Chat - Socket.io powered messaging between SMEs
  • πŸ“š Knowledge Base - Educational resources on sustainability
  • πŸ“° News Section - Latest updates on carbon emissions and Net Zero
  • πŸ“Š Carbon Footprint Tracker - 3-level sustainability system with tracking

Additional Features

  • 🏒 Organization Management - Multi-tenant SME profiles
  • 🎯 Sustainability Roadmap - 6-milestone progress tracking
  • 🎯 Goal Setting - Set and track carbon reduction goals
  • πŸ“€ File Uploads - Cloudinary integration for images and documents
  • πŸ“§ Email Notifications - Gmail SMTP for transactional emails
  • πŸ“– API Documentation - Swagger/OpenAPI docs

πŸ›  Tech Stack

  • Runtime: Node.js with TypeScript
  • Framework: Express.js
  • Database: MongoDB (Atlas - FREE tier)
  • ODM: Mongoose
  • Real-time: Socket.io
  • Authentication: JWT (jsonwebtoken)
  • File Storage: Cloudinary (FREE tier)
  • Email: Nodemailer + Gmail SMTP (FREE)
  • Validation: Joi + express-validator
  • Security: Helmet, bcryptjs, express-mongo-sanitize
  • Logging: Winston
  • API Docs: Swagger

πŸ“ Project Structure

shopify-be/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ config/           # Configuration files
β”‚   β”‚   β”œβ”€β”€ database.ts
β”‚   β”‚   β”œβ”€β”€ environment.ts
β”‚   β”‚   └── cloudinary.ts
β”‚   β”œβ”€β”€ models/           # Mongoose models
β”‚   β”‚   β”œβ”€β”€ User.ts
β”‚   β”‚   β”œβ”€β”€ Organization.ts
β”‚   β”‚   β”œβ”€β”€ Conversation.ts
β”‚   β”‚   β”œβ”€β”€ Message.ts
β”‚   β”‚   β”œβ”€β”€ KnowledgeArticle.ts
β”‚   β”‚   β”œβ”€β”€ NewsArticle.ts
β”‚   β”‚   β”œβ”€β”€ CarbonEntry.ts
β”‚   β”‚   β”œβ”€β”€ EmissionFactor.ts
β”‚   β”‚   β”œβ”€β”€ SustainabilityRoadmap.ts
β”‚   β”‚   └── SustainabilityGoal.ts
β”‚   β”œβ”€β”€ controllers/      # Route controllers
β”‚   β”œβ”€β”€ routes/           # API routes
β”‚   β”œβ”€β”€ middleware/       # Custom middleware
β”‚   β”œβ”€β”€ services/         # Business logic
β”‚   β”œβ”€β”€ validators/       # Input validation
β”‚   β”œβ”€β”€ utils/            # Utility functions
β”‚   β”œβ”€β”€ sockets/          # Socket.io handlers
β”‚   β”œβ”€β”€ types/            # TypeScript types
β”‚   β”œβ”€β”€ swagger/          # API documentation
β”‚   β”œβ”€β”€ app.ts            # Express app setup
β”‚   └── server.ts         # Entry point
β”œβ”€β”€ tests/                # Test files
β”œβ”€β”€ logs/                 # Log files
β”œβ”€β”€ .env.example          # Environment template
β”œβ”€β”€ .gitignore
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ nodemon.json
└── README.md

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and npm
  • MongoDB Atlas account (FREE)
  • Cloudinary account (FREE)
  • Gmail account with App Password

Installation

  1. Clone the repository
git clone <your-repo-url>
cd shopify-be
  1. Install dependencies
npm install
  1. Setup environment variables
cp .env.example .env

Then edit .env with your credentials:

  • MongoDB Atlas connection string
  • JWT secrets (generate random strings)
  • Cloudinary credentials
  • Gmail SMTP credentials
  1. Build TypeScript
npm run build
  1. Run in development
npm run dev
  1. Run in production
npm start

πŸ”‘ Environment Variables

See .env.example for all required variables:

Required Services Setup

1. MongoDB Atlas (FREE)

  1. Go to https://www.mongodb.com/cloud/atlas/register
  2. Create FREE cluster (M0 tier)
  3. Create database user
  4. Whitelist IP: 0.0.0.0/0
  5. Get connection string

2. Cloudinary (FREE)

  1. Go to https://cloudinary.com/users/register/free
  2. Get Cloud Name, API Key, API Secret from dashboard

3. Gmail SMTP (FREE)

  1. Enable 2-Step Verification on Google Account
  2. Go to https://myaccount.google.com/apppasswords
  3. Generate App Password for "Mail"
  4. Use 16-digit password in .env

πŸ“š API Documentation

Once running, visit:

  • Swagger UI: http://localhost:5000/api-docs
  • API Base: http://localhost:5000/api/v1

Main Endpoints

Authentication

  • POST /api/v1/auth/register - Register new user
  • POST /api/v1/auth/login - Login
  • POST /api/v1/auth/logout - Logout
  • POST /api/v1/auth/refresh - Refresh token
  • PUT /api/v1/auth/change-password - Change password

Chat

  • GET /api/v1/chat/conversations - List conversations
  • POST /api/v1/chat/conversations - Create conversation
  • GET /api/v1/chat/conversations/:id/messages - Get messages
  • POST /api/v1/chat/messages - Send message
  • WebSocket: /socket.io - Real-time chat

Knowledge Base

  • GET /api/v1/knowledge/articles - List articles
  • GET /api/v1/knowledge/articles/:slug - Get article
  • POST /api/v1/knowledge/articles - Create article (admin)
  • GET /api/v1/knowledge/search?q=...&level=... - Search

News

  • GET /api/v1/news - List news
  • GET /api/v1/news/:slug - Get news article
  • POST /api/v1/news - Create news (admin)

Carbon Tracking

  • POST /api/v1/carbon/calculate - Calculate emissions
  • POST /api/v1/carbon/entries - Create entry
  • GET /api/v1/carbon/entries?level=... - List entries
  • GET /api/v1/carbon/dashboard - Dashboard stats
  • GET /api/v1/carbon/roadmap - Get roadmap

πŸ—„ Database Models

Core Models

  • User - User accounts with roles
  • Organization - SME company profiles
  • Conversation - Chat rooms
  • Message - Chat messages

Content Models

  • KnowledgeArticle - Educational content
  • NewsArticle - News posts

Carbon Models

  • CarbonEntry - Emission records
  • EmissionFactor - Calculation factors (Ghana-specific)
  • SustainabilityRoadmap - Progress tracking
  • SustainabilityGoal - Reduction targets

🌱 Sustainability Levels

The system uses a 3-level progression:

Level 1: Foundation & Measurement

  • Basic carbon footprint tracking
  • Initial data collection
  • Understanding emissions sources

Level 2: Efficiency & Integration

  • Implementing efficiency measures
  • Renewable energy integration
  • Advanced tracking

Level 3: Transformation & Net Zero Leadership

  • Complete transformation
  • Carbon offsetting
  • Net-zero achievement

🚒 Deployment

Deploy to Render.com (FREE)

  1. Push to GitHub
git init
git add .
git commit -m "Initial commit"
git remote add origin <your-repo>
git push -u origin main
  1. Create Render Web Service
  • Go to https://render.com
  • Connect GitHub repository
  • Set build command: npm run build
  • Set start command: npm start
  • Add environment variables from .env
  1. Deploy!
  • Auto-deploys on every push

Production URL

https://solidify-api.onrender.com

πŸ“ Scripts

npm run dev       # Development with nodemon
npm run build     # Build TypeScript
npm start         # Production server
npm test          # Run tests
npm run lint      # Lint code
npm run lint:fix  # Fix linting issues

πŸ”’ Security Features

  • JWT authentication with refresh tokens
  • Password hashing with bcrypt
  • Helmet for security headers
  • Rate limiting
  • MongoDB injection prevention
  • XSS protection
  • CORS configuration
  • Input validation

πŸ‘₯ User Roles

  • Admin - Full access, manage all content
  • Manager - Organization management, create content
  • User - View content, use chat, track emissions

πŸ“§ Contact

Author: Jehiel Britstot Houmanou Email: jehielbh@gmail.com Institution: Advanced School of Systems and Data Studies (ASSDAS) Supervisor: Mr Eugene Akoto

πŸ“„ License

MIT License - See LICENSE file

πŸ™ Acknowledgments

  • Ghana Enterprises Agency (GEA)
  • KNUST Net-Zero Carbon Emission Lab
  • SME Climate Hub
  • All participating Ghanaian SMEs

Built for the fight towards Net Zero Carbon Emissions by 2050 🌍

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages