diff --git a/readme.md b/readme.md index 94d918f..57ca439 100644 --- a/readme.md +++ b/readme.md @@ -83,6 +83,8 @@ Mental model for picking this or any stack: - Testing framework? Didn't bother setting up tests for this. Bun comes with bun:test, probably use that. - Typescript - Caching implementation -- didn't get to this yet +- Haven't put much time into compression or minification of assets, just implemented the basics. Could use something like brotli or the recommended (CSSNano)[https://cssnano.github.io/cssnano/docs/introduction/] +- Advanced Hono features. Comes pre-built with (RPC)[https://hono.dev/docs/guides/rpc] and (JSX)[https://hono.dev/docs/guides/jsx] ## Going faster @@ -267,11 +269,14 @@ bun run db:migrate They should be automatically applied upon deployment. +### Organization +- /routes contains the routes for the application. As the application grows, each feature can be broken out into its own file. +- /views contains the html templates. These are rendered with Eta on the server. HTMX is used to update the DOM, check the hx-* attributes. In the future, it might be better to have sub-folders for each feature, /todo, /list, etc. +- queries.js contains the queries for the database. Queries is the main object here, and acts as your 'orm' to extend +- index.js is the entrypoint for the application. + Other stuff: -- index.js is the entrypoint for the application. It's a standard Express.js app. Edit business logic there. - src/instrumentation.js is used to instrument the app with opentelemetry. You probably don't need to change this. -- src/queries.js is a convenience wrapper around the database for interacting with the database. -- views/* contains the html templates. These are rendered with EJS on the server. HTMX is used to update the DOM, check the hx-* attributes. - public/* contains the static assets. ## Devops diff --git a/src/index.js b/src/index.js index 0fa1e66..b59a90d 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ import { Hono } from "hono"; import { Eta } from "eta"; -import TodoQueries from "./queries"; +import Queries from "./queries"; import { requiresAuth } from "./middleware/auth"; import { findDirectories, handleAsyncError, applyMiddleware } from "./utils"; import { logger } from "./instrumentation"; @@ -27,7 +27,7 @@ app.get("/", requiresAuth, async (c) => { app.get("/todos", requiresAuth, async (c) => { const [todos, getErr] = await handleAsyncError(() => - TodoQueries.getAllTodos(c.get("user")?.sub) + Queries.todo.getAllTodos(c.get("user")?.sub) ); if (getErr) { return c.text("Error: " + getErr.message, 400); @@ -39,7 +39,7 @@ app.get("/todos", requiresAuth, async (c) => { app.post("/todos", requiresAuth, async (c) => { const { listId, title, description, dueDate } = c.req.body; const [result, createErr] = await handleAsyncError(() => - TodoQueries.createTodo( + Queries.todo.createTodo( listId, title, description, @@ -51,7 +51,7 @@ app.post("/todos", requiresAuth, async (c) => { return c.text("Error: " + createErr.message, 400); } const [newTodo, getErr] = await handleAsyncError(() => - TodoQueries.getTodoById(result.id, c.get("user")?.sub) + Queries.todo.getTodoById(result.id, c.get("user")?.sub) ); if (getErr) { return c.text("Error: " + getErr.message, 400); @@ -63,13 +63,13 @@ app.post("/todos", requiresAuth, async (c) => { app.put("/todos/:id", requiresAuth, async (c) => { const { id } = c.req.param(); const [todo, getErr] = await handleAsyncError(() => - TodoQueries.getTodoById(id, c.get("user")?.sub) + Queries.todo.getTodoById(id, c.get("user")?.sub) ); if (getErr) { return c.text("Error: " + getErr.message, 400); } const [updatedTodo, updateErr] = await handleAsyncError(() => - TodoQueries.updateTodo( + Queries.todo.updateTodo( id, todo.title, todo.description, @@ -82,7 +82,7 @@ app.put("/todos/:id", requiresAuth, async (c) => { return c.text("Error: " + updateErr.message, 400); } const [refreshedTodo, refreshErr] = await handleAsyncError(() => - TodoQueries.getTodoById(id, c.get("user")?.sub) + Queries.todo.getTodoById(id, c.get("user")?.sub) ); if (refreshErr) { return c.text("Error: " + refreshErr.message, 400); @@ -94,7 +94,7 @@ app.put("/todos/:id", requiresAuth, async (c) => { app.delete("/todos/:id", requiresAuth, async (c) => { const { id } = c.req.param(); const [_, deleteErr] = await handleAsyncError(() => - TodoQueries.deleteTodo(id, c.get("user")?.sub) + Queries.todo.deleteTodo(id, c.get("user")?.sub) ); if (deleteErr) { return c.text("Error: " + deleteErr.message, 400); diff --git a/src/queries.js b/src/queries.js index de18b64..0e54e58 100644 --- a/src/queries.js +++ b/src/queries.js @@ -119,4 +119,9 @@ const TodoQueries = { }, }; -export default TodoQueries; +const Queries = { + todo: TodoQueries, + // add other queries here +}; + +export default Queries;