|
| 1 | +# Django API Server |
| 2 | + |
| 3 | +Open-Source API server powered by [Django](https://app-generator.dev/docs/technologies/django/index.html), a progressive Node.js framework for building efficient, reliable, and scalable server-side applications. |
| 4 | + |
| 5 | +> Status: **Work in progress** |
| 6 | +
|
| 7 | +- 👉 [Django API Server](#) - **Complete Documentation** |
| 8 | +- 👉 [Get Support](https://app-generator.dev/ticket/create/) via Email and Discord |
| 9 | + |
| 10 | +<br /> |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- **Best Practices**: Follows industry-standard best practices for building robust APIs. |
| 15 | +- **Backend**: Built with Django, a powerful and scalable Node.js framework. |
| 16 | +- **UI**: |
| 17 | + - React Mantis (optional frontend integration). |
| 18 | + |
| 19 | +<br /> |
| 20 | + |
| 21 | +## Backend API |
| 22 | + |
| 23 | +- **Simple, modular & intuitive structure**: Easy to understand and extend. |
| 24 | +- **Toolchain**: |
| 25 | + - Usable with the latest Node.js LTS versions: |
| 26 | + - v22.x |
| 27 | + - v21.x |
| 28 | + - v20.x |
| 29 | + - Package Managers: |
| 30 | + - PNPM, |
| 31 | + - Yarn, |
| 32 | + - Npm |
| 33 | +- **Authentication**: Auth0 for GitHub integration. |
| 34 | + - GitHub email pulled during OAuth SignIN. |
| 35 | + - Optional: Email validation. |
| 36 | +- **Roles**: Admin, Users. |
| 37 | +- **ORM**: Prisma for database management. |
| 38 | +- **User Profiles**: |
| 39 | + - ROLE: Default user. |
| 40 | + - Fields: Name, surname, bio, country, address, job. |
| 41 | +- **API Features**: |
| 42 | + - Search, Pagination. |
| 43 | + - Public Access: GET by ID, get all. |
| 44 | + - Private access (requires token): |
| 45 | + - Create, Update, Delete. |
| 46 | +- **Admin**: |
| 47 | + - Can search or mutate any user. |
| 48 | +- **Users**: |
| 49 | + - Can view and mutate only their own information. |
| 50 | + |
| 51 | +## Start with Docker |
| 52 | + |
| 53 | +@Todo |
| 54 | + |
| 55 | +## Start Django Backend |
| 56 | + |
| 57 | +> Edit Environment |
| 58 | +
|
| 59 | +Add a `.env` file to your project root directory and populate as follows: |
| 60 | + |
| 61 | +```env |
| 62 | +AUTH0_DOMAIN=YOUR_AUTH0_DOMAIN |
| 63 | +AUTH0_CLIENT_ID=YOUR_AUTH0_CLIENT_ID |
| 64 | +AUTH0_CLIENT_SECRET=YOUR_AUTH0_CLIENT_SECRET |
| 65 | +
|
| 66 | +JWT_SECRET=YOUR_JWT_SECRET |
| 67 | +
|
| 68 | +DATABASE_URL=YOUR_DATABASE_URL |
| 69 | +``` |
| 70 | + |
| 71 | +Here's how to get the required Auth0 details. You need to register a client (application) in your Auth0 dashboard. |
| 72 | + |
| 73 | +Follow these steps to register a client with Auth0: |
| 74 | + |
| 75 | +1. Open the [Auth0 Applications](https://manage.auth0.com/?_gl=1*1a4zekg*_ga*Mjg3MzE5NzcyLjE3MzcwMjU4MzA.*_ga_QKMSDV5369*MTczNzIwMTkzNy45LjEuMTczNzIwMTk1Ni40MS4wLjA.#/applications) section of the Auth0 Dashboard. |
| 76 | +2. Click on the **Create Application** button. |
| 77 | +3. Provide a **Name**, such as "GitHub Auth". |
| 78 | +4. Choose `Single Page Web Applications` as the application type. |
| 79 | +5. Click on the **Create** button. |
| 80 | +6. Finally, note down your `Domain`, `Client ID`, and `Client Secret` and add them to your `.env` file. Click the settings tab if you do not see them. |
| 81 | + |
| 82 | +Choose a random string of letters and numbers for your `JWT_SECRET` and populate the `DATABASE_URL` with your database connection string. |
| 83 | + |
| 84 | +> Install Dependencies |
| 85 | +
|
| 86 | +Run the following to install dependencies: |
| 87 | + |
| 88 | +```bash |
| 89 | +npm install |
| 90 | +``` |
| 91 | + |
| 92 | +OR |
| 93 | + |
| 94 | +```bash |
| 95 | +yarn |
| 96 | +``` |
| 97 | + |
| 98 | +> Set Up Prisma |
| 99 | +
|
| 100 | +1. Run the following command to generate the Prisma client and apply migrations: |
| 101 | + |
| 102 | +```bash |
| 103 | +npx prisma generate |
| 104 | +npx prisma migrate dev --name init |
| 105 | +``` |
| 106 | + |
| 107 | +2. If you need to seed your database, you can add a `seed` script in the `prisma/seed.ts` file and run: |
| 108 | + |
| 109 | +```bash |
| 110 | +npx prisma db seed |
| 111 | +``` |
| 112 | + |
| 113 | +> Run Your Server |
| 114 | +
|
| 115 | +Start the Django server with: |
| 116 | + |
| 117 | +```bash |
| 118 | +npm run start:dev |
| 119 | +``` |
| 120 | + |
| 121 | +OR |
| 122 | + |
| 123 | +```bash |
| 124 | +yarn start:dev |
| 125 | +``` |
| 126 | + |
| 127 | +## Compile [React UI](https://github.com/codedthemes/mantis-free-react-admin-template) |
| 128 | + |
| 129 | +> Edit Environment |
| 130 | +
|
| 131 | +Add your server base URL to your environment variables as follows: |
| 132 | + |
| 133 | +```env |
| 134 | +VITE_APP_PUBLIC_URL=<YOUR_SERVER_URL> |
| 135 | +``` |
| 136 | + |
| 137 | +> Install Dependencies |
| 138 | +
|
| 139 | +```bash |
| 140 | +npm install |
| 141 | +``` |
| 142 | + |
| 143 | +OR |
| 144 | + |
| 145 | +```bash |
| 146 | +yarn |
| 147 | +``` |
| 148 | + |
| 149 | +> Start the React UI |
| 150 | +
|
| 151 | +```bash |
| 152 | +npm run dev |
| 153 | +``` |
| 154 | + |
| 155 | +OR |
| 156 | + |
| 157 | +```bash |
| 158 | +yarn dev |
| 159 | +``` |
| 160 | + |
| 161 | +--- |
| 162 | +Django API Starter provided by [App Generator](https://app-generator.dev/) - Open-source service for developers and companies. |
0 commit comments