This digital platform is made using the Next.js React framework. It was bootstrapped
with
create-next-app
from the
with-mongodb-mongoose
example (npx create-next-app --example with-mongodb-mongoose cddl-beirut).
For the API, the mongoose object modeling library
is used to make creating/retrieving data from the MongoDB database easier.
The diagram below shows a high-level view of the file structure (not all files and folders are shown).
📦cddl-beirut
┣ 📂components
┣ 📂lib
┣ 📂models
┣ 📂pages
┃ ┣ 📂api
┃ ┣ 📜index.js
┃ ┗ 📜_app.js
┣ 📂public
┣ 📂scripts
┣ 📂styles
┣ 📜.env
┗ 📜package.json
📂componentscontains the React components for the frontend.📂libstores helper files, such asdbConnect.jswhich connects to the MongoDB database.📂modelscontains the Mongoose schemas for each of the datatypes. It also containsTypes.jswhich defines the attributes of each model using JSDoc formatting.📂pagesstores all of the primary files used for the fontend. See the Next.js pages documentation for details on how to work with pages. The entry point is_app.js, and the root page is built fromindex.js. This folder also contains the📂api/folder which serves the API.📂publicjust contains public files, such as icons and logos.📂scriptscontains scripts used separately from the main project, such as local file upload to the database (visit the folder for more details).📂stylescontains the SCSS stylesheets. They must be imported inglobals.scssso they can be used globally among all React components.📜.env(IMPORTANT) contains the URI for connecting to the MongoDB database. It is not pushed to the remote repo so it will not appear here. See the local development section for more information.📜package.jsondefines the dependencies and start scripts.
Go through the following steps to get started:
- Make sure you have Node installed and that
you can run the
npmcommand in your terminal. - Clone
the repository using
git cloneinto your local workspace. - Once you are in the project root directory, run
npm installto install the dependencies. - (IMPORTANT) In order for the app to be able to connect to the database,
create a
.envfile in the root directory and add the MongoDB connection string (URI) in the following format:MONGODB_URI=<URI>. To find this URI, navigate to the CDDL-Beirut cluster in the MongoDB dashboard and clickConnect > Connect your applicationand follow the instructions to get the correct string (replace<URI>with the string). - For the maps to work, you must also add the Mapbox access token to the
.envfile. Add the following line:NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN=<TOKEN>. - Lastly, run the command
npm run devto start the app, which is served by default on http://localhost:3000.
If everything works, you should be able to navigate to http://localhost:3000/api/images/github-logo.png and see an image of the Github logo.
Note: If you want to use the features in the scripts/ directory, use the
following additional steps to get set up.
- Install the dependencies by running
pip install -r scripts/requirements.txt. - Read the README file in the
scripts/directory for more information.
See Documentation for Heroku for deployment. Make sure to add the MongoDB connection string to the config vars.
This application uses MongoDB as its primary database, with Mongoose for schema
creation and support. Data was initially uploaded to this database using Node JS
scripts. See scripts/ for more information on this, as well as for
a database upload log.
Data is stored in the database as objects defined in Mongoose schemas, such as
archival information objects or workshop objects. See the models/
directory for all relevant files, or check Types.js for
documentation on all these types.
API documentation can be found in the pages/api/ directory. See
its README.
Contains the map.