Skip to content

Commit

Permalink
Refactor/code organization (#117)
Browse files Browse the repository at this point in the history
* 🚚 move actions into *.action files

* 🚚 move folders into the top level `src` folder

* 📝 update README.md file

* 🔧 remove `KV` from env variables
  • Loading branch information
Fredkiss3 committed Dec 21, 2023
1 parent 41282e5 commit 76a3e0d
Show file tree
Hide file tree
Showing 127 changed files with 314 additions and 189 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 +113,40 @@ A quick look at the top-level files and directories you will see in this project
```plaintext
.
├── src/
│ ├── app/
├── (actions)
├── (components)
├── (models)
└── (routes)
└──lib/
│ ├── db/schema
│ └── hooks
├── .prettierrc
│ ├── app
│ ├── actions
│ ├── components
│ ├── models
│ └── lib/
├── client
├── server
└── shared
├── biome.json
├── pnpm-lock.yaml
└── tsconfig.json
```

1. `src/app/`: this folder contains the source code to our app :
1. `src/app/`: this folder contains all the routes & pages of our app.

1. `(actions)` : this folder contains all the logic of our app.
2. `src/actions` : this folder contains all the logic of our app.

2. `(components)` : this folder contains all the components of our app.
3. `src/components` : this folder contains all the components of our app.

3. `(models)` : this folder contains all the DB models of our app.
4. `src/models` : this folder contains all the DB models of our app.

4. `(routes)` : this folder contains all the routes & pages of our app.
5. `src/lib/`: this folder contains utils & helpers used throughout our app :

2. `src/lib/`: this folder contains utils & helpers used throughout our app :
1. `client` : this folder contains all the utilities that are client-only, usually used by client components. It contains mainly hooks

1. `db/schema` : this folder contains all the drizzle sqlite schema for our DB.
2. `server` : this folder contains all the utilities that are server-only, for use within server components and server actions. It also contains the DB schemas inside `db/schema`

2. `hooks` : this folder contains all the react custom hooks used in the app.
3. `shared` : this folder contains all the utilities that are shared between the server & client, these can be used anywhere in the app.

3. `.prettierrc`: this file contains the configuration for prettier to enable autoformatting.
6. `biome.json`: this file contains the configuration for biome to enable autoformatting.

4. `pnpm-lock.yaml`: this file contains the dependencies lock for the repo.
7. `pnpm-lock.yaml`: this file contains the dependencies lock for the repo.

5. `tsconfig.json`: this file contains the configuration for typescript, that are used by the all the underlying packages
8. `tsconfig.json`: this file contains the configuration for typescript, that are used by the all the underlying packages

## 🍳 ENV VARIABLES USED

Expand Down
2 changes: 1 addition & 1 deletion src/app/(actions)/auth.ts → src/actions/auth.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getUserById,
getOrInsertUserFromGithubProfile,
githubUserSchema
} from "~/app/(models)/user";
} from "~/models/user";
import { experimental_taintObjectReference as taintObjectReference } from "react";
import { revalidatePath } from "next/cache";
import { withAuth, type AuthState } from "./middlewares";
Expand Down
File renamed without changes.
12 changes: 6 additions & 6 deletions src/app/(actions)/issue.tsx → src/actions/issue.action.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
"use server";

import { getLabelsByName } from "~/app/(models)/label";
import { getLabelsByName } from "~/models/label";
import {
getIssueAssigneesByUsername,
getIssueAssigneesByUsernameOrName,
getIssueAuthorsByName,
getIssueAuthorsByUsername,
getSingleIssueWithLabelAndUser
} from "~/app/(models)/issues";
} from "~/models/issues";

import { issueSearchListOutputValidator } from "~/app/(models)/dto/issue-search-output-validator";
import { searchIssues } from "~/app/(models)/issues/search";
import { issueSearchListOutputValidator } from "~/models/dto/issue-search-output-validator";
import { searchIssues } from "~/models/issues/search";

import { getAuthedUser } from "./auth";
import { getAuthedUser } from "./auth.action";
import { cache } from "react";

import type { IssueSearchFilters } from "~/lib/shared/utils.shared";
import { IssueHoverCardContents } from "~/app/(components)/hovercard/issue-hovercard-contents";
import { IssueHoverCardContents } from "~/components/hovercard/issue-hovercard-contents";

/**
* We use `promise` because server actions are not batched,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "server-only";
import { revalidatePath } from "next/cache";
import { getSession, getAuthedUser } from "~/app/(actions)/auth";
import { getSession, getAuthedUser } from "~/actions/auth.action";
import type { FunctionWithoutLastArg, OmitLastItemInArray } from "~/lib/types";
import type { Session } from "~/lib/server/session.server";
import type { User } from "~/lib/server/db/schema/user.sql";
Expand Down
4 changes: 2 additions & 2 deletions src/app/(actions)/theme.ts → src/actions/theme.action.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use server";

import { z } from "zod";
import { getSession } from "./auth";
import { getSession } from "./auth.action";
import { cache } from "react";
import { updateUserTheme } from "~/app/(models)/user";
import { updateUserTheme } from "~/models/user";
import { revalidatePath } from "next/cache";

import { users } from "~/lib/server/db/schema/user.sql";
Expand Down
8 changes: 4 additions & 4 deletions src/app/(actions)/user.ts → src/actions/user.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

import { revalidatePath } from "next/cache";
import { withAuth, type AuthError, type AuthState } from "./middlewares";
import { updateUserInfos } from "~/app/(models)/user";
import { updateUserInfos } from "~/models/user";
import {
updateUserProfileInfosInputValidator,
type UpdateUserProfileInfosInput
} from "~/app/(models)/dto/update-profile-info-input-validator";
} from "~/models/dto/update-profile-info-input-validator";

import type { FormState } from "~/lib/types";

export const updateUserProfile = withAuth(async function (
export const updateUserProfile = withAuth(async (
_previousState: FormState<UpdateUserProfileInfosInput> | AuthError,
formData: FormData,
{ session, currentUser }: AuthState
): Promise<FormState<UpdateUserProfileInfosInput>> {
): Promise<FormState<UpdateUserProfileInfosInput>> => {
const result = updateUserProfileInfosInputValidator.safeParse(
Object.fromEntries(formData)
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { HeaderNavLinks } from "~/app/(components)/header/header-navlinks";
import { HeaderNavLinks } from "~/components/header/header-navlinks";

import type { PageProps } from "~/lib/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from "react";
import { HeaderNavLinks } from "~/app/(components)/header/header-navlinks";
import { HeaderNavLinks } from "~/components/header/header-navlinks";

import type { PageProps } from "~/lib/types";

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from "react";
// components
import Link from "next/link";
import { HoverCard } from "~/app/(components)/hovercard/hovercard";
import { UserHoverCardContents } from "~/app/(components)/hovercard/user-hovercard-contents";
import { HoverCard } from "~/components/hovercard/hovercard";
import { UserHoverCardContents } from "~/components/hovercard/user-hovercard-contents";

// utils
import { clsx } from "~/lib/shared/utils.shared";
import { getRepositoryByOwnerAndName } from "~/app/(models)/repository";
import { getRepositoryByOwnerAndName } from "~/models/repository";
import { notFound } from "next/navigation";

// types
Expand Down
5 changes: 5 additions & 0 deletions src/app/(app)/@page_title/[user]/[repository]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as React from "react";
// types
import { RepositoryPageTitle } from "~/app/(app)/@page_title/[user]/[repository]/[...pages]/page";

export default RepositoryPageTitle;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from "next/link";

// utils
import { clsx } from "~/lib/shared/utils.shared";
import { getUserByUsername } from "~/app/(models)/user";
import { getUserByUsername } from "~/models/user";
import { notFound } from "next/navigation";

// types
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// components
import { HomeIcon } from "@primer/octicons-react";
import { Button } from "~/app/(components)/button";
import { Button } from "~/components/button";

// utils
import { clsx } from "~/lib/shared/utils.shared";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import "server-only";

// components
import { MarkdownTitle } from "~/app/(components)/markdown/markdown-title";
import { Markdown } from "~/app/(components)/markdown/markdown";
import { Cache } from "~/app/(components)/cache/cache";
import { MarkdownTitle } from "~/components/markdown/markdown-title";
import { Markdown } from "~/components/markdown/markdown";
import { Cache } from "~/components/cache/cache";

// utils
import { notFound } from "next/navigation";
import { preprocess, z } from "zod";
import { CacheKeys } from "~/lib/shared/cache-keys.shared";
import { getSingleIssue } from "~/app/(models)/issues";
import { getSingleIssue } from "~/models/issues";

// types
import type { Metadata } from "next";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as React from "react";
// components
import { Button } from "~/app/(components)/button";
import { CounterBadge } from "~/app/(components)/counter-badge";
import { IssuesListHeaderForm } from "~/app/(components)/issues/issues-list-header-form";
import { SegmentedLayout } from "~/app/(components)/segmented-layout";
import { ClearSearchButtonSection } from "~/app/(components)/issues/clear-search-button";
import { ReactQueryProvider } from "~/app/(components)/react-query-provider";
import { Button } from "~/components/button";
import { CounterBadge } from "~/components/counter-badge";
import { IssuesListHeaderForm } from "~/components/issues/issues-list-header-form";
import { SegmentedLayout } from "~/components/segmented-layout";
import { ClearSearchButtonSection } from "~/components/issues/clear-search-button";
import { ReactQueryProvider } from "~/components/react-query-provider";
import { LightBulbIcon, MilestoneIcon, TagIcon } from "@primer/octicons-react";
import { IssueListSkeleton } from "~/app/(components)/issues/issue-list-skeleton";
import { IssueSearchLink } from "~/app/(components)/issues/issue-search-link";
import { IssueList } from "~/app/(components)/issues/issue-list";
import { IssueListSkeleton } from "~/components/issues/issue-list-skeleton";
import { IssueSearchLink } from "~/components/issues/issue-search-link";
import { IssueList } from "~/components/issues/issue-list";

// utils
import { clsx } from "~/lib/shared/utils.shared";
import { getAuthedUser } from "~/app/(actions)/auth";
import { getLabelsCount } from "~/app/(models)/label";
import { getAuthedUser } from "~/actions/auth.action";
import { getLabelsCount } from "~/models/label";

// types
import type { Metadata } from "next";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Metadata } from "next";
import * as React from "react";
import { getRepositoryByOwnerAndName } from "~/app/(models)/repository";
import { getRepositoryByOwnerAndName } from "~/models/repository";
import type { LayoutProps, PageProps } from "~/lib/types";

export async function generateMetadata(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ import {
StarIcon,
TriangleDownIcon
} from "@primer/octicons-react";
import { Avatar } from "~/app/(components)/avatar";
import { Badge } from "~/app/(components)/badge";
import { CounterBadge } from "~/app/(components)/counter-badge";
import { Button } from "~/app/(components)/button";
import { Avatar } from "~/components/avatar";
import { Badge } from "~/components/badge";
import { CounterBadge } from "~/components/counter-badge";
import { Button } from "~/components/button";
import Link from "next/link";
import { Skeleton } from "~/app/(components)/skeleton";
import { Markdown } from "~/app/(components)/markdown/markdown";
import { Cache } from "~/app/(components)/cache/cache";
import { Skeleton } from "~/components/skeleton";
import { Markdown } from "~/components/markdown/markdown";
import { Cache } from "~/components/cache/cache";

// utils
import { getSession } from "~/app/(actions)/auth";
import { getGithubRepoData } from "~/app/(actions)/github";
import { getRepositoryByOwnerAndName } from "~/app/(models)/repository";
import { getSession } from "~/actions/auth.action";
import { getGithubRepoData } from "~/actions/github.action";
import { getRepositoryByOwnerAndName } from "~/models/repository";
import {
AUTHOR_AVATAR_URL,
GITHUB_AUTHOR_USERNAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import {
LocationIcon,
OrganizationIcon
} from "@primer/octicons-react";
import { Avatar } from "~/app/(components)/avatar";
import { Pagination } from "~/app/(components)/pagination";
import { Skeleton } from "~/app/(components)/skeleton";
import { Avatar } from "~/components/avatar";
import { Pagination } from "~/components/pagination";
import { Skeleton } from "~/components/skeleton";

// utils
import { getGithubRepoData } from "~/app/(actions)/github";
import { getGithubRepoData } from "~/actions/github.action";
import { formatDate, range, reversePaginate } from "~/lib/shared/utils.shared";

// types
Expand Down Expand Up @@ -68,6 +68,7 @@ async function StargazersPageContent({ currentPage }: { currentPage: number }) {
<a
href={`https://github.com/${stargazer.login}`}
target="_blank"
rel="noreferrer"
>
{stargazer.login}
</a>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// components
import { Footer } from "~/app/(components)/footer";
import { Header } from "~/app/(components)/header/header";
import { Footer } from "~/components/footer";
import { Header } from "~/components/header/header";
import { clsx } from "~/lib/shared/utils.shared";

export default async function AppLayout({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @next/next/no-img-element */
import { HomeIcon } from "@primer/octicons-react";
import { Button } from "~/app/(components)/button";
import { Button } from "~/components/button";

