Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- **Name:** UFOund it
- **What it is:** UFOund it, is a webapp that displays UFO sightings.
- **Dataset:** [NUFORC UFO Sightings (Kaggle)](https://www.kaggle.com/datasets/NUFORC/ufo-sightings), CSV, approx 80,000 reports, approx 15mb.
- **Current state:** The frontend runs on hand-written mock data in `frontend/src/data/`. No backend or database yet.
- **Current state:** The frontend runs on hand-written mock data in `frontend/src/data/`. The backend is an Apollo Server with only a placeholder `health` query and is not yet connected to the frontend. No database yet.
- **Course context:** NTNU IT2810 project. Must be reproducible, accessible and sustainable.

## Tech stack
Expand All @@ -30,12 +30,16 @@ npm install
# Start frontend dev server
npm run dev

# Start backend
# TODO: backend not created yet
# Start backend dev server (GraphQL on http://localhost:3001, restarts on save)
# Use PORT=3002 npm run dev:backend if port 3001 is taken
npm run dev:backend

# Build (type-check + production build of the frontend)
# Build (type-check + production build of frontend and backend)
npm run build

# Run the built backend (as on the VM)
npm run start -w backend

# Lint
npm run lint

Expand All @@ -61,11 +65,12 @@ frontend/
types/ Shared TypeScript types
data/ Mock sightings (to be replaced by GraphQL)
# graphql/ Planned: Apollo queries
# backend/ Planned: Node + TypeScript GraphQL server
# src/
# schema/
# resolvers/
# db/
backend/ Node + TypeScript GraphQL server (Apollo Server 5)
src/
index.ts Starts the server on PORT (default 3001)
schema.ts GraphQL type definitions and resolvers
# db/ Planned: MySQL connection and queries
dist/ Build output from `npm run build` (git-ignored)
# docs/
```

Expand Down
23 changes: 23 additions & 0 deletions backend/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import js from '@eslint/js'
import globals from 'globals'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'
import eslintConfigPrettier from 'eslint-config-prettier/flat'

// Mirrors frontend/eslint.config.js without the React plugins, and with
// Node globals instead of browser globals.
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.ts'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
// Last, so it can turn off any rule that would fight Prettier.
eslintConfigPrettier,
],
languageOptions: {
globals: globals.node,
},
},
])
26 changes: 26 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "backend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "tsx watch src/index.ts",
"build": "tsc -p .",
"start": "node dist/index.js",
"lint": "eslint ."
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@types/node": "^24.19.1",
"eslint": "^10.12.0",
"eslint-config-prettier": "^10.1.8",
"globals": "^17.13.0",
"tsx": "^4.23.15",
"typescript": "~6.0.2",
"typescript-eslint": "^8.71.0"
},
"dependencies": {
"@apollo/server": "^5.5.1",
"graphql": "^16.14.2"
}
}
15 changes: 15 additions & 0 deletions backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApolloServer } from '@apollo/server'
import { startStandaloneServer } from '@apollo/server/standalone'
import { resolvers, typeDefs } from './schema.ts'

// 3001 is the backend port agreed for the course VM. PORT allows
// overriding it locally if something else is already using 3001.
const port = Number(process.env.PORT) || 3001

const server = new ApolloServer({ typeDefs, resolvers })

const { url } = await startStandaloneServer(server, {
listen: { port },
})

console.log(`GraphQL server ready at ${url}`)
17 changes: 17 additions & 0 deletions backend/src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Placeholder schema that only proves the server is running. The real
* Sighting types and queries will be agreed on by the group and added
* in a separate issue.
*/
export const typeDefs = `#graphql
type Query {
"Returns \\"ok\\" when the server is up."
health: String!
}
`

export const resolvers = {
Query: {
health: () => 'ok',
},
}
28 changes: 28 additions & 0 deletions backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
/* Output: compile src/ to plain JavaScript in dist/ for the VM */
"rootDir": "src",
"outDir": "dist",
"sourceMap": true,

/* Runtime: Node 20+ with ES modules */
"target": "es2023",
"lib": ["ES2023"],
"module": "nodenext",
"types": ["node"],
"skipLibCheck": true,

/* Imports: write `./schema.ts`, emitted as `./schema.js` */
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true,
"verbatimModuleSyntax": true,
"erasableSyntaxOnly": true,

/* Type checking */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
}
Loading