Skip to content

Fullstack app (NextJS + NodeJS) deployement on ECS Fargate

Notifications You must be signed in to change notification settings

AKRAMSOUIDA/ECS_fullstack_app-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ ECS Fullstack Application

AWS Docker Node.js Next.js React Terraform

A production-ready fullstack application deployed on AWS ECS with enterprise-grade features

🌐 Live Demo β€’ πŸ“– Documentation β€’ πŸš€ Quick Start β€’ πŸ—οΈ Architecture


✨ Features

πŸ”₯ Modern Tech Stack

  • Backend: Node.js + Express.js API
  • Frontend: Next.js + React SPA
  • Infrastructure: Terraform IaC
  • Containerization: Docker & Docker Compose
  • Cloud: AWS ECS + ECR + ALB

πŸ›‘οΈ Enterprise Security

  • SSL/HTTPS encryption
  • CORS protection
  • Non-root containers
  • VPC network isolation
  • IAM roles and policies

⚑ Production Ready

  • Auto-scaling capabilities
  • Health check monitoring
  • Load balancer integration
  • CloudWatch logging
  • CI/CD pipeline with GitHub Actions

🎯 Developer Experience

  • Hot reload development
  • Multi-stage Docker builds
  • Infrastructure as Code
  • Automated deployments
  • PR checks and validation

πŸ—οΈ Architecture

graph TB
    subgraph "GitHub"
        REPO[Repository]
        ACTIONS[GitHub Actions<br/>CI/CD Pipeline]
    end
    
    subgraph "AWS Cloud"
        ALB[Application Load Balancer<br/>SSL/HTTPS]
        
        subgraph "ECS Cluster"
            API[Node.js API<br/>Port 3001]
            WEB[Next.js Frontend<br/>Port 3000]
        end
        
        subgraph "Container Registry"
            ECR1[ECR: API Image]
            ECR2[ECR: Frontend Image]
        end
        
        subgraph "Infrastructure"
            TF[Terraform State]
            IAM[IAM Roles]
            VPC[VPC & Networking]
        end
        
        CW[CloudWatch<br/>Logs & Monitoring]
    end
    
    USER[πŸ‘€ Users] --> ALB
    ALB --> API
    ALB --> WEB
    WEB --> API
    API --> CW
    WEB --> CW
    ECR1 --> API
    ECR2 --> WEB
    REPO --> ACTIONS
    ACTIONS --> ECR1
    ACTIONS --> ECR2
    ACTIONS --> TF
Loading

πŸš€ Quick Start

Prerequisites

  • Docker & Docker Compose
  • AWS CLI configured
  • Terraform (for infrastructure)
  • Node.js 18+ (optional for local dev)

🐳 Local Development

# Clone the repository
git clone https://github.com/AKRAMSOUIDA/ECS_fullstack_app-.git
cd ECS_fullstack_app-

# Start all services
docker compose up --build

# πŸŽ‰ Access your applications
# Frontend: http://localhost:3000
# API: http://localhost:3001

☁️ AWS Deployment

Option 1: Terraform (Recommended)

# Navigate to Terraform directory
cd Terraform

# Initialize Terraform
terraform init

# Plan deployment
terraform plan

# Deploy infrastructure
terraform apply

Option 2: GitHub Actions CI/CD

  1. Fork this repository
  2. Set up AWS credentials in GitHub Secrets
  3. Push to main branch - automatic deployment!

πŸ“ Project Structure

ECS_fullstack_app-/
β”œβ”€β”€ πŸ”§ api/                     # Node.js Express API
β”‚   β”œβ”€β”€ server.js              # Main server application
β”‚   β”œβ”€β”€ package.json           # Dependencies & scripts
β”‚   └── Dockerfile             # Container configuration
β”œβ”€β”€ 🎨 frontend/               # Next.js React App
β”‚   β”œβ”€β”€ pages/                 # Application pages
β”‚   β”œβ”€β”€ components/            # Reusable components
β”‚   β”œβ”€β”€ public/                # Static assets
β”‚   β”œβ”€β”€ package.json           # Dependencies & scripts
β”‚   └── Dockerfile             # Container configuration
β”œβ”€β”€ πŸ—οΈ Terraform/              # Infrastructure as Code
β”‚   β”œβ”€β”€ main.tf                # Main Terraform configuration
β”‚   β”œβ”€β”€ modules/               # Reusable Terraform modules
β”‚   β”‚   β”œβ”€β”€ ecr/              # Container registry
β”‚   β”‚   β”œβ”€β”€ ecs/              # Container orchestration
β”‚   β”‚   └── alb/              # Load balancer
β”‚   └── deploy.sh             # Deployment script
β”œβ”€β”€ πŸ”„ .github/workflows/      # CI/CD Pipelines
β”‚   β”œβ”€β”€ deploy.yml            # Deployment workflow
β”‚   β”œβ”€β”€ terraform.yml         # Infrastructure workflow
β”‚   └── pr-check.yml          # PR validation
β”œβ”€β”€ 🐳 docker-compose.yml      # Local development
β”œβ”€β”€ πŸ“‹ deployment-guide.md     # Deployment instructions
└── πŸ“– README.md              # You are here!

πŸ”Œ API Endpoints

Health Check

GET /health
{
  "status": "OK",
  "timestamp": "2025-06-27T08:00:00.000Z"
}

User Management

GET /api/users          # Get all users
POST /api/users         # Create new user

Example Response:

[
  {
    "id": 1,
    "name": "John Doe",
    "email": "john@example.com"
  }
]

πŸ› οΈ Technology Stack

πŸ”™ Backend

  • Runtime: Node.js 18+
  • Framework: Express.js
  • Features: REST API, CORS, Health Checks
  • Container: Alpine Linux

🎨 Frontend

  • Framework: Next.js 14
  • Library: React 18
  • Features: SSR, API Routes, Responsive
  • Build: Production optimized

☁️ Infrastructure

  • Compute: AWS ECS Fargate
  • Registry: Amazon ECR
  • Load Balancer: Application LB
  • IaC: Terraform
  • Monitoring: CloudWatch

πŸ”„ DevOps

  • CI/CD: GitHub Actions
  • Container: Docker
  • Orchestration: Docker Compose
  • Automation: Terraform

πŸ”§ Configuration

Environment Variables

Variable Description Default
NODE_ENV Environment mode development
PORT Server port 3001
NEXT_PUBLIC_API_URL API endpoint URL http://localhost:3001
AWS_REGION AWS deployment region us-east-1

GitHub Secrets (for CI/CD)

Secret Description
AWS_ACCESS_KEY_ID AWS access key
AWS_SECRET_ACCESS_KEY AWS secret key
AWS_REGION AWS region

πŸ“Š Performance & Monitoring

🎯 Optimizations

  • Container: Multi-stage Docker builds
  • Frontend: Static generation & code splitting
  • Caching: Efficient Docker layer caching
  • Resources: Proper CPU/memory limits
  • Auto-scaling: Based on CPU/memory metrics

πŸ“ˆ Monitoring

  • Health Checks: Container & application level
  • Logging: Structured JSON logs to CloudWatch
  • Metrics: CPU, memory, and custom metrics
  • Alerts: Automated monitoring alerts
  • Dashboards: CloudWatch dashboards

πŸš€ Deployment Options

Method Use Case Complexity Features
Terraform Production IaC Medium Full control, versioning
GitHub Actions Automated CI/CD Low Auto-deployment
Manual ECS Learning/Testing High Step-by-step control

πŸ›‘οΈ Security Features

  • πŸ”’ SSL/HTTPS: End-to-end encryption with ACM certificates
  • 🌐 CORS: Proper cross-origin handling
  • 🐳 Container Security: Non-root users, minimal images
  • πŸ” Environment Variables: Secure config management
  • 🏠 VPC: Isolated network environment
  • πŸ‘€ IAM: Least privilege access policies
  • ↩️ HTTP Redirect: Automatic HTTPS redirect
  • πŸ” Security Groups: Network-level firewall rules

πŸ”„ CI/CD Pipeline

GitHub Actions Workflows

  1. PR Checks (pr-check.yml)

    • Code linting and testing
    • Docker build validation
    • Security scanning
  2. Terraform (terraform.yml)

    • Infrastructure validation
    • Plan and apply changes
    • State management
  3. Deployment (deploy.yml)

    • Build and push Docker images
    • Deploy to ECS
    • Health check validation

πŸ“š Documentation


🀝 Contributing

We welcome contributions! Here's how to get started:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’» Make your changes
  4. πŸ§ͺ Test locally with docker compose up
  5. πŸ“ Commit your changes (git commit -m 'Add amazing feature')
  6. πŸš€ Push to the branch (git push origin feature/amazing-feature)
  7. 🎯 Open a Pull Request

Development Guidelines

  • Follow existing code style
  • Add tests for new features
  • Update documentation as needed
  • Ensure Docker builds pass
  • Test infrastructure changes

🎯 Roadmap

  • Add database integration (RDS)
  • Implement authentication (Cognito)
  • Add monitoring dashboards
  • Multi-environment support
  • Blue/Green deployments
  • Cost optimization features

πŸ“„ License

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


πŸ™ Acknowledgments

  • Built with ❀️ using AWS services
  • Powered by modern web technologies
  • Inspired by cloud-native best practices
  • Community-driven development

⭐ Star this repo if you found it helpful!

Made with ❀️ by AKRAM SOUIDA

πŸ” Back to top

About

Fullstack app (NextJS + NodeJS) deployement on ECS Fargate

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published