Skip to content
Open
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: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ next-env.d.ts

# firebase
firebase-debug.log
firestore-debug.log
firestore-debug.log
sqlite.db
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Stage 1: Build aşaması
FROM node:18-alpine AS builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .
RUN npm run build

# Stage 2: Production
FROM node:18-alpine AS production

WORKDIR /app

COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/package*.json ./

EXPOSE 3000

HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000', (r) => {if (r.statusCode !== 200) throw new Error(r.statusCode)})"

CMD ["npm", "start"]
81 changes: 78 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
# Firebase Studio
# SimuBourse - Financial Simulation Game

This is a NextJS starter in Firebase Studio.
Welcome to SimuBourse, an immersive financial simulation platform built with Next.js, Drizzle ORM, and Genkit for AI-powered features. Trade stocks, cryptocurrencies, create and manage your own companies, invest in others, and get investment advice from an integrated AI.

To get started, take a look at src/app/page.tsx.
## Tech Stack

- **Framework**: [Next.js](https://nextjs.org/) (App Router)
- **Styling**: [Tailwind CSS](https://tailwindcss.com/) & [ShadCN UI](https://ui.shadcn.com/)
- **Database**: [SQLite](https://www.sqlite.org/) via `better-sqlite3`
- **ORM**: [Drizzle ORM](https://orm.drizzle.team/)
- **Generative AI**: [Firebase Genkit](https://firebase.google.com/docs/genkit)
- **Authentication**: Custom JWT-based session management

## Getting Started

Follow these steps to get your local development environment up and running.

### 1. Prerequisites

- [Node.js](https://nodejs.org/) (v20.x or higher)
- npm or another package manager

### 2. Installation

First, clone the repository and install the dependencies:

```bash
git clone <your-repository-url>
cd SimuBourse-u2 # Or your project directory
npm install
```

### 3. Environment Variables

Create a `.env` file in the root of your project. This file is for your secret keys. You will need a Google AI API key for the Genkit features to work.

```env
# Get your key from Google AI Studio: https://makersuite.google.com/app/apikey
GOOGLE_API_KEY="your_google_ai_api_key"
```

### 4. Initialize the Database

The project uses SQLite, and the database file (`sqlite.db`) will be created automatically. To set up the necessary tables, run the initialization script:

```bash
npm run db:init
```
This command only needs to be run once. It will create all the necessary tables in your `sqlite.db` file.

### 5. Run the Development Server

You're all set! Start the development server:

```bash
npm run dev
```

The application should now be running at [http://localhost:9002](http://localhost:9002).

## Available Scripts

- `npm run dev`: Starts the Next.js development server with Turbopack.
- `npm run build`: Builds the application for production.
- `npm run start`: Starts a Next.js production server.
- `npm run lint`: Runs ESLint to check for code quality.
- `npm run db:init`: Initializes the SQLite database with the required schema.

## Deployment to a VM with PM2

To run this application in production on a Linux VM:

1. Clone the project and install dependencies (`npm install`).
2. Set up your `.env` file with your production `GOOGLE_API_KEY`.
3. Build the project: `npm run build`.
4. Use `pm2` to start and manage the application:
```bash
pm2 start npm --name "simubourse" -- run start -p 3000
```
This will start the app on port 3000 and ensure it restarts automatically.
10 changes: 2 additions & 8 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { defineConfig } from 'drizzle-kit';
import * as d from 'dotenv';
d.config({ path: '.env' });

if (!process.env.DATABASE_URL) {
throw new Error('DATABASE_URL is not set');
}

export default defineConfig({
dialect: 'postgresql',
dialect: 'sqlite',
schema: './src/lib/db/schema.ts',
out: './drizzle',
dbCredentials: {
url: process.env.DATABASE_URL,
url: './sqlite.db',
},
});
Loading