Skip to content

daniel961/UserManagment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Fullstack Microservices App with React, Node.js, and PostgreSQL

This project is a full-stack application consisting of:

  • User Service: A Node.js + TypeScript + Apollo GraphQL microservice connected to PostgreSQL.
  • Client: A React frontend served with Nginx.
  • Database: PostgreSQL database managed through Docker.

Features

  1. User Management:
    • Create, Read, Update, Delete (CRUD) operations on users via GraphQL.
  2. Load Balancing:
    • User service runs with multiple replicas behind an Nginx reverse proxy.
  3. Frontend:
    • React app served via Nginx to interact with the user service.

Prerequisites


Project Structure

├── client/ # React frontend
│ ├── src/ # React source code
│ ├── public/ # Static assets
│ ├── Dockerfile # Docker setup for the React app
│ └── nginx.conf # Nginx configuration for serving React
├── user/ # User service (Node.js + GraphQL)
│ ├── src/ # Source code for the Node.js service
│ ├── Dockerfile # Docker setup for the Node.js service
│ ├── .env # Environment variables for the user service
│ └── nginx/ # Nginx reverse proxy config
├── docker-compose.yml # Orchestrates the multi-service app
└── README.md # Project documentation

How to Run the Application

1. Clone the Repository

git clone <repository-url>
cd <repository-folder>


Inside the user/.env file, ensure the following variables are set:


# SERVICE ENV
DB_HOST=db
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=postgres
DB_NAME=users_db



# USER DB ENV
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=users_db

Run the following command to build and launch all services:

docker-compose up --build && docker-compose up

This will:

  1. Build the user service and client Docker images.

  2. Start the PostgreSQL database container.

  3. Start Nginx for load balancing and frontend serving.

  4. Access the Application

Frontend: Open http://localhost:3000 to view the React app. GraphQL Playground: Open http://localhost:4000 to interact with the GraphQL API.

GraphQL API (User Service)

Fetch All Users

query {
  users {
    id
    firstName
    lastName
    birthDate
    city
  }
}

Mutations Create User

mutation CreateUser(
  $firstName: String!
  $lastName: String!
  $birthDate: DateTime!
  $city: String!
) {
  createUser(
    firstName: $firstName
    lastName: $lastName
    birthDate: $birthDate
    city: $city
  ) {
    id
    firstName
    lastName
  }
}

Update user

mutation UpdateUser(
  $id: ID!
  $firstName: String
  $lastName: String
  $birthDate: DateTime
  $city: String
) {
  updateUser(
    id: $id
    firstName: $firstName
    lastName: $lastName
    birthDate: $birthDate
    city: $city
  ) {
    id
    firstName
    lastName
  }
}

Delete User

mutation DeleteUser($id: ID!) {
  deleteUser(id: $id)
}

Notes

Ensure Docker Compose runs successfully without errors. Check logs using:

docker-compose logs

Future Enhancements

  • Add authentication and authorization.

  • Integrate CI/CD pipelines for automated testing and deployment.

  • Add monitoring and logging for better observability.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published