UserLookup System Architecture


GraphQL Spring Boot Application for User and Post Management - Demonstrating efficient user and post management with precise data queries


System Overview

flowchart TD subgraph ClientLayer[Clients] Web[Web App] Mobile[Mobile App] Postman[Postman/Testing] end subgraph APILayer[API Layer] GraphQL[GraphQL Endpoint] end subgraph ServiceLayer[Service Layer] Resolver[GraphQL Resolvers] Service[Business Services] end subgraph DataLayer[Data Layer] Repository[Spring Data JPA] H2[(H2 Database)] end ClientLayer -->|HTTP Requests| APILayer APILayer --> ServiceLayer ServiceLayer --> DataLayer

Key Features

  • Precise data queries with GraphQL
  • User and post management
  • Pagination and filtering support
  • Clean, extensible GraphQL schema
  • In-memory H2 database
  • Custom exception handling
  • Input validation
  • Relationship management

Technology Stack

Java 17
Language
Spring Boot 3
Framework
Spring GraphQL
API Layer
H2 Database
Storage

Detailed Architecture

classDiagram class User { +String id +String name +String email +List~Post~ posts } class Post { +String id +String title +String content +User author } class UserRepository { +findById(String id) User +findAll() List~User~ +findAll(Pageable pageable) Page~User~ } class PostRepository { +findByAuthorId(String authorId) List~Post~ } class UserService { +getUser(String id) User +getAllUsers() List~User~ +getUsersPaged(Pageable pageable) Page~User~ +createUser(UserInput input) User } class PostService { +getPostsByUser(String userId) List~Post~ +createPost(PostInput input) Post } class UserResolver { +posts(User user) List~Post~ } class Query { +getUser(String id) User +getAllUsers() List~User~ +getUsersPaged(int page, int size) Page~User~ +getPostsByUser(String userId) List~Post~ } class Mutation { +createUser(UserInput input) User +createPost(PostInput input) Post } User "1" -- "*" Post UserRepository ..> User PostRepository ..> Post UserService ..> UserRepository PostService ..> PostRepository UserResolver ..> PostService Query ..> UserService Query ..> PostService Mutation ..> UserService Mutation ..> PostService

Layered Architecture

GraphQL Layer

Schema definition and query/mutation handling

Resolver Layer

Data fetching and relationship resolution

Service Layer

Business logic and transaction management

Repository Layer

Data access and persistence

Model Layer

Entity definitions and relationships

API Examples

Get User by ID
query {
  getUser(id: "1") {
    id
    name
    email
    posts {
      id
      title
    }
  }
}
Get Paginated Users
query {
  getUsersPaged(page: 0, size: 2) {
    id
    name
    email
  }
}
Get Posts by User
query {
  getPostsByUser(userId: "1") {
    id
    title
    content
  }
}
Get All Users
query {
  getAllUsers {
    id
    name
    email
  }
}
Create User
mutation {
  createUser(input: { 
    name: "Alice Johnson", 
    email: "alice@example.com" 
  }) {
    id
    name
    email
  }
}
Create Post
mutation {
  createPost(input: { 
    title: "GraphQL with Spring", 
    content: "Content goes here", 
    authorId: "1" 
  }) {
    id
    title
    author {
      id
      name
    }
  }
}

Postman Testing

Test the API using Postman with either:

  • Raw JSON requests
  • Postman's native GraphQL support
JSON Request Example
{
  "query": "query { getUser(id: \"1\") { id name } }"
}

H2 Console

Access the in-memory database console at:

http://localhost:8080/h2-console

JDBC URL: jdbc:h2:mem:testdb

Username: sa (no password)

Setup Instructions

Quick Start

  1. Clone the repository:
    git clone https://github.com/PritiAryal/UserLookup.git
    cd UserLookup
  2. Build the project:
    mvn clean install
  3. Run the application:
    mvn spring-boot:run
  4. Access GraphQL endpoint at:
    http://localhost:8080/graphql