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
37 changes: 37 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Dependencies and build output
node_modules
dist
.pnpm-store

# Git and IDE
.git
.gitignore
.cursor
.vscode
*.code-workspace

# Env and secrets (use runtime env or secrets)
.env
.env.*
!.env.example

# Tests and coverage
coverage
**/__tests__
**/*.test.ts
**/*.spec.ts
jest.config.js
jest.setup.js

# Docs and misc
docs
*.md
!README.md

# CI
.github

# Local and OS
.DS_Store
Thumbs.db
*.log
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# EditorConfig: keep indentation consistent so format-on-save doesn't break spec.ts
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
27 changes: 23 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
DATABASE_URL=""
SESSION_SECRET=""
REPL_ID=""
API_PROD_URL=""
# Required: at least one of DATABASE_URL (dev) or DATABASE_URL_PROD (prod)
DATABASE_URL="postgresql://user:password@localhost:5432/museum"
# DATABASE_URL_PROD="postgresql://..."

# Required: min 32 characters
SESSION_SECRET="your-super-secret-session-key-at-least-32-chars"

# Server
PORT=5001
NODE_ENV=development

# CORS: allowed origin for browser requests (default http://localhost:3000)
FRONTEND_URL="http://localhost:3000"
# Optional: comma-separated extra origins
# CORS_ORIGINS="https://app.example.com,https://admin.example.com"

# Production: set when NODE_ENV=production
# API_PROD_URL="https://api.example.com"

# Optional: Cloudinary (for gallery uploads)
# CLOUDINARY_CLOUD_NAME=
# CLOUDINARY_API_KEY=
# CLOUDINARY_API_SECRET=
24 changes: 24 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* ESLint config for TypeScript and Node.js (ESLint 8 compatible).
* Ensures consistent style and catches common issues before push/CI.
*/
module.exports = {
root: true,
env: { node: true, es2022: true },
parser: "@typescript-eslint/parser",
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
plugins: ["@typescript-eslint"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
ignorePatterns: ["node_modules", "dist", "*.js", "drizzle", "config/openapi"],
rules: {
"@typescript-eslint/no-unused-vars": ["warn", { argsIgnorePattern: "^_" }],
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-require-imports": "off",
"no-console": ["warn", { allow: ["warn", "error"] }],
},
};
135 changes: 135 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: CI

on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]

jobs:
test:
name: Test and Lint
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 8

- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Check formatting
run: pnpm run format:check

- name: Run linter
run: pnpm run lint

- name: Type check
run: pnpm run check

- name: Run tests
run: pnpm run test
env:
NODE_ENV: test

- name: Build project
run: pnpm run build

build:
name: Build
runs-on: ubuntu-latest
needs: test

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 8

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "pnpm"

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- name: Setup pnpm cache
uses: actions/cache@v4
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Prepare for build
run: pnpm run prebuild

- name: Build for production
run: pnpm run build:prod

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7

docker:
name: Docker build
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true
tags: museum-management-rest-api:latest
cache-from: type=gha
cache-to: type=gha,mode=max
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ logs
config/database/reset-db.ts
todo-tasks.md
config/database/seed.ts
config/database/badagry_backend.code-workspace.json
config/database/museum-management.code-workspace*
.DS_Store
*.swp
*.swo
Expand Down
23 changes: 23 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Dependencies and build
node_modules
dist
build
*.min.js

# Lockfiles and generated
pnpm-lock.yaml
package-lock.json
*.config.js

# Drizzle and migrations (generated)
drizzle/**/*.sql

# Env (secrets)
.env
.env.*
!.env.example

# OpenAPI spec (manual formatting; do not strip curly braces or reformat)
config/openapi/
config/openapi/spec.ts
**/config/openapi/**
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "es5",
"printWidth": 100
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"editor.formatOnSave": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"editor.detectIndentation": false,
"editor.tabSize": 2,
"editor.insertSpaces": true,
"prettier.ignorePath": ".prettierignore"
}
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Museum Management REST API — multi-stage build (smallest image)
# =============================================================
# Stage 1: Dependencies and build
FROM node:20-alpine AS builder

RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app

COPY package.json pnpm-lock.yaml* ./
RUN pnpm install --frozen-lockfile

COPY tsconfig.json ./
COPY index.ts app.ts ./
COPY config config/
COPY middlewares middlewares/
COPY server server/
COPY drizzle.config.ts ./
COPY drizzle drizzle/

RUN pnpm run build

# Prune dev dependencies so runner only gets production node_modules
RUN pnpm prune --prod

# Stage 2: Production runner (minimal: no pnpm, no dev deps)
FROM node:20-alpine AS runner

WORKDIR /app

ENV NODE_ENV=production
ENV PORT=5001

# Copy only runtime artifacts from builder (no source, no devDependencies)
COPY --from=builder /app/package.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/drizzle ./drizzle
COPY --from=builder /app/drizzle.config.ts ./

# Non-root user for security
RUN addgroup -g 1001 -S app && adduser -u 1001 -S app -G app
USER app

EXPOSE ${PORT}

CMD ["node", "dist/index.js"]
Loading
Loading