Skip to content

danielsidauruk/3-tier-architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

3-Tier Architecture

This project implements a 3-tier architecture using AWS, Terraform, and a Python backend.

Infrastructure Diagram

Infrastructure Diagram

Architecture

A classic 3-tier architecture deployed on AWS using Terraform.

  • Frontend: Static HTML site served by Nginx
  • Backend: Flask REST API written in Python, running on Gunicorn, using PyMongo for database access and Redis for caching
  • Data Layer:
    • Amazon DocumentDB (MongoDB-compatible) as the primary datastore
    • Amazon ElastiCache (Redis) for in-memory caching

Project Structure

.
├── diagram
└── src
    └── app
    │   ├── backend
    │   └── frontend
    └── aws
        └── modules
            ├── backend
            ├── documentdb
            ├── elasticache
            ├── frontend
            ├── iam
            └── network

Deployment

  1. Configure AWS Credentials: Make sure you have your AWS credentials configured properly.

  2. Initialize Terraform:

    cd aws
    terraform init
  3. Apply Terraform:

    terraform apply
  4. Destroy Infrastructure:

    terraform destroy

How the App Works

Demonstration

Data Retrieval Flow

  1. Request: Client ➔ Backend
  2. Check: Backend ➔ Redis (Search for data)
  3. Decision:
    • IF HIT: Redis ➔ BackendClient
    • IF MISS: Redis ➔ Backend (Not found) ➔ Step 4
  4. Fetch: Backend ➔ MongoDB (Get original data)
  5. Update: MongoDB ➔ BackendRedis (Save for next time)
  6. Deliver: Backend ➔ Client 🏁

API Endpoints

The backend provides the following API endpoints:

  • GET /system-status: Returns the status of the system.
  • GET /get_data/<string:key>: Retrieves data from the cache or database.
  • GET /list_all_data: Retrieves all data from the database.
  • POST /set_data: Inserts new data into the database.
  • DELETE /delete_data/<string:key>: Deletes data from the database.
  • GET /health: Returns the health of the backend and its database connections.

Other Documentation

Idea Source

This project is for educational purposes and is based on a common architectural pattern. For more examples and best practices, please refer to the AWS Architecture Center.

About

Automating the deployment of a 3-Tier Architecture on AWS using Terraform.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors