Skip to content

akvo/science-for-africa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Science of Africa

πŸš€ Quick Start

Development Mode

# Start all services
docker compose up

# Access your application:
# - Frontend: http://localhost:3000
# - Strapi Admin: http://localhost:1337/admin
# - Database Admin: http://localhost:5050
# - Mail Server: http://localhost:8025

Production Simulation

# Build and run production-like environment
docker compose -f compose.mimic-prod.yml up --build

# Access via Nginx reverse proxy:
# - Application: http://localhost
# - CMS: http://localhost/cms

πŸ“ Project Structure

${PROJECT_DIR}/
β”œβ”€β”€ backend/                    # Strapi CMS
β”‚   β”œβ”€β”€ __tests__/             # Backend test files
β”‚   β”‚   β”œβ”€β”€ helpers/           # Test utilities
β”‚   β”‚   β”œβ”€β”€ api/               # API endpoint tests
β”‚   β”‚   β”œβ”€β”€ controllers/       # Controller tests
β”‚   β”‚   └── models/            # Model/Service tests
β”‚   β”œβ”€β”€ config/                # Strapi configuration
β”‚   β”œβ”€β”€ src/                   # API routes and controllers
β”‚   β”œβ”€β”€ scripts/               # Startup and utility scripts
β”‚   β”œβ”€β”€ jest.config.js         # Jest configuration
β”‚   β”œβ”€β”€ Dockerfile             # Production build
β”‚   └── Dockerfile-dev         # Development build
β”œβ”€β”€ frontend/                  # Next.js Application
β”‚   β”œβ”€β”€ __tests__/             # Frontend test files
β”‚   β”‚   β”œβ”€β”€ components/        # Component tests
β”‚   β”‚   β”œβ”€β”€ lib/               # Utility tests
β”‚   β”‚   β”œβ”€β”€ pages/             # Page tests
β”‚   β”‚   └── __snapshots__/     # Jest snapshots
β”‚   β”œβ”€β”€ src/                   # Application source code
β”‚   β”œβ”€β”€ jest.config.js         # Jest configuration
β”‚   β”œβ”€β”€ jest.setup.js          # Jest setup file
β”‚   β”œβ”€β”€ Dockerfile             # Production build
β”‚   └── docker-entrypoint.sh   # Runtime environment injection
β”œβ”€β”€ nginx/                     # Nginx reverse proxy
β”‚   └── conf.d/                # Nginx configuration
β”œβ”€β”€ db/                        # Database initialization
β”‚   └── docker-entrypoint-initdb.d/
β”œβ”€β”€ pgadmin4/                  # Database administration
β”œβ”€β”€ TESTING.md                 # Testing documentation
β”œβ”€β”€ compose.yml                # Development environment
└── compose.mimic-prod.yml     # Production simulation

πŸ”§ Development

Services Overview

Service Port Description
Frontend 3000 Next.js development server
Backend 1337 Strapi CMS with hot reload
Database 5432 PostgreSQL with persistent storage
PgAdmin 5050 Database administration interface
Mailpit 8025 Email testing and preview

Backend (Strapi)

Frontend (Next.js)

  • URL: http://localhost:3000
  • Hot Reload: Enabled with fast refresh
  • API Proxy: Configured to backend
  • Environment Variables: Runtime injection

Database (PostgreSQL)

  • Host: localhost:5432
  • Database: ${PROJECT_DIR}
  • Username: akvo
  • Password: password
  • Admin Interface: http://localhost:5050

Email Testing (Mailpit)

πŸ“¦ Available Commands

Development

# Start development environment
docker compose up

# View logs
docker compose logs -f [service_name]

# Rebuild specific service
docker compose up --build [service_name]

# Stop all services
docker compose down

# Reset database (destructive)
docker compose down -v

Production Simulation

# Build and start production environment
docker compose -f compose.mimic-prod.yml up --build

# Scale services
docker compose -f compose.mimic-prod.yml up --scale frontend=2

# View production logs
docker compose -f compose.mimic-prod.yml logs

Database Operations

# Access database directly
docker compose exec db psql -U akvo -d ${PROJECT_DIR}

# Backup database
docker compose exec db pg_dump -U akvo ${PROJECT_DIR} > backup.sql

# Restore database
cat backup.sql | docker compose exec -T db psql -U akvo -d ${PROJECT_DIR}

πŸ› οΈ Configuration

Environment Variables

Backend Configuration

  • DATABASE_*: PostgreSQL connection settings
  • JWT_SECRET: Authentication token secret
  • APP_KEYS: Strapi application keys
  • SMTP_*: Email server configuration
  • GCS_*: Google Cloud Storage (optional)

Frontend Configuration

  • NEXT_PUBLIC_BACKEND_URL: API endpoint URL
  • NEXT_TELEMETRY_DISABLED: Disable Next.js telemetry

Email Configuration

The setup includes Mailpit for email testing:

  • SMTP server runs on port 1025
  • Web interface available at http://localhost:8025
  • All emails are captured and can be viewed in the interface

🚒 Deployment

Production Checklist

  • Update all environment variables with production values
  • Configure SSL certificates in Nginx
  • Set up proper database credentials
  • Configure external storage (GCS/S3) for file uploads
  • Set up monitoring and logging
  • Configure backup strategies

Environment-Specific Builds

# Build production images
docker build -t ${PROJECT_DIR}-backend ./backend
docker build -t ${PROJECT_DIR}-frontend ./frontend
docker build -t ${PROJECT_DIR}-nginx ./nginx

# Push to registry
docker tag ${PROJECT_DIR}-backend your-registry/${PROJECT_DIR}-backend:latest
docker push your-registry/${PROJECT_DIR}-backend:latest

πŸ” Security Considerations

Development

  • Default credentials are used for convenience
  • All services are exposed on localhost
  • Debug mode is enabled

Production

  • Change all default passwords and secrets
  • Use environment variables for sensitive data
  • Implement proper SSL/TLS
  • Configure firewall rules
  • Enable audit logging

πŸ§ͺ Testing

This project includes comprehensive testing infrastructure for both backend and frontend.

Quick Start

# Run all backend tests
cd backend && npm test

# Run all frontend tests
cd frontend && npm test

# Run tests in Docker
docker compose exec backend npm test
docker compose exec frontend npm test

Backend Testing (Jest + Supertest)

Test Scripts:

npm test              # Run all tests
npm run test:watch    # Run tests in watch mode
npm run test:coverage # Generate coverage report
npm run test:ci       # Run tests in CI mode

Test Structure:

backend/__tests__/
β”œβ”€β”€ helpers/
β”‚   β”œβ”€β”€ setup.js      # Test environment setup
β”‚   └── strapi.js     # Strapi test utilities
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ health.test.js   # API endpoint tests
β”‚   └── auth.test.js     # Authentication tests
β”œβ”€β”€ controllers/
β”‚   └── example.test.js  # Controller tests
└── models/
    └── example.test.js  # Model/Service tests

Example Test:

const request = require('supertest');
const { setupStrapi, getStrapi } = require('../helpers/strapi');

describe('API Endpoint', () => {
  beforeAll(async () => await setupStrapi());

  it('should return data', async () => {
    const strapi = getStrapi();
    const response = await request(strapi.server.httpServer)
      .get('/api/your-endpoint')
      .expect(200);
    expect(response.body.data).toBeDefined();
  });
});

Frontend Testing (Jest + React Testing Library)

Test Scripts:

npm test              # Run all tests
npm run test:watch    # Run tests in watch mode
npm run test:coverage # Generate coverage report
npm run test:update   # Update snapshots
npm run test:ci       # Run tests in CI mode

Test Structure:

frontend/__tests__/
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ Button.test.jsx        # Component unit tests
β”‚   β”œβ”€β”€ Card.snapshot.test.jsx # Snapshot tests
β”‚   └── Form.interaction.test.jsx # Interaction tests
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ strapi.test.js         # Utility function tests
β”‚   └── test-utils.jsx         # Custom test utilities
└── pages/
    └── Home.test.jsx          # Page component tests

Test Types Included:

  • Unit Tests: Test individual components and functions
  • Interaction Tests: Test user interactions with @testing-library/user-event
  • Snapshot Tests: Catch unintended UI changes

Example Test:

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

describe('Button', () => {
  it('calls onClick when clicked', async () => {
    const handleClick = jest.fn();
    const user = userEvent.setup();

    render(<Button onClick={handleClick}>Click me</Button>);
    await user.click(screen.getByText('Click me'));

    expect(handleClick).toHaveBeenCalled();
  });
});

Coverage Reports

After running `npm run test:coverage`, view reports at:

  • Backend: `backend/coverage/lcov-report/index.html`
  • Frontend: `frontend/coverage/lcov-report/index.html`

CI/CD Integration

# Example GitHub Actions workflow
test:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
    - run: cd backend && npm ci && npm run test:ci
    - run: cd frontend && npm ci && npm run test:ci

For detailed testing documentation, see TESTING.md.

πŸ“š Documentation

Key Technologies

API Documentation

πŸ†˜ Troubleshooting

Common Issues

Port Conflicts

# Check for port usage
lsof -i :3000
lsof -i :1337
lsof -i :5432

# Kill processes if needed
npx kill-port 3000 1337 5432

Database Connection Issues

# Reset database
docker compose down -v
docker compose up db
# Wait for database to be ready, then start other services

Image Build Issues

# Clean Docker cache
docker system prune -f
docker builder prune -f

# Rebuild without cache
docker compose build --no-cache

Permission Issues

# Fix file permissions (if needed)
sudo chown -R $USER:$USER .

Logs and Debugging

# View all logs
docker compose logs

# Follow specific service logs
docker compose logs -f backend
docker compose logs -f frontend

# Debug mode
DEBUG=* docker compose up

🀝 Contributing

Development Workflow

  1. Make changes to source code
  2. Test locally with docker compose up
  3. Verify production build with docker compose -f compose.mimic-prod.yml up
  4. Submit pull request

Code Style

  • Backend: Follow Strapi conventions
  • Frontend: Use Prettier and ESLint
  • Commit messages: Follow conventional commits

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


🎯 Next Steps

  1. Content Modeling: Create your content types in Strapi admin
  2. Frontend Development: Build your pages and components
  3. API Integration: Connect frontend to Strapi API
  4. Authentication: Implement user authentication if needed
  5. Deployment: Configure production environment

Happy coding! πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •