A robust Java backend application built with Spring Boot for the GreenCode project - an innovative platform focused on sustainable development and environmental initiatives.
GreenCode is a full-stack system designed to support environmental, sustainability, and community-impact projects under Bos-Com.
It consists of a Spring Boot backend API and a React frontend (new addition), with future integrations planned.
GreenCode is a comprehensive backend system designed to support environmental sustainability projects, green technology initiatives, and eco-friendly business operations. The platform provides robust APIs for managing environmental data, user authentication, and sustainable development metrics.
-
RESTful API
-
JWT/OAuth authentication
-
PostgreSQL database support
-
Centralised configuration (
config/,.env) -
Dockerized for easy deployment
-
Swagger/OpenAPI documentation
-
Java 17 - Modern Java with latest features
-
Spring Boot 3.2.0 - Rapid application development framework
-
Spring Security - Authentication and authorization
-
Spring Data JPA - Data persistence layer
-
H2 Database - In-memory database for development
-
PostgreSQL - Production database support
-
Maven - Dependency management and build tool
-
JWT - JSON Web Token authentication
-
Swagger/OpenAPI - API documentation
-
Spring Actuator - Application monitoring and metrics
- Modern React (Create React App)
- React Router for navigation
- Axios for API communication
- Authentication UI (login, password reset flow)
- Responsive UI with Tailwind CSS (recommended)
- Ready to connect to backend reset API
- Java 17 or higher
- Maven 3.8 or higher
- Node.js 16 or higher (for frontend)
- PostgreSQL 13 or higher
- Docker & Docker Compose (optional, recommended)
-
Clone the repository
git clone https://github.com/MarlonPiusMulamba/GreenCode.git cd GreenCode -
Start all services with Docker Compose
# Build and start all services docker-compose up -d # Check service status docker-compose ps
-
Access the applications
- Backend API: http://localhost:8080
- Frontend: http://localhost:3000
- API Docs: http://localhost:8080/swagger-ui.html
-
Navigate to project root
cd GreenCode -
Set up database
# Create PostgreSQL database createdb greencode # Or use psql psql -c "CREATE DATABASE greencode;"
-
Configure environment variables
# Copy environment template cp config/.env.example config/.env # Edit config/.env with your settings # Database URL, JWT secret, etc.
-
Build and run the backend
# Using Maven mvn clean install mvn spring-boot:run # Or using the Maven wrapper ./mvnw clean install ./mvnw spring-boot:run
-
Run database migrations
# Flyway migrations run automatically on startup # Or run manually: mvn flyway:migrate
-
Navigate to frontend directory
cd greencode-frontend -
Install dependencies
npm install # OR yarn install -
Set up environment variables
# Create environment file cp .env.example .env.local # Edit .env.local with backend URL REACT_APP_API_URL=http://localhost:8080/api
-
Start the development server
npm start # OR yarn start -
Access the frontend Open http://localhost:3000 in your browser
Once the backend is running, visit:
- Swagger UI: http://localhost:8080/swagger-ui.html
- OpenAPI JSON: http://localhost:8080/v3/api-docs
| Category | Base Path | Description |
|---|---|---|
| Authentication | /api/auth |
Login, register, refresh tokens |
| Users | /api/users |
User management and profiles |
| Projects | /api/projects |
Environmental project management |
| Sustainability | /api/sustainability |
Sustainability metrics and tracking |
| Analytics | /api/analytics |
Data analytics and reporting |
| Files | /api/files |
File upload and management |
The API uses JWT-based authentication:
# Login
curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"your@email.com","password":"password"}'
# Use returned token in subsequent requests
curl -X GET http://localhost:8080/api/projects \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Create config/.env:
# Database Configuration
DB_URL=jdbc:postgresql://localhost:5432/greencode
DB_USERNAME=greencode_user
DB_PASSWORD=your_password
# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRATION=86400000
# Server Configuration
SERVER_PORT=8080
SERVER_HOST=localhost
# File Upload
UPLOAD_DIR=./uploads
MAX_FILE_SIZE=10485760
# Email Configuration (optional)
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USERNAME=your-email@gmail.com
EMAIL_PASSWORD=your-app-passwordCreate greencode-frontend/.env.local:
# API Configuration
REACT_APP_API_URL=http://localhost:8080/api
REACT_APP_API_TIMEOUT=10000
# Application Configuration
REACT_APP_NAME=GreenCode
REACT_APP_VERSION=1.0.0
# Feature Flags
REACT_APP_ENABLE_ANALYTICS=true
REACT_APP_ENABLE_UPLOADS=true# Run all tests
mvn test
# Run tests with coverage
mvn jacoco:report
# Run specific test class
mvn test -Dtest=ProjectServiceTest
# Run integration tests
mvn test -Dtest=**/*IntegrationTest# Navigate to frontend directory
cd greencode-frontend
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Run E2E tests
npm run test:e2e-
Build production images
docker-compose -f docker-compose.prod.yml build
-
Start production services
docker-compose -f docker-compose.prod.yml up -d
-
Health checks
# Check backend health curl http://localhost:8080/actuator/health # Check frontend curl http://localhost:3000
-
Build JAR file
mvn clean package -DskipTests
-
Run with production profile
java -jar target/greencode-1.0.0.jar --spring.profiles.active=prod
-
Build for production
cd greencode-frontend npm run build -
Deploy build artifacts
# Copy build directory to your web server cp -r build/* /var/www/html/
1. Database connection failed
# Check PostgreSQL status
pg_isready
# Check database exists
psql -l | grep greencode
# Test connection
psql -h localhost -U greencode_user -d greencode2. Port conflicts
# Check what's using port 8080
netstat -tulpn | grep :8080
# Kill process
kill -9 <PID>
# Or use different port
mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=80813. Frontend can't connect to backend
# Check backend is running
curl http://localhost:8080/actuator/health
# Check CORS configuration
# Ensure backend allows requests from http://localhost:30004. Maven build failures
# Clean Maven cache
mvn clean
# Force update dependencies
mvn clean install -U
# Check Java version
java -version5. Node.js issues
# Clear npm cache
npm cache clean --force
# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
# Check Node version
node --version # Should be 16+1. Container won't start
# Check logs
docker-compose logs backend
docker-compose logs frontend
# Rebuild containers
docker-compose down
docker-compose build --no-cache
docker-compose up -d2. Database connection in Docker
# Check database container
docker-compose exec db psql -U greencode_user -d greencode
# Restart database
docker-compose restart dbGreenCode/
βββ src/ # Spring Boot source code
β βββ main/
β β βββ java/com/greencode/
β β β βββ config/ # Security, database, CORS config
β β β βββ controller/ # REST API controllers
β β β βββ service/ # Business logic services
β β β βββ repository/ # JPA repositories
β β β βββ model/ # JPA entities
β β β βββ dto/ # Data transfer objects
β β β βββ util/ # Utility classes
β β βββ resources/
β β βββ application.yml # Spring configuration
β β βββ db/migration/ # Flyway migrations
β βββ test/ # Test classes
βββ config/ # External configuration
β βββ .env.example # Environment template
β βββ docker/ # Docker configurations
βββ docs/ # Documentation
β βββ api/ # API documentation
β βββ deployment/ # Deployment guides
βββ greencode-frontend/ # React frontend
β βββ public/ # Static assets
β βββ src/
β β βββ components/ # React components
β β βββ pages/ # Page components
β β βββ services/ # API services
β β βββ utils/ # Utility functions
β β βββ styles/ # CSS/SCSS files
β βββ package.json # Node.js dependencies
β βββ .env.example # Frontend env template
βββ target/ # Maven build output
βββ pom.xml # Maven build file
βββ docker-compose.yml # Development Docker setup
βββ docker-compose.prod.yml # Production Docker setup
βββ README.md # This file
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Commit your changes (
git commit -m 'feat: 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.