Skip to content
NIAEFEUPPublic

About

NIAEFEUP's recruitment website

Resources

Stars

13 stars

Watchers

0 watching

Forks

Repository files navigation

iNIcio — Recruitment Website for NIAEFEUP

This repository contains the source code for iNIcio, the recruitment platform for the Núcleo de Informática da AEFEUP (NIAEFEUP). It is built with Next.js for the frontend and backend logic, and uses Drizzle ORM with a PostgreSQL database for data management.


🚀 Getting Started

Follow these steps to get the project running locally:

1. Install dependencies

This will also automatically register the pre-commit hook that formats your code on commit.

npm install

2. Start the local services

Make sure you have Docker installed. Then, run the following command to start the local services (PostgreSQL, MinIO, and the websocket server):

docker compose up -d

This also provisions the local S3 bucket: after MinIO starts, the one-shot createbuckets service creates a bucket named after S3_BUCKET (default inicio, see .env). The MinIO console is available at http://localhost:9001 (login inicio / inicio123).

3. Setup environment variables

Copy the .env.example file to .env and fill in the required environment variables:

cp .env.example .env

Edit the .env file to set your database connection string and other necessary configurations.

4. Push the schema to the database

This will apply the current schema to the running PostgreSQL container.

npm run db:push

5. Start the development server

Run the following command to start the Next.js development server:

npm run dev

🧪 Useful Scripts

# Format code manually
npm run format:fix

# Run lint checks
npm run lint

# Start & stop the PostgreSQL database
docker compose down
docker compose up -d

# Push the schema to the database
npm run db:push

🗄️ Database & Drizzle ORM

The project uses Drizzle ORM with a PostgreSQL database for managing and querying data.

📁 Directory Structure

src/
└── db/
    ├── db.ts               # Initializes the Drizzle instance
    └── schema/             # Contains schema definition files (tables, relations, enums)
        ├── index.ts        # Aggregates all schema definitions
        ├── interview.ts
        ├── recruitment.ts
        └── ...

🧠 Initialization (db.ts)

The db.ts file initializes the Drizzle ORM instance and connects to the PostgreSQL database using the connection string defined in the .env file.

import { drizzle } from "drizzle-orm/node-postgres";
import * as schema from "./schema";

export const db = drizzle(process.env.DATABASE_URL!, { schema });

This ensures the app reuses a single database connection and schema reference instead of re-creating it in multiple places.

You can import the database like so:

import { db } from "@/db/db";

📚 Schema Files

  • All database tables and relationships are defined inside src/db/schema/ as individual .ts files.

  • Each file exports one or more tables (or enums, views, etc.).

  • There's an index.ts file inside schema/ that re-exports everything. This is required so Drizzle can register the full schema when initializing.

Whenever you create a new file inside schema/, make sure to add its exports to index.ts.

🔄 Applying Schema Changes

The TypeScript schema in src/db/schema/ is the single source of truth, and changes are shipped as versioned SQL migrations generated by Drizzle Kit. The SQL lives in drizzle/ and is committed. The production container runs the bundled migrate.cjs runner on startup. It uses the same Drizzle migrator, reads the committed SQL from drizzle/, and applies each migration exactly once without requiring the full development dependency tree in the runtime image.

To change the database:

  1. Edit the relevant file(s) in src/db/schema/ (and re-export anything new from index.ts).

  2. Generate a migration:

    npm run db:generate
  3. Review the generated SQL in drizzle/ before committing.

  4. Apply the migrations:

    npm run db:migrate

npm run db:push still exists for local databases, but do not use it on the shared/production database — it bypasses the migration history and can prompt interactively.

About

NIAEFEUP's recruitment website

Resources

Stars

13 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages