1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { getStudentById, getStudentByAdmission, updateStudent } from "../database/queries.ts";
3import type { ApiResponse, Student } from "../../shared/types.ts";
4
5## Features
6
7- **Profile Management**: View and edit student profiles with database persistence
8- **Academics**: Track units, examinations, and academic progress
9- **Finances**: Manage fee payments and view fee structures
16โโโ backend/
17โ โโโ index.ts # Main Hono server
18โ โโโ database/
19โ โ โโโ schema.ts # Database schema and migrations
20โ โ โโโ queries.ts # Database query functions
21โ โโโ routes/
22โ โโโ profile.ts # Profile management routes
37## Setup
38
391. The backend automatically creates the database tables on first run
402. Access the profile page at the root URL
413. Use the API endpoints to manage data
25## Technical Implementation
26
27- **Database**:[Val Town SQLite](https://docs.val.town/std/sqlite/) for storing users, sessions, and magic link tokens
28- **Frontend**: React with Tailwind CSS
29- **Backend**: Hono.js for API routes and middleware
59 const tokenHash = hashToken(token);
60
61 // Get the token from the database using its hash
62 const { rows } = await sqlite.execute(
63 `SELECT email, expires_at FROM ${MAGIC_LINKS_TABLE} WHERE id = ?`,
66
67 if (rows.length === 0) {
68 console.log("Did not find magic link token in database");
69 return { valid: false };
70 }
3import { Hono } from "npm:hono";
4import { authMiddleware } from "./auth.ts";
5import { USER_TABLE } from "./database/schema.ts";
6
7const app = new Hono();
1import { getCookie, setCookie } from "npm:hono/cookie";
2import { createMiddleware } from "npm:hono/factory";
3import { createMagicLinkToken, sendMagicLinkEmail, validateMagicLinkToken } from "./database/magic-links.ts";
4import { createSession, generateSessionToken, invalidateSession, validateSessionToken } from "./database/sessions.ts";
5
6export const authMiddleware = createMiddleware(async (c, next) => {
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { runMigrations } from "./database/migrations.ts";
4import auth from "./routes/auth.ts";
5import posts from "./routes/posts.ts";
14});
15
16// Initialize database on startup
17await runMigrations();
18
5import ValTown from "npm:@valtown/sdk";
6import SocialData from "../sdk/index.ts";
7import { setupDatabase, USAGE_TABLE } from "./database.ts";
8import { searchTwitterRoute } from "./routes/search.ts";
9
14
15// Uncomment this if you're forking this project:
16// await setupDatabase()
17
18// https://socialdata.gitbook.io/docs/pricing
3export const USAGE_TABLE = "socialDataProxy_usage_2";
4
5export async function setupDatabase() {
6 await sqlite.execute(`
7 CREATE TABLE IF NOT EXISTS ${USAGE_TABLE} (
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { requireAuth } from "./auth.ts";
3import { createMessage, getMessages } from "../database/queries.ts";
4import { generateId } from "../../shared/utils.ts";
5import type { ApiResponse, Message } from "../../shared/types.ts";