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
3 changes: 1 addition & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@

// Use 'postCreateCommand' to run commands after the container is created.
// Note: Useful for when they open it and want everything to just start
"postCreateCommand": "./.devcontainer/setup.sh",
"postStartCommand": "./.devcontainer/post_start.sh"
"postCreateCommand": "./.devcontainer/setup.sh"
}
4 changes: 0 additions & 4 deletions .devcontainer/post_start.sh

This file was deleted.

11 changes: 0 additions & 11 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,5 @@ fi
(cd server && POETRY_VIRTUALENVS_CREATE=false poetry install)
(cd client && npm install)

# Run the database in the background
docker compose up -d

# Wait for the database to start
# Get the container ID of the db service
DB_CONTAINER_ID=$(docker compose ps -q db)
echo "Waiting for the database to be ready..."
until [ "$(docker inspect -f '{{.State.Health.Status}}' "$DB_CONTAINER_ID")" == "healthy" ]; do
sleep 1
done

# Nuke and migrate db
(cd server && ./nuke.sh)
6 changes: 0 additions & 6 deletions .env.prod.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ APP_NAME=DjangoAPI
API_SECRET_KEY= CHANGE THIS TO A RANDOM STRING
API_ALLOWED_HOSTS=".localhost 127.0.0.1 [::1] .codersforcauses.org"

POSTGRES_HOST=db
POSTGRES_NAME=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_PORT=5432

DJANGO_SUPERUSER_PASSWORD= CHANGE THIS TO A RANDOM STRING
DJANGO_SUPERUSER_EMAIL= CHANGE THIS TO A VALID EMAIL
DJANGO_SUPERUSER_USERNAME= CHANGE THIS TO A VALID USERNAME
Expand Down
72 changes: 17 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Django + Nextjs Template: Standardised CFC Tech Stack

---

## Quick Start (Dev Container) - Recommended
## Quick Start (Dev Container)

The easiest way to get started is using the VS Code Dev Container:

Expand Down Expand Up @@ -37,90 +37,52 @@ The easiest way to get started is using the VS Code Dev Container:

**Note**: Only follow these steps if you're NOT using the dev container.

### Prerequisites
### Installation Steps

#### 1. Install Prerequisites

