Go Back

Bognar.dev

January 10, 2024

Introduction

Tech Stack:

Key Features:

Backend

Overview

The backend was programmed using Go using the Gin web server, because go is an easy and fast language.

It serves the purpose of a "basic" CRUD-API Layer to the database, it does not serve the html and frontend by itself.

Core Features Implementation

My backend had the task of being there for all the Project operations and handling authorization of the user, so that only authorized user (The admin) can alter project data.

The codebase is structured using a fairly standard Filesystem:

Auth-Controller

func Login(c *gin.Context)
func Register(c *gin.Context)
func Status(c *gin.Context)
func CurrentUser(c *gin.Context)

Project-Controller

func GetProjects(c *gin.Context)
func CreateProject(c *gin.Context)
func GetProjectByID(c *gin.Context)
func UpdateProject(c *gin.Context)

Middleware

func JwtAuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		fmt.Println("jwt middleware")
		err := token.ValidateToken(c)
		if err != nil {
			fmt.Println("Middleware error: ", err)
			c.String(http.StatusUnauthorized, "Unauthorized")
			c.Abort()
			return
		}
		fmt.Println("Authorized")
		c.Next()
	}
}

Public Routes

r.GET("/", controllers.Hey)
r.GET("/api/projects", controllers.GetProjects)
r.GET("/api/projects/:id", controllers.GetProjectByID)
r.POST("/login", controllers.Login)
r.POST("/register", controllers.Register)

Private Routes

private := r.Group("/private")
private.Use(middlewares.JwtAuthMiddleware()) //Private routes protected by middleware
{
	private.GET("/user", controllers.CurrentUser)
	private.GET("/status", controllers.Status)
	private.POST("/createProject", controllers.CreateProject)
	private.POST("/updateProject", controllers.UpdateProject)
}

Functionality Level

Because the API is not consumable publicly the error handling is being handled internally and a user-friendly error handling is done on the frontend following this guide

In a real life scenario I would ditch splitting database, in favor of a full-stack solution that Next.js offers.

The database uses sqlx for type-safe SQL query to the database.

Issues

Using file storage and database from Supabase requires connecting to the DB and the Storage separately, because I wanted to use SQLx strings for the Database.

Before using the Admin dashboard the admin needs to be crated by another authorized admin

Design Considerations

I chose to use raw SQL to query the data, which helps me being future proof in case I want to migrate the service to a different stack.

The Backend layer is protected by middleware and uses JWT token instead of cookie storage to authorize users.

Code Quality

My code follows best practices such as using structures to Marshal and unMarshal JSON data from requests with go's encoding package, I can be confident using the Project structure because go handles filling it for me ad will error when a field is missing.

Encoding Package Go

Database Implementation

Overview

Core Features Implementation

DB w:900 h:200

The project JSON structure

Jsonblob

Design Considerations

Innovative Approaches

Frontend Technical Analysis

Overview

Components

Example

import { twMerge } from "tailwind-merge"
import ScrollMotionDiv from "./scroll-motion-div"

export default function Card({ className, children, motion = false }: { className?: string, children: React.ReactNode, motion?: boolean }) {
    if (motion) {
        return (
            <ScrollMotionDiv className={twMerge(className, 'pt-3 w-full text-card-foreground grid bg-background-50 backdrop-blur-sm shadow-sm shadow-primary-400 rounded-lg ')}>
                {children}
            </ScrollMotionDiv>
        )
    }
    return (
        <div className={twMerge(className, 'pt-3 w-full text-card-foreground grid bg-background-50 backdrop-blur-sm shadow-sm shadow-primary-400 rounded-lg ')}>
            {children}
        </div>
    )
}

It is possible to reuse my cards all over the project as I can specify if I want it to have animation/motion can add Tailwind style classes to customize it in any place. I can also pass any kind of components as children so I can render anything inside a card.

Formidable Blog article

export default async function ProjectPage({ params }: { params: { id: string } }) {
  const response = await fetch(`${process.env.BACKEND_URL}/api/projects/${params.id}`, { next: { revalidate: 3600 } })
  const project = await (response.json()) as Project;
  
  return (
    <>

      <ProjectEditForm className="" project={project}>
        <ProjectEditHeader>

          {project.data.tags.map((tag, index) => (
            <div key={index} className='flex gap-2'>
              <ProjectEditTag tag={tag}>{tag}</ProjectEditTag>
              <Icons.circleMinus className="w-1 h-1"  />
            </div>
          ))}

          <Icons.circlePlus className='m-3 self-center' />
        </ProjectEditHeader>
        <ProjectEditDate>
          Start Date
        </ProjectEditDate>
        <ProjectEditDate>
          End Date
        </ProjectEditDate>
        <ProjectEditText />
        <ProjectMarkdown></ProjectMarkdown>
        <SubmitButton>Save</SubmitButton>
      </ProjectEditForm>

    </>
  );
}

Challenges and Solutions

How to safely render markdown in react

HCI-Investigation

Overview

Importance of HCI

User Study

Results

Age of participants

Age Graph

Gender of participants

gender Graph

Positive Feedback

Design Feedback

Devices used to access the Website

devices Graph

Content Suggestions

Contact Ease

Mode Preferences

Implementation of Solutions

Example

The comment that made me realize: Create individual pages for different categories Younger people it was easy to navigate older people found it hard to navigate and didn't even know how to use the links to different pages

Before

Link before improvement w:200 h:100

After

After implementation w:200 h:100

2nd Fix

User found that the navbar was too small

Small header bg contain

Big header bg contain

Design Considerations

Frontend DevOps and Hosting

Backend DevOps and Hosting

Database Deployment

Script for Local Development


rem
echo Starting Docker Desktop...
start "" "C:\Program Files\Docker\Docker\Docker Desktop.exe"

rem 
timeout /t 10

rem 
echo Starting Supabase...
cd C:\Users\Niklas\Documents\Uni23_24\WEB\bognar.dev-portfolio\app
start npx supabase start

rem
timeout /t 10

rem
echo Starting Go application...
cd C:\Users\Niklas\Documents\Uni23_24\WEB\bognar.dev-backend\
start cmd /k "go run main.go"

rem 
echo Starting Next.js development server...
start cmd /k "cd C:\Users\Niklas\Documents\Uni23_24\WEB\bognar.dev-portfolio && pnpm run dev"

Optimization Investigation

Introduction

Current State

Lighthouse Analysis

bg contain

Identified Issues