export default function AppNotFound() {
return (
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from "react";

// components
import { UpdateUserInfosForm } from "~/app/(components)/update-user-infos-form";
import { Button } from "~/app/(components)/button";
import { UpdateUserInfosForm } from "~/components/update-user-infos-form";
import { Button } from "~/components/button";

// utils
import { getAuthedUser, redirectIfNotAuthed } from "~/app/(actions)/auth";
import { updateUserProfileInfosInputValidator } from "~/app/(models)/dto/update-profile-info-input-validator";
import { getAuthedUser, redirectIfNotAuthed } from "~/actions/auth.action";
import { updateUserProfileInfosInputValidator } from "~/models/dto/update-profile-info-input-validator";

// types
import type { Metadata } from "next";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import * as React from "react";

// components
import { ThemeForm } from "~/app/(components)/theme-form";
import { ThemeForm } from "~/components/theme-form";

// utils
import { redirectIfNotAuthed } from "~/app/(actions)/auth";
import { getTheme } from "~/app/(actions)/theme";
import { redirectIfNotAuthed } from "~/actions/auth.action";
import { getTheme } from "~/actions/theme.action";

// types
import type { Metadata } from "next";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// components
import { Avatar } from "~/app/(components)/avatar";
import { Avatar } from "~/components/avatar";

import { VerticalNavlist } from "~/app/(components)/vertical-navlist";
import { VerticalNavlist } from "~/components/vertical-navlist";

// utils
import { getAuthedUser, redirectIfNotAuthed } from "~/app/(actions)/auth";
import { getAuthedUser, redirectIfNotAuthed } from "~/actions/auth.action";
import { clsx } from "~/lib/shared/utils.shared";

export default async function SettingsLayout({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { redirect } from "next/navigation";
import { redirectIfNotAuthed } from "~/app/(actions)/auth";
import { redirectIfNotAuthed } from "~/actions/auth.action";

export default async function Page() {
await redirectIfNotAuthed("/settings/account");
Expand Down
Loading

0 comments on commit 76a3e0d

Please sign in to comment.