- **Node.js 18+** and **npm** - [Download here](https://nodejs.org/)
- **Node.js 20+** and **npm** - [Download here](https://nodejs.org/)
- **Python 3.12+** - [Download here](https://python.org/)
- **Poetry** (Python package manager) - [Installation guide](https://python-poetry.org/docs/#installation)
- **Docker Desktop** - [Download here](https://www.docker.com/products/docker-desktop/)

### Installation Steps

#### 1. Clone the Repository
#### 2. Clone the Repository
```bash
git clone <your-repo-url>
cd <project-name>
```

#### 2. Install Prerequisites
#### 3. Set Up Environment Variables

**Poetry (Python package manager)**
```bash
# Official installer (all OSes)
curl -sSL https://install.python-poetry.org | python3 -

# If that fails, use pip (all OSes)
pip install poetry
```

#### 3. Start the Database
The client and server are configured by `.env` files, local to your device and not tracked by git.
To set these up you can simply copy the `.env.example` files in each to a new `.env` file.

```bash
cd server && docker compose up -d
```

#### 4. Set Up Environment Variables

Before proceeding, create your environment files by copying the examples:
Run the command below to do this automatically (system dependant).
```bash
cp ./client/.env.example ./client/.env && cp ./server/.env.example ./server/.env
```

**Backend (`.env` in `server/`)**
```env
APP_NAME=DjangoAPI
APP_ENV=DEVELOPMENT
API_SECRET_KEY=your-secret-key-here
API_ALLOWED_HOSTS=.localhost 127.0.0.1 [::1]

POSTGRES_HOST=localhost
POSTGRES_NAME=your_db_name
POSTGRES_USER=your_username
POSTGRES_PASSWORD=your_password
POSTGRES_PORT=5432

DJANGO_SUPERUSER_PASSWORD=Password123
DJANGO_SUPERUSER_EMAIL=admin@test.com
DJANGO_SUPERUSER_USERNAME=admin

FRONTEND_URL=http://localhost:3000
```

**Frontend (`.env` in `client/`)**
```env
NEXT_PUBLIC_BACKEND_URL=http://localhost:8000
```

#### 5. Set Up the Backend (Django)
#### 4. Set Up the Backend (Django)
```bash
cd server
poetry install
poetry shell

eval $(poetry env activate) #Bash/Zsh/Csh
Invoke-Expression (poetry env activate) #Powershell

python manage.py migrate
python manage.py createsuperuser # optional
python manage.py runserver
```

#### 6. Set Up the Frontend (Next.js)
#### 5. Set Up the Frontend (Next.js)
```bash
cd client
npm install
npm run dev
```

#### 7. Verify Installation
#### 6. Verify Installation
- Frontend: [http://localhost:3000](http://localhost:3000)
- Backend API: [http://localhost:8000](http://localhost:8000)
- Admin panel: [http://localhost:8000/admin](http://localhost:8000/admin)

---
Expand Down
38 changes: 15 additions & 23 deletions client/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
import { defineConfig } from "eslint/config";
import { FlatCompat } from '@eslint/eslintrc'
import importPlugin from "eslint-plugin-import";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import _import from "eslint-plugin-import";
import { fixupPluginRules } from "@eslint/compat";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
baseDirectory: import.meta.dirname,
});

export default defineConfig([
const eslintConfig =[
...compat.config({
extends: ["next/core-web-vitals", "next/typescript"]
}),
{
files: ["**/*.ts", "**/*.tsx"],
extends: compat.extends(
"plugin:@next/next/recommended",
"plugin:@tanstack/eslint-plugin-query/recommended",
),

plugins: {
"simple-import-sort": simpleImportSort,
import: fixupPluginRules(_import),
'simple-import-sort': simpleImportSort,
import: importPlugin,
},

languageOptions: {
parser: tsParser,
},

rules: {
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn",
Expand All @@ -41,4 +28,9 @@ export default defineConfig([
"import/no-duplicates": "warn",
},
},
]);
{
ignores: ["node_modules/**", ".next/**", "next-env.d.ts"]
}
];

export default eslintConfig
35 changes: 18 additions & 17 deletions client/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import os from "node:os";
// import os from "node:os";
// import isInsideContainer from "is-inside-container";

import isInsideContainer from "is-inside-container";

const isWindowsDevContainer = () =>
os.release().toLowerCase().includes("microsoft") && isInsideContainer();
// const isWindowsDevContainer = () =>
// os.release().toLowerCase().includes("microsoft") && isInsideContainer();

/** @type {import('next').NextConfig} */
const nextConfig = {

const config = {
reactStrictMode: true,
// dumb fix for windows docker
webpack: isWindowsDevContainer()
? (config) => {
config.watchOptions = {
poll: 1000,
aggregateTimeout: 300,
};
return config;
}
: undefined,
turbopack: {
root: import.meta.dirname,
},
outputFileTracingRoot: import.meta.dirname,
// Turns on file change polling for the Windows Dev Container
// Doesn't work currently for turbopack, so file changes will not automatically update the client.
// watchOptions: isWindowsDevContainer()
// ? {
// pollIntervalMs: 1000
// }
// : undefined,
};

export default nextConfig;
export default config;
9 changes: 6 additions & 3 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "client",
"version": "0.1.0",
"private": true,
"engines":{
"node": ">=20.0.0"
},
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
Expand Down
1 change: 0 additions & 1 deletion client/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import axios from "axios";
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";

Expand Down
3 changes: 2 additions & 1 deletion client/tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Config } from "tailwindcss";
import { fontFamily } from "tailwindcss/defaultTheme";
import animate from "tailwindcss-animate";

const config = {
darkMode: ["class"],
Expand Down Expand Up @@ -78,7 +79,7 @@ const config = {
},
},
},
plugins: [require("tailwindcss-animate")],
plugins: [animate],
} satisfies Config;

export default config;
14 changes: 0 additions & 14 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
services:
db:
image: postgres:16.4
restart: unless-stopped
volumes:
- ./data/db:/var/lib/postgresql/data
env_file: ./.env.prod
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 3s
timeout: 3s
retries: 5

server:
image: ghcr.io/codersforcauses/transplant-prod-server:latest
container_name: transplant_server
Expand All @@ -24,8 +12,6 @@ services:
- ./opt/static_files:/opt/static_files
environment:
- DJANGO_SETTINGS_MODULE=api.settings
depends_on:
- db

client:
image: ghcr.io/codersforcauses/transplant-prod-client:latest
Expand Down
14 changes: 0 additions & 14 deletions docker-compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docker/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.12-slim

RUN apt-get update && apt-get install --yes --no-install-recommends postgresql-client g++ libssl-dev && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install --yes --no-install-recommends g++ libssl-dev && rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip && pip install poetry

Expand Down
11 changes: 0 additions & 11 deletions docker/server/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
#!/bin/bash

# Wait until Database is available before continuing
printf "\n" && echo "Checking Database is up"
# using psql
while ! pg_isready -q -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER
do
echo "$(date) - waiting for database to start"
sleep 1
done

>&2 echo "Postgres is up - continuing"

echo "Applying database migrations"
python manage.py migrate --noinput

Expand Down
6 changes: 0 additions & 6 deletions server/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ APP_ENV=DEVELOPMENT
API_SECRET_KEY="supersecretkey"
API_ALLOWED_HOSTS=".localhost 127.0.0.1 [::1]"

POSTGRES_HOST=localhost
POSTGRES_NAME=postgres
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_PORT=5432

DJANGO_SUPERUSER_PASSWORD=Password123
DJANGO_SUPERUSER_EMAIL=admin@test.com
DJANGO_SUPERUSER_USERNAME=admin
Expand Down
Loading