diff --git a/_content/cases/stepsy.wiki.md b/_content/cases/stepsy.wiki.md new file mode 100644 index 0000000..600a5ec --- /dev/null +++ b/_content/cases/stepsy.wiki.md @@ -0,0 +1,44 @@ +--- +title: Multi-tenant knowledge base website based on Google APIs +goal: Create a modern multi-tenant web app that lets users use their Google Drive as a knowledge base +role: Design and implement the web app +date: Jul 29, 2023 - Nov 5, 2023 +--- + +
+Solution + +I chose NextJS as the backbone for this project as it offers the greatest amount of flexibility while still being very powerful both on the client as well as on the server with an active community and thriving ecosystem. + +For styles I chose TailwindCSS with DaisyUI for the optimizations and development speed that come out of using them. Tailwind uses purgecss to minimize the final bundle making the page load and feel faster. + +The database is PostgreSQL with Prisma ORM running on Vercel's cloud infrastructure. + +For authentication I chose NextAuth with JWT as it's the preferred way to handle auth in a NextJS project. + + +The actual implementation is a lengthy process involving many moving parts and lots of code. I'll go over the three most challenging problems in no particular order. + +Interfacing with Google Drive is done to read the content there and almost never used for writing except for setting and removing permissions. To read the content the reader must have appropriate permissions and that's determined by the auth system with a JWT. +For each request we can get the JWT and use it in the google client to auth unless it's an anonymous user, in which case we must use a google service account JWT. This JWT holds a google client access token used by google in determining permissions. +Once the client is set up we can start making drive requests on behalf of the user getting their drive content inside the web app including folders, files, documents, pictures, shared drives and so on, which can later be rendered on a page. +These requests are a bottleneck, which required many optimizations and concurrency tricks to make the site considerably faster than the competition. + +The storage API uses Prisma ORM for storing and getting all the user info including wikis and spaces. When a user logs in they can see their wiki as well as all the wikis they are allowed to manage. It's used to handle authorized requests like changing the wiki/space name, url, permissions and more. Storage is an integral part of any web application. + +The UI/UX uses TailwindCSS and DaisyUI to make everything a fast, modern, optimized and intuitive experience with extra features like dozens of themes as well as a custom theme builder. +React was used with TypeScript to provide a nice modern client-side experience between transitions and interactions. +This setup supports maximum optimization as you can see in the screenshots below allowing the app to reach a lighthouse score of 100 on all but one (it has 99) pages. +Both mobile and desktop is supported. +
+ +This project aims to be a Google Drive frontend. It uses the Google APIs to fetch document data and display that data in a wiki-style web page. + + +![thumbnail](/thumbnail.png) + + +It supports Google Docs, Google Sheets, Google Slides, PDFs and regular files. + + + diff --git a/bun.lockb b/bun.lockb index 68a6bbd..ce03ca9 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/flake.nix b/flake.nix index 97de4fc..6c7acc2 100644 --- a/flake.nix +++ b/flake.nix @@ -20,7 +20,9 @@ tmux new-session -s my_session -d tmux new-window -t my_session:1 tmux new-window -t my_session:2 + tmux new-window -t my_session:3 tmux send-keys -t my_session:1.0 'vi' C-m + tmux send-keys -t my_session:3.0 'bun run dev' C-m tmux attach-session -t my_session ''; in diff --git a/package.json b/package.json index 0455da4..615d5ed 100644 --- a/package.json +++ b/package.json @@ -14,9 +14,16 @@ "@fortawesome/free-regular-svg-icons": "^6.4.2", "@fortawesome/free-solid-svg-icons": "^6.4.2", "@fortawesome/react-fontawesome": "latest", + "gray-matter": "^4.0.3", "next": "latest", "react": "latest", - "react-dom": "latest" + "react-dom": "latest", + "react-markdown": "^9.0.0", + "rehype-highlight": "^7.0.0", + "rehype-raw": "^7.0.0", + "remark-frontmatter": "^5.0.0", + "remark-gfm": "^4.0.0", + "tailwind-highlightjs": "^2.0.1" }, "devDependencies": { "typescript": "latest", diff --git a/public/c/cases/stepsy.wiki.md/thumbnail.png b/public/c/cases/stepsy.wiki.md/thumbnail.png new file mode 100644 index 0000000..674951c Binary files /dev/null and b/public/c/cases/stepsy.wiki.md/thumbnail.png differ diff --git a/src/app/c/[...slug]/content.module.css b/src/app/c/[...slug]/content.module.css new file mode 100644 index 0000000..2b55e18 --- /dev/null +++ b/src/app/c/[...slug]/content.module.css @@ -0,0 +1,47 @@ +.md ol { + @apply list-decimal list-inside +} +.md ul { + @apply list-disc list-inside +} + +.md blockquote { + @apply border-l-neutral-500 border-l-4 p-2 +} + +.md blockquote p { + @apply before:content-['"'] after:content-['"'] +} + +.md details { + @apply p-20 +} + +.md details * { + @apply p-2 +} + +.md h1 { + @apply text-6xl +} + +.md h2 { + @apply text-5xl +} + +.md h3 { + @apply text-4xl +} + +.md h4 { + @apply text-3xl +} + +.md h5 { + @apply text-2xl +} + +.md h6 { + @apply text-xl +} + diff --git a/src/app/c/[...slug]/page.tsx b/src/app/c/[...slug]/page.tsx new file mode 100644 index 0000000..84bc094 --- /dev/null +++ b/src/app/c/[...slug]/page.tsx @@ -0,0 +1,88 @@ +import { getAllPaths, getContent } from "$lib/content"; +import Markdown from "react-markdown"; +import remarkGfm from "remark-gfm"; +import remarkFrontmatter from "remark-frontmatter"; +import styles from "./content.module.css" +import Image from "next/image"; +import rehypeRaw from "rehype-raw"; +import rehypeHighlight from "rehype-highlight"; + +type Params = { + slug: string[] +} + +type Props = { + params: Params +} + +export async function generateStaticParams(): Promise { + return getAllPaths().map(p => ({ slug: p.split("/") })) +} + +export default function Content({ params }: Props) { + const imgSize = 1024; + const { data, content } = getContent(params.slug); + + const title = () => { + return ( + + {data.title} + + ) + } + const goal = () => { + const g = data.goal + return g ? + ( +
+

The goal

+ {g} +
+ ) : + "" + } + const role = () => { + const r = data.role + return r ? + ( +
+

My role

+ {r} +
+ ) : + "" + } + + const ctnt = () => { + return ( + + {alt!} + + ) + } + }} + > + {content} + + ) + } + return ( +
+
+ {title()} + {goal()} + {role()} +
+
+ {ctnt()} +
+
+ ) +} diff --git a/src/app/cases/page.tsx b/src/app/cases/page.tsx new file mode 100644 index 0000000..2503574 --- /dev/null +++ b/src/app/cases/page.tsx @@ -0,0 +1,7 @@ +import Cases from "$components/cases"; + +export default function CasesPage() { + return ( + + ) +} diff --git a/src/app/components/cases.tsx b/src/app/components/cases.tsx new file mode 100644 index 0000000..f210d37 --- /dev/null +++ b/src/app/components/cases.tsx @@ -0,0 +1,25 @@ +import { GrayMatterFile } from "gray-matter"; +import Link from "next/link"; +import { getCases } from "../lib/content"; + +export default function Cases() { + const cases: GrayMatterFile[] = getCases() + return ( +
+ {cases.map((c) => { + const d = c.data; + const date = d.date.split("-") + const from = date[0]?.trim() + const to = date[1]?.trim() + return ( +
+ + {d.title} + {from} {to ? `- ${to}` : ""} + +
+ ) + })} +
+ ) +} diff --git a/src/app/components/links.tsx b/src/app/components/links.tsx index 2af472d..b9e647d 100644 --- a/src/app/components/links.tsx +++ b/src/app/components/links.tsx @@ -5,13 +5,15 @@ import Link from "next/link"; export default function Links() { return ( -
- - - - - - +
+
+ + + + + + +
) } diff --git a/src/app/components/navbar.tsx b/src/app/components/navbar.tsx new file mode 100644 index 0000000..5d6a773 --- /dev/null +++ b/src/app/components/navbar.tsx @@ -0,0 +1,26 @@ +"use client" +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { ReactNode } from "react"; + +export default function Navbar() { + const path = usePathname() + + const link = (text: ReactNode, href: string) => { + return ( + + {text} + + ) + } + + return ( +
+
+ {link("Home", "/")} + {link("Cases", "/cases")} + {link("Contact", "/contact")} +
+
+ ) +} diff --git a/src/app/contact/page.tsx b/src/app/contact/page.tsx new file mode 100644 index 0000000..f5669fc --- /dev/null +++ b/src/app/contact/page.tsx @@ -0,0 +1,15 @@ +import { faEnvelope } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; + +export default function Contact() { + + const email = "ivan@idimitrov.dev"; + + return ( +
+
+ +
+
+ ) +} diff --git a/src/app/globals.css b/src/app/globals.css index 8acb3ef..1f2b342 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -7,10 +7,14 @@ body { } main { - @apply grid w-full h-full + @apply flex flex-col w-full h-full } svg { @apply w-14 h-14 text-amber-100 hover:text-cyan-500 } +.btn { + @apply bg-gray-900 text-gray-300 hover:bg-gray-700 hover:text-white rounded-md px-3 py-2 text-sm font-medium aria-selected:bg-gray-600 +} + diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 34328c7..9a7aed6 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,4 +1,5 @@ import './globals.css' +import Navbar from './components/navbar' import type { Metadata } from 'next' export const metadata: Metadata = { @@ -13,7 +14,12 @@ export default function RootLayout({ }) { return ( - {children} + +
+ + {children} +
+ ) } diff --git a/src/app/lib/content.ts b/src/app/lib/content.ts new file mode 100644 index 0000000..3388e4a --- /dev/null +++ b/src/app/lib/content.ts @@ -0,0 +1,43 @@ +import fs from "fs"; +import matter, { GrayMatterFile } from "gray-matter"; +import path from "path"; + +const baseDir = "./_content/" + +export const getContent = (slug: string[]): GrayMatterFile => { + let p = path.join(baseDir) + slug.forEach(s => { + p = path.join(p, s) + }) + const file = fs.readFileSync(p, "utf8") + const m = matter(file); + m.data.slug = `/c/${slug.join("/")}` + return m +} + +const getAllPathsRecursive = (base = baseDir): string[] => { + let results = [] as string[]; + + const files = fs.readdirSync(base); + + for (const file of files) { + const filePath = path.join(base, file); + const stat = fs.statSync(filePath); + + if (stat.isDirectory()) { + results = results.concat(getAllPathsRecursive(filePath)); + } else if (path.extname(filePath) === '.md') { + results.push(filePath); + } + } + return results; +} + +export const getAllPaths = (base = baseDir): string[] => { + return getAllPathsRecursive(base).map(p => p.substring(9)) +} + +export const getCases = (): GrayMatterFile[] => { + return getAllPaths(`${baseDir}cases/`).map(s => s.split("/")).map(getContent) +} + diff --git a/src/app/page.tsx b/src/app/page.tsx index f844da4..ea77018 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -2,8 +2,6 @@ import Links from "$components/links"; export default function Home() { return ( -
- -
+ ) } diff --git a/tailwind.config.ts b/tailwind.config.ts index 1af3b8f..0d293a4 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -6,15 +6,14 @@ const config: Config = { './src/components/**/*.{js,ts,jsx,tsx,mdx}', './src/app/**/*.{js,ts,jsx,tsx,mdx}', ], + safelist: [{ + pattern: /hljs+/, + }], theme: { - extend: { - backgroundImage: { - 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', - 'gradient-conic': - 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))', - }, + hljs: { + theme: 'night-owl', }, }, - plugins: [], + plugins: [require('tailwind-highlightjs')], } export default config